2
* Copyright (C) 1998-2007 Luca Deri <deri@ntop.org>
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22
#include <winsock2.h> /* winsock.h is included automatically */
29
/* on mingw, the definitions we need are in pcap.h - Scott Renfro <scott@renfro.org> */
34
#define EADDRINUSE WSAEADDRINUSE
35
#define ENOTSOCK WSAENOTSOCK
36
#define EOPNOTSUPP WSAEOPNOTSUPP
39
/* Courtesy of Wies-Software <wies@wiessoft.de> */
40
extern char* getadminpass(const char *prompt);
41
extern unsigned long waitForNextEvent(unsigned long ulDelay /* ms */);
42
extern u_char isNtopAservice;
43
extern const char *inet_ntop(int af, const void *src, char *dst, size_t size);
45
extern char _wdir[], VERSION[];
47
#ifndef CFG_DATAFILE_DIR
48
#define CFG_DATAFILE_DIR _wdir
52
typedef int NDIS_STATUS, *PNDIS_STATUS;
54
/* ******************* */
57
#define strcasecmp _stricmp
59
extern int getopt(int num, char *const *argv, const char *opts);
60
#define getopt getopt____
62
#define unlink(a) _unlink(a)
63
#define close(a) _close(a)
66
/* on mingw, struct timezone isn't defined so s/struct timezone/void/ - Scott Renfro <scott@renfro.org> */
67
extern int gettimeofday(struct timeval*, void*);
69
extern int gettimeofday(struct timeval*, struct timezone*);
71
extern unsigned long waitForNextEvent(unsigned long ulDelay /* ms */);
73
extern int getopt_long (int argc, char *const *argv, const char *options,
74
const struct option *long_options, int *opt_index);
76
extern void printAvailableInterfaces();
77
extern char* getpass(const char *prompt);
78
extern ULONG GetHostIPAddr();
80
#define MAKE_WITH_ZLIB
82
#define HAVE_PCAP_FREEALLDEVS
85
#if !defined(__GNUC__)
87
#define in6_addr in_addr6
90
#define pthread_self GetCurrentThreadId
93
/* *************************************************************** */
97
Declaration of POSIX directory browsing functions and types for Win32.
99
Kevlin Henney (mailto:kevlin@acm.org), March 1997.
101
Copyright Kevlin Henney, 1997. All rights reserved.
103
Permission to use, copy, modify, and distribute this software and its
104
documentation for any purpose is hereby granted without fee, provided
105
that this copyright and permissions notice appear in all copies and
106
derivatives, and that no charge may be made for the software and its
107
documentation except to cover cost of distribution.
111
#if defined(WIN32) && defined(__GNUC__) && !defined(__MINGW32__)
112
#define DIRENT_INCLUDED
122
long handle; /* -1 for failed rewind */
123
struct _finddata_t info;
124
struct dirent result; /* d_name null iff first time */
125
char *name; /* NTBS */
128
DIR *opendir(const char *);
130
struct dirent *readdir(DIR *);
131
void rewinddir(DIR *);
136
#define RETSIGTYPE void
138
#define ETHERMTU 1500
140
#define DLT_NULL 0 /* no link-layer encapsulation */
141
#define DLT_EN10MB 1 /* Ethernet (10Mb) */
142
#define DLT_EN3MB 2 /* Experimental Ethernet (3Mb) */
143
#define DLT_AX25 3 /* Amateur Radio AX.25 */
144
#define DLT_PRONET 4 /* Proteon ProNET Token Ring */
145
#define DLT_CHAOS 5 /* Chaos */
146
#define DLT_IEEE802 6 /* IEEE 802 Networks */
147
#define DLT_ARCNET 7 /* ARCNET */
148
#define DLT_SLIP 8 /* Serial Line IP */
149
#define DLT_PPP 9 /* Point-to-point Protocol */
150
#define DLT_FDDI 10 /* FDDI */
153
* Ethernet address - 6 octets
156
u_char ether_addr_octet[6];
160
* Structure of a 10Mb/s Ethernet header.
162
struct ether_header {
163
u_char ether_dhost[6];
164
u_char ether_shost[6];
168
#define ETHeRTYPE_PUP 0x0200 /* PUP protocol */
169
#define ETHERTYPE_IP 0x0800 /* IP protocol */
170
#define ETHERTYPE_ARP 0x0806 /* Addr. resolution protocol */
171
#define ETHERTYPE_REVARP 0x8035 /* reverse Addr. resolution protocol */
174
/************************************************************************/
176
/* on mingw, tcp_seq is defined - Scott Renfro <scott@renfro.org> */
177
#if defined (WIN32) && !defined (tcp_seq)
178
typedef u_int tcp_seq;
183
* Per RFC 793, September, 1981.
186
u_short th_sport; /* source port */
187
u_short th_dport; /* destination port */
188
tcp_seq th_seq; /* sequence number */
189
tcp_seq th_ack; /* acknowledgement number */
190
#if BYTE_ORDER == LITTLE_ENDIAN
191
u_char th_x2:4, /* (unused) */
192
th_off:4; /* data offset */
194
u_char th_off:4, /* data offset */
195
th_x2:4; /* (unused) */
204
u_short th_win; /* window */
205
u_short th_sum; /* checksum */
206
u_short th_urp; /* urgent pointer */
209
/* ********************************************* */
212
#if BYTE_ORDER == LITTLE_ENDIAN
213
u_char ip_hl:4, /* header length */
214
ip_v:4; /* version */
216
u_char ip_v:4, /* version */
217
ip_hl:4; /* header length */
219
u_char ip_tos; /* type of service */
220
short ip_len; /* total length */
221
u_short ip_id; /* identification */
222
short ip_off; /* fragment offset field */
223
#define IP_DF 0x4000 /* dont fragment flag */
224
#define IP_MF 0x2000 /* more fragments flag */
225
#define IP_OFFMASK 0x1fff /* mask for fragmenting bits */
226
u_char ip_ttl; /* time to live */
227
u_char ip_p; /* protocol */
228
u_short ip_sum; /* checksum */
229
struct in_addr ip_src,ip_dst; /* source and dest address */
232
/* ********************************************* */
235
* Udp protocol header.
236
* Per RFC 768, September, 1981.
239
u_short uh_sport; /* source port */
240
u_short uh_dport; /* destination port */
241
short uh_ulen; /* udp length */
242
u_short uh_sum; /* udp checksum */
245
/* ********************************************* */
247
typedef struct _FRAMEETH
249
BYTE DestAddr[6]; // Indirizzo ethernet destinazione
250
BYTE SrcAddr[6]; // Indirizzo ethernet sorgente
252
BYTE Type[2]; // Tipo di pacchetto (o lunghezza per IEEE 802.3)
253
// il valore deve essere letto con la relazione:
254
// 256 * Type[0] + Type[1]
255
// e non semplicemente con un cast esplicito ad
256
// uno short, altrimenti (su una macchina INTEL)
257
// i byte pi� e meno significativi risultano
260
BYTE Dati[1500]; // Dati contenuti nel pacchetto
261
} FRAMEETH, *PFRAMEETH;
263
/* ********************************************* */
268
u_int32_t ira_preference;
273
u_int8_t icmp_type; /* type of message, see below */
274
u_int8_t icmp_code; /* type sub code */
275
u_int16_t icmp_cksum; /* ones complement checksum of struct */
278
u_char ih_pptr; /* ICMP_PARAMPROB */
279
struct in_addr ih_gwaddr; /* gateway address */
280
struct ih_idseq /* echo datagram */
287
/* ICMP_UNREACH_NEEDFRAG -- Path MTU Discovery (RFC1191) */
291
u_int16_t ipm_nextmtu;
296
u_int8_t irt_num_addrs;
298
u_int16_t irt_lifetime;
301
#define icmp_pptr icmp_hun.ih_pptr
302
#define icmp_gwaddr icmp_hun.ih_gwaddr
303
#define icmp_id icmp_hun.ih_idseq.icd_id
304
#define icmp_seq icmp_hun.ih_idseq.icd_seq
305
#define icmp_void icmp_hun.ih_void
306
#define icmp_pmvoid icmp_hun.ih_pmtu.ipm_void
307
#define icmp_nextmtu icmp_hun.ih_pmtu.ipm_nextmtu
308
#define icmp_num_addrs icmp_hun.ih_rtradv.irt_num_addrs
309
#define icmp_wpa icmp_hun.ih_rtradv.irt_wpa
310
#define icmp_lifetime icmp_hun.ih_rtradv.irt_lifetime
322
/* options and then 64 bits of data */
324
struct icmp_ra_addr id_radv;
328
#define icmp_otime icmp_dun.id_ts.its_otime
329
#define icmp_rtime icmp_dun.id_ts.its_rtime
330
#define icmp_ttime icmp_dun.id_ts.its_ttime
331
#define icmp_ip icmp_dun.id_ip.idi_ip
332
#define icmp_radv icmp_dun.id_radv
333
#define icmp_mask icmp_dun.id_mask
334
#define icmp_data icmp_dun.id_data
338
* Definition of type and code field values.
340
#define ICMP_ECHOREPLY 0 /* echo reply */
341
#define ICMP_UNREACH 3 /* dest unreachable, codes: */
342
#define ICMP_UNREACH_NET 0 /* bad net */
343
#define ICMP_UNREACH_HOST 1 /* bad host */
344
#define ICMP_UNREACH_PROTOCOL 2 /* bad protocol */
345
#define ICMP_UNREACH_PORT 3 /* bad port */
346
#define ICMP_UNREACH_NEEDFRAG 4 /* IP_DF caused drop */
347
#define ICMP_UNREACH_SRCFAIL 5 /* src route failed */
348
#define ICMP_SOURCEQUENCH 4 /* packet lost, slow down */
349
#define ICMP_REDIRECT 5 /* shorter route, codes: */
350
#define ICMP_REDIRECT_NET 0 /* for network */
351
#define ICMP_REDIRECT_HOST 1 /* for host */
352
#define ICMP_REDIRECT_TOSNET 2 /* for tos and net */
353
#define ICMP_REDIRECT_TOSHOST 3 /* for tos and host */
354
#define ICMP_ECHO 8 /* echo service */
355
#define ICMP_TIMXCEED 11 /* time exceeded, code: */
356
#define ICMP_TIMXCEED_INTRANS 0 /* ttl==0 in transit */
357
#define ICMP_TIMXCEED_REASS 1 /* ttl==0 in reass */
358
#define ICMP_PARAMPROB 12 /* ip header bad */
359
#define ICMP_TSTAMP 13 /* timestamp request */
360
#define ICMP_TSTAMPREPLY 14 /* timestamp reply */
361
#define ICMP_IREQ 15 /* information request */
362
#define ICMP_IREQREPLY 16 /* information reply */
363
#define ICMP_MASKREQ 17 /* address mask request */
364
#define ICMP_MASKREPLY 18 /* address mask reply */
366
#define ICMP_MAXTYPE 18
368
/* ********************************************* */
371
* Address Resolution Protocol.
373
* See RFC 826 for protocol description. ARP packets are variable
374
* in size; the arphdr structure defines the fixed-length portion.
375
* Protocol type values are the same as those for 10 Mb/s Ethernet.
376
* It is followed by the variable-sized fields ar_sha, arp_spa,
377
* arp_tha and arp_tpa in that order, according to the lengths
378
* specified. Field names used correspond to RFC 826.
381
u_short ar_hrd; /* format of hardware address */
382
#define ARPHRD_ETHER 1 /* ethernet hardware address */
383
u_short ar_pro; /* format of protocol address */
384
u_char ar_hln; /* length of hardware address */
385
u_char ar_pln; /* length of protocol address */
386
u_short ar_op; /* one of: */
387
#define ARPOP_REQUEST 1 /* request to resolve address */
388
#define ARPOP_REPLY 2 /* response to previous request */
389
#define REVARP_REQUEST 3 /* Reverse ARP request */
390
#define REVARP_REPLY 4 /* Reverse ARP reply */
392
* The remaining fields are variable in size,
393
* according to the sizes above, and are defined
394
* as appropriate for specific hardware/protocol
395
* combinations. (E.g., see <netinet/if_ether.h>.)
398
uchar_t ar_sha[]; /* sender hardware address */
399
uchar_t ar_spa[]; /* sender protocol address */
400
uchar_t ar_tha[]; /* target hardware address */
401
uchar_t ar_tpa[]; /* target protocol address */
408
struct arphdr ea_hdr; /* fixed-size header */
409
u_int8_t arp_sha[ETH_ALEN]; /* sender hardware address */
410
u_int8_t arp_spa[4]; /* sender protocol address */
411
u_int8_t arp_tha[ETH_ALEN]; /* target hardware address */
412
u_int8_t arp_tpa[4]; /* target protocol address */
414
#define arp_hrd ea_hdr.ar_hrd
415
#define arp_pro ea_hdr.ar_pro
416
#define arp_hln ea_hdr.ar_hln
417
#define arp_pln ea_hdr.ar_pln
418
#define arp_op ea_hdr.ar_op
420
/* ********************************************* */
422
extern void initWinsock32();
423
extern void termWinsock32();
424
extern void sniffSinglePacket(void(*pbuf_process)(u_char *unused,
425
const struct pcap_pkthdr *h,
428
extern char* strptime(const char *buf, const char *fmt, struct tm *tm);
430
/* ********************************************* */
432
// Max number of packets handled by the public version
433
#define MAX_NUM_PACKETS 1000
435
extern short isWinNT();
436
extern void get_serial(unsigned long *driveSerial);
438
/* #define WIN32_DEMO */