Debian Codegraph @

src/windows.c

raw symbols SCIP
1 /* arping/src/windows.c
2 *
3 * Copyright (C) 2000-2011 Thomas Habets <[email protected]>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 /***************
21 * This code has worked at one point, but I'm not a Windows programmer
22 * so it's not being maintained. Should not be hard to get working
23 * again though for someone who is.
24 ***************/
25 #if HAVE_CONFIG_H
26 #include "config.h"
27 #endif
28
29 #include <pcap.h>
30
31 #include "arping.h"
32
33 /**
34 *
35 */
36 void
37 do_signal_init()
38 {
39 SetConsoleCtrlHandler(arping_console_ctrl_handler, TRUE);
40 /* SetConsoleCtrlHandler(NULL, TRUE); */
41 }
42
43 /**
44 * untested for a long time. Maybe since arping 2.05 or so.
45 */
46 static void
47 ping_recv_win32(pcap_t *pcap, uint32_t packetwait, pcap_handler func)
48 {
49 struct timespec tv,tv2;
50 char done = 0;
51 /* windows won't let us do select() */
52 getclock(&tv2);
53
54 while (!done && !time_to_die) {
55 struct pcap_pkthdr *pkt_header;
56 u_char *pkt_data;
57 if (pcap_next_ex(pcap, &pkt_header, &pkt_data) > 0) {
58 func(pcap, pkt_header, pkt_data);
59 }
60 getclock(&tv);
61
62 /*
63 * setup next timespec, not very exact
64 */
65 tv.tv_sec = (packetwait / 1000000)
66 - (tv.tv_sec - tv2.tv_sec);
67 tv.tv_nsec = (packetwait % 1000000)
68 - (tv.tv_nsec - tv2.tv_nsec);
69 fixup_timespec(&tv);
70
71 usleep(10);
72 if (tv.tv_sec < 0) {
73 done=1;
74 }
75 }
76 }
77
78 /**
79 * Fall back on getting device name from pcap.
80 */
81 const char *
82 arping_lookupdev_default(int32_t srcip, uint32_t dstip,
83 char *ebuf)
84 {
85 WCHAR buf[LIBNET_ERRBUF_SIZE + PCAP_ERRBUF_SIZE];
86 WCHAR* ret = (WCHAR*)pcap_lookupdev((char*)buf);
87 if (ret != NULL) {
88 wcstombs(ebuf, ret, LIBNET_ERRBUF_SIZE + PCAP_ERRBUF_SIZE);
89 return ebuf;
90 }
91 return NULL;
92 }
93
94 static BOOL WINAPI arping_console_ctrl_handler(DWORD dwCtrlType)
95 {
96 if (verbose) {
97 printf("arping_console_ctrl_handler(%d)\n", (int)dwCtrlType);
98 }
99 time_to_die = 1;
100
101 if (0) {
102 /* if SetConsoleCtrlHandler() does what I think, this
103 isn't needed */
104 if (display == NORMAL) {
105 printf("\n--- %s statistics ---\n"
106 "%d packets transmitted, %d packets received, "
107 "%3.0f%% "
108 "unanswered\n", target, numsent, numrecvd,
109 100.0
110 - 100.0 * (float)(numrecvd)/(float)numsent);
111 }
112 }
113 return TRUE;
114 }
115 /* ---- Emacs Variables ----
116 * Local Variables:
117 * c-basic-offset: 8
118 * indent-tabs-mode: nil
119 * End:
120 */