~ubuntu-branches/ubuntu/wily/ntop/wily-proposed

« back to all changes in this revision

Viewing changes to ntop/ntop_win32.h

  • Committer: Bazaar Package Importer
  • Author(s): Dennis Schoen
  • Date: 2002-04-12 11:38:47 UTC
  • Revision ID: james.westby@ubuntu.com-20020412113847-4k4yydw0pzybc6g8
Tags: upstream-2.0.0
Import upstream version 2.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  Copyright (C) 1998-99 Luca Deri <deri@ntop.org>
 
3
 *                        Portions by Stefano Suin <stefano@ntop.org>
 
4
 *                      
 
5
 *                        http://www.ntop.org/
 
6
 *                                      
 
7
 *  This program is free software; you can redistribute it and/or modify
 
8
 *  it under the terms of the GNU General Public License as published by
 
9
 *  the Free Software Foundation; either version 2 of the License, or
 
10
 *  (at your option) any later version.
 
11
 *
 
12
 *  This program is distributed in the hope that it will be useful,
 
13
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
 *  GNU General Public License for more details.
 
16
 *
 
17
 *  You should have received a copy of the GNU General Public License
 
18
 *  along with this program; if not, write to the Free Software
 
19
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
20
 */
 
21
 
 
22
 
 
23
#include <winsock2.h> /* winsock.h is included automatically */
 
24
 
 
25
#if defined(WIN32) && defined(__GNUC__)
 
26
/* on mingw, the definitions we need are in pcap.h - Scott Renfro <scott@renfro.org> */
 
27
#include "pcap.h"
 
28
#endif
 
29
 
 
30
#define HAVE_GDBM_H
 
31
#define HAVE_GDCHART
 
32
#define MULTITHREADED
 
33
#define ASYNC_ADDRESS_RESOLUTION
 
34
 
 
35
#define STATIC_PLUGIN
 
36
 
 
37
/* Courtesy of Wies-Software <wies@wiessoft.de> */
 
38
extern unsigned long waitForNextEvent(unsigned long ulDelay /* ms */);
 
39
#define sleep(a /* sec */) waitForNextEvent(1000*a /* ms */)
 
40
 
 
41
#define DATAFILE_DIR    "."
 
42
#define PLUGIN_DIR              "."
 
43
#define CONFIGFILE_DIR  "."
 
44
#define DBFILE_DIR      "."
 
45
 
 
46
/* ndis.h */
 
47
typedef int NDIS_STATUS, *PNDIS_STATUS; 
 
48
 
 
49
/* ******************* */
 
50
 
 
51
/* typedef ULONGLONG TrafficCounter; */
 
52
/* typedef unsigned long TrafficCounter; */
 
53
#if defined (WIN32) && !defined (__GNUC__)
 
54
typedef unsigned char  u_char;
 
55
typedef unsigned short u_short;
 
56
typedef unsigned int   u_int;
 
57
typedef unsigned long  u_long;
 
58
#endif
 
59
typedef unsigned int   tcp_seq;
 
60
 
 
61
typedef u_char  uint8_t;
 
62
typedef u_short uint16_t; 
 
63
typedef u_int   uint32_t; 
 
64
 
 
65
/*
 
66
typedef unsigned long u_int32, u_int32_t;
 
67
typedef long int32_t;
 
68
*/
 
69
 
 
70
#define strcasecmp _stricmp
 
71
 
 
72
extern int getopt(int num, char *const *argv, const char *opts);
 
73
#if defined(WIN32) && defined(__GNUC__)
 
74
/* on mingw, struct timezone isn't defined so s/struct timezone/void/ - Scott Renfro <scott@renfro.org> */
 
75
extern int gettimeofday(struct timeval*, void*);
 
76
#else
 
77
extern int gettimeofday(struct timeval*, struct timezone*);
 
78
#endif
 
79
extern unsigned long waitForNextEvent(unsigned long ulDelay /* ms */);
 
80
 
 
81
extern ULONG GetHostIPAddr();
 
82
 
 
83
#define RETSIGTYPE void
 
84
 
 
85
 
 
86
#define ETHERMTU        1500
 
87
 
 
88
#define DLT_NULL        0       /* no link-layer encapsulation */
 
89
#define DLT_EN10MB      1       /* Ethernet (10Mb) */
 
90
#define DLT_EN3MB       2       /* Experimental Ethernet (3Mb) */
 
91
#define DLT_AX25        3       /* Amateur Radio AX.25 */
 
92
#define DLT_PRONET      4       /* Proteon ProNET Token Ring */
 
93
#define DLT_CHAOS       5       /* Chaos */
 
94
#define DLT_IEEE802     6       /* IEEE 802 Networks */
 
95
#define DLT_ARCNET      7       /* ARCNET */
 
96
#define DLT_SLIP        8       /* Serial Line IP */
 
97
#define DLT_PPP         9       /* Point-to-point Protocol */
 
98
#define DLT_FDDI        10      /* FDDI */
 
99
 
 
100
/*
 
101
 * Ethernet address - 6 octets
 
102
 */
 
103
struct ether_addr {
 
104
  u_char ether_addr_octet[6];
 
105
};
 
106
 
 
107
/*
 
108
 * Structure of a 10Mb/s Ethernet header.
 
109
 */
 
110
struct  ether_header {
 
111
  u_char        ether_dhost[6];
 
112
  u_char        ether_shost[6];
 
113
  u_short       ether_type;
 
114
};
 
115
 
 
116
#define ETHERTYPE_PUP           0x0200  /* PUP protocol */
 
117
#define ETHERTYPE_IP            0x0800  /* IP protocol */
 
118
#define ETHERTYPE_ARP           0x0806  /* Addr. resolution protocol */
 
119
#define ETHERTYPE_REVARP        0x8035  /* reverse Addr. resolution protocol */
 
120
 
 
121
 
 
122
/************************************************************************/
 
123
 
 
124
/* on mingw, tcp_seq is defined - Scott Renfro <scott@renfro.org> */
 
125
#if defined (WIN32) && !defined (__GNUC__)
 
126
typedef u_int   tcp_seq;
 
127
#endif
 
128
 
 
129
/*
 
130
 * TCP header.
 
131
 * Per RFC 793, September, 1981.
 
132
 */
 
133
struct tcphdr {
 
134
        u_short th_sport;               /* source port */
 
135
        u_short th_dport;               /* destination port */
 
136
        tcp_seq th_seq;                 /* sequence number */
 
137
        tcp_seq th_ack;                 /* acknowledgement number */
 
138
#if BYTE_ORDER == LITTLE_ENDIAN 
 
139
        u_char  th_x2:4,                /* (unused) */
 
140
                th_off:4;               /* data offset */
 
141
#else
 
142
        u_char  th_off:4,               /* data offset */
 
143
                th_x2:4;                /* (unused) */
 
144
#endif
 
145
        u_char  th_flags;
 
146
#define TH_FIN  0x01
 
147
#define TH_SYN  0x02
 
148
#define TH_RST  0x04
 
149
#define TH_PUSH 0x08
 
150
#define TH_ACK  0x10
 
151
#define TH_URG  0x20
 
152
        u_short th_win;                 /* window */
 
153
        u_short th_sum;                 /* checksum */
 
154
        u_short th_urp;                 /* urgent pointer */
 
155
};
 
156
 
 
157
/* ********************************************* */
 
158
 
 
159
struct ip {
 
160
#if BYTE_ORDER == LITTLE_ENDIAN 
 
161
        u_char  ip_hl:4,                /* header length */
 
162
                ip_v:4;                 /* version */
 
163
#else
 
164
        u_char  ip_v:4,                 /* version */
 
165
                ip_hl:4;                /* header length */
 
166
#endif
 
167
        u_char  ip_tos;                 /* type of service */
 
168
        short   ip_len;                 /* total length */
 
169
        u_short ip_id;                  /* identification */
 
170
        short   ip_off;                 /* fragment offset field */
 
171
#define IP_DF 0x4000                    /* dont fragment flag */
 
172
#define IP_MF 0x2000                    /* more fragments flag */
 
173
#define IP_OFFMASK 0x1fff               /* mask for fragmenting bits */
 
174
        u_char  ip_ttl;                 /* time to live */
 
175
        u_char  ip_p;                   /* protocol */
 
176
        u_short ip_sum;                 /* checksum */
 
177
        struct  in_addr ip_src,ip_dst;  /* source and dest address */
 
178
};
 
179
 
 
180
/* ********************************************* */
 
181
 
 
182
/*
 
183
 * Udp protocol header.
 
184
 * Per RFC 768, September, 1981.
 
185
 */
 
186
struct udphdr {
 
187
        u_short uh_sport;               /* source port */
 
188
        u_short uh_dport;               /* destination port */
 
189
        short   uh_ulen;                /* udp length */
 
190
        u_short uh_sum;                 /* udp checksum */
 
191
};
 
192
 
 
193
/* ********************************************* */
 
194
 
 
195
typedef struct _FRAMEETH
 
196
{
 
197
        BYTE DestAddr[6];   // Indirizzo ethernet destinazione
 
198
        BYTE SrcAddr[6];        // Indirizzo ethernet sorgente
 
199
 
 
200
        BYTE Type[2];           // Tipo di pacchetto (o lunghezza per IEEE 802.3)
 
201
                                                // il valore deve essere letto con la relazione:
 
202
                                                //      256 * Type[0] + Type[1]
 
203
                                                // e non semplicemente con un cast esplicito ad 
 
204
                                                // uno short, altrimenti (su una macchina INTEL) 
 
205
                                                // i byte pi� e meno significativi risultano
 
206
                                                // scambiati
 
207
 
 
208
        BYTE Dati[1500];        // Dati contenuti nel pacchetto
 
209
}  FRAMEETH, *PFRAMEETH;
 
210
 
 
211
/* ********************************************* */
 
212
 
 
213
struct icmp_ra_addr
 
214
{
 
215
  u_int32_t ira_addr;
 
216
  u_int32_t ira_preference;
 
217
};
 
218
 
 
219
struct icmp
 
220
{
 
221
  u_int8_t  icmp_type;  /* type of message, see below */
 
222
  u_int8_t  icmp_code;  /* type sub code */
 
223
  u_int16_t icmp_cksum; /* ones complement checksum of struct */
 
224
  union
 
225
  {
 
226
    u_char ih_pptr;             /* ICMP_PARAMPROB */
 
227
    struct in_addr ih_gwaddr;   /* gateway address */
 
228
    struct ih_idseq             /* echo datagram */
 
229
    {
 
230
      u_int16_t icd_id;
 
231
      u_int16_t icd_seq;
 
232
    } ih_idseq;
 
233
    u_int32_t ih_void;
 
234
 
 
235
    /* ICMP_UNREACH_NEEDFRAG -- Path MTU Discovery (RFC1191) */
 
236
    struct ih_pmtu
 
237
    {
 
238
      u_int16_t ipm_void;
 
239
      u_int16_t ipm_nextmtu;
 
240
    } ih_pmtu;
 
241
 
 
242
    struct ih_rtradv
 
243
    {
 
244
      u_int8_t irt_num_addrs;
 
245
      u_int8_t irt_wpa;
 
246
      u_int16_t irt_lifetime;
 
247
    } ih_rtradv;
 
248
  } icmp_hun;
 
249
#define icmp_pptr       icmp_hun.ih_pptr
 
250
#define icmp_gwaddr     icmp_hun.ih_gwaddr
 
251
#define icmp_id         icmp_hun.ih_idseq.icd_id
 
252
#define icmp_seq        icmp_hun.ih_idseq.icd_seq
 
253
#define icmp_void       icmp_hun.ih_void
 
254
#define icmp_pmvoid     icmp_hun.ih_pmtu.ipm_void
 
255
#define icmp_nextmtu    icmp_hun.ih_pmtu.ipm_nextmtu
 
256
#define icmp_num_addrs  icmp_hun.ih_rtradv.irt_num_addrs
 
257
#define icmp_wpa        icmp_hun.ih_rtradv.irt_wpa
 
258
#define icmp_lifetime   icmp_hun.ih_rtradv.irt_lifetime
 
259
  union
 
260
  {
 
261
    struct
 
262
    {
 
263
      u_int32_t its_otime;
 
264
      u_int32_t its_rtime;
 
265
      u_int32_t its_ttime;
 
266
    } id_ts;
 
267
    struct
 
268
    {
 
269
      struct ip idi_ip;
 
270
      /* options and then 64 bits of data */
 
271
    } id_ip;
 
272
    struct icmp_ra_addr id_radv;
 
273
    u_int32_t   id_mask;
 
274
    u_int8_t    id_data[1];
 
275
  } icmp_dun;
 
276
#define icmp_otime      icmp_dun.id_ts.its_otime
 
277
#define icmp_rtime      icmp_dun.id_ts.its_rtime
 
278
#define icmp_ttime      icmp_dun.id_ts.its_ttime
 
279
#define icmp_ip         icmp_dun.id_ip.idi_ip
 
280
#define icmp_radv       icmp_dun.id_radv
 
281
#define icmp_mask       icmp_dun.id_mask
 
282
#define icmp_data       icmp_dun.id_data
 
283
};
 
284
 
 
285
/*
 
286
 * Definition of type and code field values.
 
287
 */
 
288
#define ICMP_ECHOREPLY          0               /* echo reply */
 
289
#define ICMP_UNREACH            3               /* dest unreachable, codes: */
 
290
#define ICMP_UNREACH_NET        0               /* bad net */
 
291
#define ICMP_UNREACH_HOST       1               /* bad host */
 
292
#define ICMP_UNREACH_PROTOCOL   2               /* bad protocol */
 
293
#define ICMP_UNREACH_PORT       3               /* bad port */
 
294
#define ICMP_UNREACH_NEEDFRAG   4               /* IP_DF caused drop */
 
295
#define ICMP_UNREACH_SRCFAIL    5               /* src route failed */
 
296
#define ICMP_SOURCEQUENCH       4               /* packet lost, slow down */
 
297
#define ICMP_REDIRECT           5               /* shorter route, codes: */
 
298
#define ICMP_REDIRECT_NET       0               /* for network */
 
299
#define ICMP_REDIRECT_HOST      1               /* for host */
 
300
#define ICMP_REDIRECT_TOSNET    2               /* for tos and net */
 
301
#define ICMP_REDIRECT_TOSHOST   3               /* for tos and host */
 
302
#define ICMP_ECHO               8               /* echo service */
 
303
#define ICMP_TIMXCEED           11              /* time exceeded, code: */
 
304
#define ICMP_TIMXCEED_INTRANS   0               /* ttl==0 in transit */
 
305
#define ICMP_TIMXCEED_REASS     1               /* ttl==0 in reass */
 
306
#define ICMP_PARAMPROB          12              /* ip header bad */
 
307
#define ICMP_TSTAMP             13              /* timestamp request */
 
308
#define ICMP_TSTAMPREPLY        14              /* timestamp reply */
 
309
#define ICMP_IREQ               15              /* information request */
 
310
#define ICMP_IREQREPLY          16              /* information reply */
 
311
#define ICMP_MASKREQ            17              /* address mask request */
 
312
#define ICMP_MASKREPLY          18              /* address mask reply */
 
313
 
 
314
#define ICMP_MAXTYPE            18
 
315
 
 
316
/* ********************************************* */
 
317
 
 
318
/*
 
319
 * Address Resolution Protocol.
 
320
 *
 
321
 * See RFC 826 for protocol description.  ARP packets are variable
 
322
 * in size; the arphdr structure defines the fixed-length portion.
 
323
 * Protocol type values are the same as those for 10 Mb/s Ethernet.
 
324
 * It is followed by the variable-sized fields ar_sha, arp_spa,
 
325
 * arp_tha and arp_tpa in that order, according to the lengths
 
326
 * specified.  Field names used correspond to RFC 826.
 
327
 */
 
328
struct  arphdr {
 
329
        u_short ar_hrd; /* format of hardware address */
 
330
#define ARPHRD_ETHER    1       /* ethernet hardware address */
 
331
        u_short ar_pro; /* format of protocol address */
 
332
        u_char  ar_hln;         /* length of hardware address */
 
333
        u_char  ar_pln;         /* length of protocol address */
 
334
        u_short ar_op;          /* one of: */
 
335
#define ARPOP_REQUEST   1       /* request to resolve address */
 
336
#define ARPOP_REPLY     2       /* response to previous request */
 
337
#define REVARP_REQUEST  3       /* Reverse ARP request */
 
338
#define REVARP_REPLY    4       /* Reverse ARP reply */
 
339
        /*
 
340
         * The remaining fields are variable in size,
 
341
         * according to the sizes above, and are defined
 
342
         * as appropriate for specific hardware/protocol
 
343
         * combinations.  (E.g., see <netinet/if_ether.h>.)
 
344
         */
 
345
#ifdef  notdef
 
346
        uchar_t ar_sha[];       /* sender hardware address */
 
347
        uchar_t ar_spa[];       /* sender protocol address */
 
348
        uchar_t ar_tha[];       /* target hardware address */
 
349
        uchar_t ar_tpa[];       /* target protocol address */
 
350
#endif  /* notdef */
 
351
};
 
352
 
 
353
#define ETH_ALEN  6
 
354
 
 
355
struct  ether_arp {
 
356
        struct  arphdr ea_hdr;          /* fixed-size header */
 
357
        u_int8_t arp_sha[ETH_ALEN];     /* sender hardware address */
 
358
        u_int8_t arp_spa[4];            /* sender protocol address */
 
359
        u_int8_t arp_tha[ETH_ALEN];     /* target hardware address */
 
360
        u_int8_t arp_tpa[4];            /* target protocol address */
 
361
};
 
362
#define arp_hrd ea_hdr.ar_hrd
 
363
#define arp_pro ea_hdr.ar_pro
 
364
#define arp_hln ea_hdr.ar_hln
 
365
#define arp_pln ea_hdr.ar_pln
 
366
#define arp_op  ea_hdr.ar_op
 
367
 
 
368
/* ********************************************* */
 
369
 
 
370
extern void initWinsock32();
 
371
extern void termWinsock32();
 
372
extern void sniffSinglePacket(void(*pbuf_process)(u_char *unused, 
 
373
                  const struct pcap_pkthdr *h, 
 
374
                  const u_char *p));
 
375
 
 
376
/*
 
377
 * on mingw, call closesocket, not close, at least on win2k (the args
 
378
 * have different types: int vs. SOCKET
 
379
 *
 
380
 */
 
381
#if defined (WIN32) && !defined (__GNUC__)
 
382
#define close(fd) closesocket(fd)
 
383
#endif
 
384
 
 
385
/* ********* MULTITHREAD STUFF ********* */
 
386
 
 
387
#define pthread_t              HANDLE
 
388
#define pthread_mutex_t        HANDLE
 
389
#define pthread_cond_t         HANDLE
 
390
 
 
391
 
 
392
typedef struct conditionalVariable {
 
393
        HANDLE condVar;
 
394
        CRITICAL_SECTION criticalSection;
 
395
} ConditionalVariable;
 
396
 
 
397
/* ********************************************* */
 
398
 
 
399
// Max number of packets handled by the public version
 
400
#define MAX_NUM_PACKETS   1000
 
401
 
 
402
extern short isWinNT();
 
403
 
 
404
/* #define WIN32_DEMO */