~ubuntu-branches/ubuntu/natty/ntop/natty

« back to all changes in this revision

Viewing changes to ntop_win32.h

  • Committer: Bazaar Package Importer
  • Author(s): Ludovico Cavedon, Jordan Metzmeier, Ludovico Cavedon
  • Date: 2010-12-15 20:06:19 UTC
  • mfrom: (5.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20101215200619-0ojz3iak95ihibun
Tags: 3:4.0.3+dfsg1-1
[ Jordan Metzmeier ]
* New upstream release (Closes: #522042)
* Move data files to /usr/share/ntop (Closes: #595450).
* Package architecture independent data in a separate ntop-data package.
* Use debhelper 7.
* Update Standards-Version to 3.9.1.
* Depend on python-mako.
* Do not include ntop.txt in binary packages as it is a copy of the man
  page.
* Do not include NEWS, as it is outdated.
* Switch to package source version 3.0 (quilt).
* Add password creation to debconf
* Changed init script to fix localization problems (thanks to Alejandro
  Varas <alej0varas@gmail.com>, LP: #257466)
* Remove manual update-rc.d calls from postrm and postinst. debhelper adds
  this for us.
* Add pre-depends on adduser for postinst script.
* Fix errors in the manpages: fix-manpage-errors.patch.
* Added fixes for matching active interfaces.
* Added a watch file.

[ Ludovico Cavedon ]
* Remove direct changes to upstream tree, and move them into specific patch
  files:
  - fix-manpage-errors.patch: fix typos in ntop.8.
  - dot-path.patch: fix path of /usr/bin/dot executable
* Add patches:
  - reduce-autogen-purged-files.patch: prevent agutogen.sh from reamoving
  too many files during cleanup.
  - Add build-without-ntop-darwin.patch, to fix compilation without
  ntop_darwin.c.
* No longer add faq.html, as it is not distributed in the upstream tarball.
* Use ${source:Version} in control file. Have ntop-data recommend
  ntop.
* Rename dirs to ntop.dirs and keep only empty directories that need
  to be created.
* Remove var/lib from ntop.install file, as it is empty (keeping it in
  ntop.dirs).
* Update po files.
* Breaks and Replaces instead of Conflitcs for ntop-data.
* Use a longer package description.
* Remove useless configure options from debian/rules.
* Move private shared libraries libraries in /usr/lib/ntop.
* Add change-plugin-dir.patch for adjusting plugin directory.
* Remove development files.
* Use system library for MochiKit.js.
* Rewrite DEP5 copyright file.
* Repackage upstream tarball in order to remove non-DFSG-compliant code. Add
  get-orig-source.sh script and get-orig-source target in debian/rules.
* Add explanation to README.Debian why geolocation is no longer working.
* Add avoid-copy-maxmind-db.patch to prevent copying of Geo*.dat
  files.
* Remove old unused patches.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *  Copyright (C) 1998-2007 Luca Deri <deri@ntop.org>
3
 
 *                      
4
 
 *                          http://www.ntop.org/
5
 
 *                                      
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.
10
 
 *
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.
15
 
 *
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.
19
 
 */
20
 
 
21
 
 
22
 
#include <winsock2.h> /* winsock.h is included automatically */
23
 
#include <direct.h>
24
 
 
25
 
#if defined(WIN32)
26
 
#include "Packet32.h"
27
 
 
28
 
#if defined(__GNUC__)
29
 
/* on mingw, the definitions we need are in pcap.h - Scott Renfro <scott@renfro.org> */
30
 
#include "pcap.h"
31
 
#endif
32
 
#include "dirent.h"
33
 
 
34
 
#define EADDRINUSE              WSAEADDRINUSE
35
 
#define ENOTSOCK                WSAENOTSOCK
36
 
#define EOPNOTSUPP              WSAEOPNOTSUPP
37
 
#endif
38
 
 
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);
44
 
 
45
 
extern char _wdir[], VERSION[];
46
 
 
47
 
#ifndef CFG_DATAFILE_DIR
48
 
#define CFG_DATAFILE_DIR        _wdir
49
 
#endif
50
 
 
51
 
/* ndis.h */
52
 
typedef int NDIS_STATUS, *PNDIS_STATUS; 
53
 
 
54
 
/* ******************* */
55
 
 
56
 
#define socklen_t int
57
 
#define strcasecmp _stricmp
58
 
 
59
 
extern int getopt(int num, char *const *argv, const char *opts);
60
 
#define getopt getopt____
61
 
 
62
 
#define unlink(a) _unlink(a)
63
 
#define close(a) _close(a)
64
 
 
65
 
#if defined(__GNUC__)
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*);
68
 
#else
69
 
extern int gettimeofday(struct timeval*, struct timezone*);
70
 
#endif
71
 
extern unsigned long waitForNextEvent(unsigned long ulDelay /* ms */);
72
 
 
73
 
extern int getopt_long (int argc, char *const *argv, const char *options,
74
 
                                                const struct option *long_options, int *opt_index);
75
 
 
76
 
extern void printAvailableInterfaces();
77
 
extern char* getpass(const char *prompt);
78
 
extern ULONG GetHostIPAddr();
79
 
 
80
 
#define MAKE_WITH_ZLIB
81
 
#define HAVE_DIRENT_H
82
 
#define HAVE_PCAP_FREEALLDEVS
83
 
#define HAVE_MYSQL_H
84
 
 
85
 
#if !defined(__GNUC__)
86
 
#define INET6
87
 
#define in6_addr in_addr6
88
 
#endif
89
 
 
90
 
#define pthread_self GetCurrentThreadId
91
 
 
92
 
 
93
 
/* *************************************************************** */
94
 
 
95
 
/*
96
 
 
97
 
    Declaration of POSIX directory browsing functions and types for Win32.
98
 
 
99
 
    Kevlin Henney (mailto:kevlin@acm.org), March 1997.
100
 
 
101
 
    Copyright Kevlin Henney, 1997. All rights reserved.
102
 
 
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.
108
 
    
109
 
*/
110
 
 
111
 
#if defined(WIN32) && defined(__GNUC__) && !defined(__MINGW32__)
112
 
#define DIRENT_INCLUDED
113
 
 
114
 
struct dirent
115
 
{
116
 
    char *d_name;
117
 
};
118
 
 
119
 
 
120
 
typedef struct DIR
121
 
{
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 */
126
 
} DIR;
127
 
 
128
 
DIR           *opendir(const char *);
129
 
int           closedir(DIR *);
130
 
struct dirent *readdir(DIR *);
131
 
void          rewinddir(DIR *);
132
 
 
133
 
#endif
134
 
 
135
 
 
136
 
#define RETSIGTYPE void
137
 
 
138
 
#define ETHERMTU        1500
139
 
 
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 */
151
 
 
152
 
/*
153
 
 * Ethernet address - 6 octets
154
 
 */
155
 
struct ether_addr {
156
 
  u_char ether_addr_octet[6];
157
 
};
158
 
 
159
 
/*
160
 
 * Structure of a 10Mb/s Ethernet header.
161
 
 */
162
 
struct  ether_header {
163
 
  u_char        ether_dhost[6];
164
 
  u_char        ether_shost[6];
165
 
  u_short       ether_type;
166
 
};
167
 
 
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 */
172
 
 
173
 
 
174
 
/************************************************************************/
175
 
 
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;
179
 
#endif
180
 
 
181
 
/*
182
 
 * TCP header.
183
 
 * Per RFC 793, September, 1981.
184
 
 */
185
 
struct tcphdr {
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 */
193
 
#else
194
 
        u_char  th_off:4,               /* data offset */
195
 
                th_x2:4;                /* (unused) */
196
 
#endif
197
 
        u_char  th_flags;
198
 
#define TH_FIN  0x01
199
 
#define TH_SYN  0x02
200
 
#define TH_RST  0x04
201
 
#define TH_PUSH 0x08
202
 
#define TH_ACK  0x10
203
 
#define TH_URG  0x20
204
 
        u_short th_win;                 /* window */
205
 
        u_short th_sum;                 /* checksum */
206
 
        u_short th_urp;                 /* urgent pointer */
207
 
};
208
 
 
209
 
/* ********************************************* */
210
 
 
211
 
struct ip {
212
 
#if BYTE_ORDER == LITTLE_ENDIAN 
213
 
        u_char  ip_hl:4,                /* header length */
214
 
                ip_v:4;                 /* version */
215
 
#else
216
 
        u_char  ip_v:4,                 /* version */
217
 
                ip_hl:4;                /* header length */
218
 
#endif
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 */
230
 
};
231
 
 
232
 
/* ********************************************* */
233
 
 
234
 
/*
235
 
 * Udp protocol header.
236
 
 * Per RFC 768, September, 1981.
237
 
 */
238
 
struct udphdr {
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 */
243
 
};
244
 
 
245
 
/* ********************************************* */
246
 
 
247
 
typedef struct _FRAMEETH
248
 
{
249
 
        BYTE DestAddr[6];   // Indirizzo ethernet destinazione
250
 
        BYTE SrcAddr[6];        // Indirizzo ethernet sorgente
251
 
 
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
258
 
                                                // scambiati
259
 
 
260
 
        BYTE Dati[1500];        // Dati contenuti nel pacchetto
261
 
}  FRAMEETH, *PFRAMEETH;
262
 
 
263
 
/* ********************************************* */
264
 
 
265
 
struct icmp_ra_addr
266
 
{
267
 
  u_int32_t ira_addr;
268
 
  u_int32_t ira_preference;
269
 
};
270
 
 
271
 
struct icmp
272
 
{
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 */
276
 
  union
277
 
  {
278
 
    u_char ih_pptr;             /* ICMP_PARAMPROB */
279
 
    struct in_addr ih_gwaddr;   /* gateway address */
280
 
    struct ih_idseq             /* echo datagram */
281
 
    {
282
 
      u_int16_t icd_id;
283
 
      u_int16_t icd_seq;
284
 
    } ih_idseq;
285
 
    u_int32_t ih_void;
286
 
 
287
 
    /* ICMP_UNREACH_NEEDFRAG -- Path MTU Discovery (RFC1191) */
288
 
    struct ih_pmtu
289
 
    {
290
 
      u_int16_t ipm_void;
291
 
      u_int16_t ipm_nextmtu;
292
 
    } ih_pmtu;
293
 
 
294
 
    struct ih_rtradv
295
 
    {
296
 
      u_int8_t irt_num_addrs;
297
 
      u_int8_t irt_wpa;
298
 
      u_int16_t irt_lifetime;
299
 
    } ih_rtradv;
300
 
  } icmp_hun;
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
311
 
  union
312
 
  {
313
 
    struct
314
 
    {
315
 
      u_int32_t its_otime;
316
 
      u_int32_t its_rtime;
317
 
      u_int32_t its_ttime;
318
 
    } id_ts;
319
 
    struct
320
 
    {
321
 
      struct ip idi_ip;
322
 
      /* options and then 64 bits of data */
323
 
    } id_ip;
324
 
    struct icmp_ra_addr id_radv;
325
 
    u_int32_t   id_mask;
326
 
    u_int8_t    id_data[1];
327
 
  } icmp_dun;
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
335
 
};
336
 
 
337
 
/*
338
 
 * Definition of type and code field values.
339
 
 */
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 */
365
 
 
366
 
#define ICMP_MAXTYPE            18
367
 
 
368
 
/* ********************************************* */
369
 
 
370
 
/*
371
 
 * Address Resolution Protocol.
372
 
 *
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.
379
 
 */
380
 
struct  arphdr {
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 */
391
 
        /*
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>.)
396
 
         */
397
 
#ifdef  notdef
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 */
402
 
#endif  /* notdef */
403
 
};
404
 
 
405
 
#define ETH_ALEN  6
406
 
 
407
 
struct  ether_arp {
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 */
413
 
};
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
419
 
 
420
 
/* ********************************************* */
421
 
 
422
 
extern void initWinsock32();
423
 
extern void termWinsock32();
424
 
extern void sniffSinglePacket(void(*pbuf_process)(u_char *unused, 
425
 
                  const struct pcap_pkthdr *h, 
426
 
                  const u_char *p));
427
 
 
428
 
extern char* strptime(const char *buf, const char *fmt, struct tm *tm);
429
 
 
430
 
/* ********************************************* */
431
 
 
432
 
// Max number of packets handled by the public version
433
 
#define MAX_NUM_PACKETS   1000
434
 
 
435
 
extern short isWinNT();
436
 
extern void get_serial(unsigned long *driveSerial);
437
 
 
438
 
/* #define WIN32_DEMO */