Added support for Win32, based on WinPcap.
This commit is contained in:
parent
3d856fe865
commit
6831542ec7
|
@ -0,0 +1,46 @@
|
||||||
|
/* @(#) $Header: /tcpdump/master/libpcap/Win32/Include/Gnuc.h,v 1.1 2002-08-01 08:33:05 risso Exp $ (LBL) */
|
||||||
|
|
||||||
|
/* Define __P() macro, if necessary */
|
||||||
|
|
||||||
|
#ifndef __P
|
||||||
|
#if __STDC__
|
||||||
|
#define __P(protos) protos
|
||||||
|
#else
|
||||||
|
#define __P(protos) ()
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* inline foo */
|
||||||
|
#ifndef __cplusplus
|
||||||
|
#ifdef __GNUC__
|
||||||
|
#define inline __inline
|
||||||
|
#else
|
||||||
|
#define inline
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Handle new and old "dead" routine prototypes
|
||||||
|
*
|
||||||
|
* For example:
|
||||||
|
*
|
||||||
|
* __dead void foo(void) __attribute__((volatile));
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#ifdef __GNUC__
|
||||||
|
#ifndef __dead
|
||||||
|
#define __dead volatile
|
||||||
|
#endif
|
||||||
|
#if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)
|
||||||
|
#ifndef __attribute__
|
||||||
|
#define __attribute__(args)
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#ifndef __dead
|
||||||
|
#define __dead
|
||||||
|
#endif
|
||||||
|
#ifndef __attribute__
|
||||||
|
#define __attribute__(args)
|
||||||
|
#endif
|
||||||
|
#endif
|
|
@ -0,0 +1,122 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of the project nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* $Id: addrinfo.h,v 1.1 2002-08-01 08:33:05 risso Exp $ */
|
||||||
|
|
||||||
|
#ifndef HAVE_ADDRINFO
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Error return codes from getaddrinfo()
|
||||||
|
*/
|
||||||
|
#define EAI_ADDRFAMILY 1 /* address family for hostname not supported */
|
||||||
|
#define EAI_AGAIN 2 /* temporary failure in name resolution */
|
||||||
|
#define EAI_BADFLAGS 3 /* invalid value for ai_flags */
|
||||||
|
#define EAI_FAIL 4 /* non-recoverable failure in name resolution */
|
||||||
|
#define EAI_FAMILY 5 /* ai_family not supported */
|
||||||
|
#define EAI_MEMORY 6 /* memory allocation failure */
|
||||||
|
#define EAI_NODATA 7 /* no address associated with hostname */
|
||||||
|
#define EAI_NONAME 8 /* hostname nor servname provided, or not known */
|
||||||
|
#define EAI_SERVICE 9 /* servname not supported for ai_socktype */
|
||||||
|
#define EAI_SOCKTYPE 10 /* ai_socktype not supported */
|
||||||
|
#define EAI_SYSTEM 11 /* system error returned in errno */
|
||||||
|
#define EAI_BADHINTS 12
|
||||||
|
#define EAI_PROTOCOL 13
|
||||||
|
#define EAI_MAX 14
|
||||||
|
|
||||||
|
/* internal error */
|
||||||
|
#define NETDB_INTERNAL -1 /* see errno */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Flag values for getaddrinfo()
|
||||||
|
*/
|
||||||
|
#define AI_PASSIVE 0x00000001 /* get address to use bind() */
|
||||||
|
#define AI_CANONNAME 0x00000002 /* fill ai_canonname */
|
||||||
|
#define AI_NUMERICHOST 0x00000004 /* prevent name resolution */
|
||||||
|
/* valid flags for addrinfo */
|
||||||
|
#define AI_MASK (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST)
|
||||||
|
|
||||||
|
#define AI_ALL 0x00000100 /* IPv6 and IPv4-mapped (with AI_V4MAPPED) */
|
||||||
|
#define AI_V4MAPPED_CFG 0x00000200 /* accept IPv4-mapped if kernel supports */
|
||||||
|
#define AI_ADDRCONFIG 0x00000400 /* only if any address is assigned */
|
||||||
|
#define AI_V4MAPPED 0x00000800 /* accept IPv4-mapped IPv6 address */
|
||||||
|
/* special recommended flags for getipnodebyname */
|
||||||
|
#define AI_DEFAULT (AI_V4MAPPED_CFG | AI_ADDRCONFIG)
|
||||||
|
|
||||||
|
struct addrinfo {
|
||||||
|
int ai_flags; /* AI_PASSIVE, AI_CANONNAME */
|
||||||
|
int ai_family; /* PF_xxx */
|
||||||
|
int ai_socktype; /* SOCK_xxx */
|
||||||
|
int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */
|
||||||
|
size_t ai_addrlen; /* length of ai_addr */
|
||||||
|
char *ai_canonname; /* canonical name for hostname */
|
||||||
|
struct sockaddr *ai_addr; /* binary address */
|
||||||
|
struct addrinfo *ai_next; /* next structure in linked list */
|
||||||
|
};
|
||||||
|
|
||||||
|
extern void freeaddrinfo (struct addrinfo *);
|
||||||
|
extern void freehostent (struct hostent *);
|
||||||
|
extern char *gai_strerror (int);
|
||||||
|
extern int getaddrinfo (const char *, const char *,
|
||||||
|
const struct addrinfo *, struct addrinfo **);
|
||||||
|
extern int getnameinfo (const struct sockaddr *, size_t, char *,
|
||||||
|
size_t, char *, size_t, int);
|
||||||
|
extern struct hostent *getipnodebyaddr (const void *, size_t, int, int *);
|
||||||
|
extern struct hostent *getipnodebyname (const char *, int, int, int *);
|
||||||
|
extern int inet_pton (int, const char *, void *);
|
||||||
|
extern const char *inet_ntop (int, const void *, char *, size_t);
|
||||||
|
#endif /* HAVE_ADDRINFO */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Constants for getnameinfo()
|
||||||
|
*/
|
||||||
|
#ifndef NI_MAXHOST
|
||||||
|
#define NI_MAXHOST 1025
|
||||||
|
#endif
|
||||||
|
#ifndef NI_MAXSERV
|
||||||
|
#define NI_MAXSERV 32
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Flag values for getnameinfo()
|
||||||
|
*/
|
||||||
|
#ifndef NI_NOFQDN
|
||||||
|
#define NI_NOFQDN 0x00000001
|
||||||
|
#endif
|
||||||
|
#ifndef NI_NUMERICHOST
|
||||||
|
#define NI_NUMERICHOST 0x00000002
|
||||||
|
#endif
|
||||||
|
#ifndef NI_NAMEREQD
|
||||||
|
#define NI_NAMEREQD 0x00000004
|
||||||
|
#endif
|
||||||
|
#ifndef NI_NUMERICSERV
|
||||||
|
#define NI_NUMERICSERV 0x00000008
|
||||||
|
#endif
|
||||||
|
#ifndef NI_DGRAM
|
||||||
|
#define NI_DGRAM 0x00000010
|
||||||
|
#endif
|
|
@ -0,0 +1,349 @@
|
||||||
|
/*
|
||||||
|
* ++Copyright++ 1983, 1989, 1993
|
||||||
|
* -
|
||||||
|
* Copyright (c) 1983, 1989, 1993
|
||||||
|
* The Regents of the University of California. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. All advertising materials mentioning features or use of this software
|
||||||
|
* must display the following acknowledgement:
|
||||||
|
* This product includes software developed by the University of
|
||||||
|
* California, Berkeley and its contributors.
|
||||||
|
* 4. Neither the name of the University nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
* -
|
||||||
|
* Portions Copyright (c) 1993 by Digital Equipment Corporation.
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies, and that
|
||||||
|
* the name of Digital Equipment Corporation not be used in advertising or
|
||||||
|
* publicity pertaining to distribution of the document or software without
|
||||||
|
* specific, written prior permission.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
|
||||||
|
* WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
|
||||||
|
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
|
||||||
|
* CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
|
||||||
|
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
|
||||||
|
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
||||||
|
* SOFTWARE.
|
||||||
|
* -
|
||||||
|
* --Copyright--
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @(#)nameser.h 8.1 (Berkeley) 6/2/93
|
||||||
|
* nameser.h,v 1.2 1995/05/06 14:23:54 hjl Exp
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _NAMESER_H_
|
||||||
|
#define _NAMESER_H_
|
||||||
|
|
||||||
|
#ifndef WIN32
|
||||||
|
#include <sys/param.h>
|
||||||
|
#if (!defined(BSD)) || (BSD < 199306)
|
||||||
|
# include <sys/bitypes.h>
|
||||||
|
#else
|
||||||
|
# include <sys/types.h>
|
||||||
|
#endif
|
||||||
|
#include <sys/cdefs.h>
|
||||||
|
#else
|
||||||
|
#include <pcap-stdinc.h>
|
||||||
|
#define __LITTLE_ENDIAN 1
|
||||||
|
#define __BYTE_ORDER __LITTLE_ENDIAN
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* revision information. this is the release date in YYYYMMDD format.
|
||||||
|
* it can change every day so the right thing to do with it is use it
|
||||||
|
* in preprocessor commands such as "#if (__BIND > 19931104)". do not
|
||||||
|
* compare for equality; rather, use it to determine whether your resolver
|
||||||
|
* is new enough to contain a certain feature.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define __BIND 19940417 /* interface version stamp */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Define constants based on rfc883
|
||||||
|
*/
|
||||||
|
#define PACKETSZ 512 /* maximum packet size */
|
||||||
|
#define MAXDNAME 256 /* maximum domain name */
|
||||||
|
#define MAXCDNAME 255 /* maximum compressed domain name */
|
||||||
|
#define MAXLABEL 63 /* maximum length of domain label */
|
||||||
|
#define HFIXEDSZ 12 /* #/bytes of fixed data in header */
|
||||||
|
#define QFIXEDSZ 4 /* #/bytes of fixed data in query */
|
||||||
|
#define RRFIXEDSZ 10 /* #/bytes of fixed data in r record */
|
||||||
|
#define INT32SZ 4 /* for systems without 32-bit ints */
|
||||||
|
#define INT16SZ 2 /* for systems without 16-bit ints */
|
||||||
|
#define INADDRSZ 4 /* for sizeof(struct inaddr) != 4 */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Internet nameserver port number
|
||||||
|
*/
|
||||||
|
#define NAMESERVER_PORT 53
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Currently defined opcodes
|
||||||
|
*/
|
||||||
|
#define QUERY 0x0 /* standard query */
|
||||||
|
#define IQUERY 0x1 /* inverse query */
|
||||||
|
#define STATUS 0x2 /* nameserver status query */
|
||||||
|
/*#define xxx 0x3 *//* 0x3 reserved */
|
||||||
|
#define NS_NOTIFY_OP 0x4 /* notify secondary of SOA change */
|
||||||
|
#ifdef ALLOW_UPDATES
|
||||||
|
/* non standard - supports ALLOW_UPDATES stuff from Mike Schwartz */
|
||||||
|
# define UPDATEA 0x9 /* add resource record */
|
||||||
|
# define UPDATED 0xa /* delete a specific resource record */
|
||||||
|
# define UPDATEDA 0xb /* delete all named resource record */
|
||||||
|
# define UPDATEM 0xc /* modify a specific resource record */
|
||||||
|
# define UPDATEMA 0xd /* modify all named resource record */
|
||||||
|
# define ZONEINIT 0xe /* initial zone transfer */
|
||||||
|
# define ZONEREF 0xf /* incremental zone referesh */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Currently defined response codes
|
||||||
|
*/
|
||||||
|
#ifdef HAVE_ADDRINFO
|
||||||
|
#define NOERROR 0 /* no error */
|
||||||
|
#endif /* HAVE_ADDRINFO */
|
||||||
|
#define FORMERR 1 /* format error */
|
||||||
|
#define SERVFAIL 2 /* server failure */
|
||||||
|
#define NXDOMAIN 3 /* non existent domain */
|
||||||
|
#define NOTIMP 4 /* not implemented */
|
||||||
|
#define REFUSED 5 /* query refused */
|
||||||
|
#ifdef ALLOW_UPDATES
|
||||||
|
/* non standard */
|
||||||
|
# define NOCHANGE 0xf /* update failed to change db */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Type values for resources and queries
|
||||||
|
*/
|
||||||
|
#define T_A 1 /* host address */
|
||||||
|
#define T_NS 2 /* authoritative server */
|
||||||
|
#define T_MD 3 /* mail destination */
|
||||||
|
#define T_MF 4 /* mail forwarder */
|
||||||
|
#define T_CNAME 5 /* canonical name */
|
||||||
|
#define T_SOA 6 /* start of authority zone */
|
||||||
|
#define T_MB 7 /* mailbox domain name */
|
||||||
|
#define T_MG 8 /* mail group member */
|
||||||
|
#define T_MR 9 /* mail rename name */
|
||||||
|
#define T_NULL 10 /* null resource record */
|
||||||
|
#define T_WKS 11 /* well known service */
|
||||||
|
#define T_PTR 12 /* domain name pointer */
|
||||||
|
#define T_HINFO 13 /* host information */
|
||||||
|
#define T_MINFO 14 /* mailbox information */
|
||||||
|
#define T_MX 15 /* mail routing information */
|
||||||
|
#define T_TXT 16 /* text strings */
|
||||||
|
#define T_RP 17 /* responsible person */
|
||||||
|
#define T_AFSDB 18 /* AFS cell database */
|
||||||
|
#define T_X25 19 /* X_25 calling address */
|
||||||
|
#define T_ISDN 20 /* ISDN calling address */
|
||||||
|
#define T_RT 21 /* router */
|
||||||
|
#define T_NSAP 22 /* NSAP address */
|
||||||
|
#define T_NSAP_PTR 23 /* reverse NSAP lookup (deprecated) */
|
||||||
|
#define T_SIG 24 /* security signature */
|
||||||
|
#define T_KEY 25 /* security key */
|
||||||
|
#define T_PX 26 /* X.400 mail mapping */
|
||||||
|
#define T_GPOS 27 /* geographical position (withdrawn) */
|
||||||
|
#define T_AAAA 28 /* IP6 Address */
|
||||||
|
#define T_LOC 29 /* Location Information */
|
||||||
|
/* non standard */
|
||||||
|
#define T_UINFO 100 /* user (finger) information */
|
||||||
|
#define T_UID 101 /* user ID */
|
||||||
|
#define T_GID 102 /* group ID */
|
||||||
|
#define T_UNSPEC 103 /* Unspecified format (binary data) */
|
||||||
|
/* Query type values which do not appear in resource records */
|
||||||
|
#define T_AXFR 252 /* transfer zone of authority */
|
||||||
|
#define T_MAILB 253 /* transfer mailbox records */
|
||||||
|
#define T_MAILA 254 /* transfer mail agent records */
|
||||||
|
#define T_ANY 255 /* wildcard match */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Values for class field
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define C_IN 1 /* the arpa internet */
|
||||||
|
#define C_CHAOS 3 /* for chaos net (MIT) */
|
||||||
|
#define C_HS 4 /* for Hesiod name server (MIT) (XXX) */
|
||||||
|
/* Query class values which do not appear in resource records */
|
||||||
|
#define C_ANY 255 /* wildcard match */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Status return codes for T_UNSPEC conversion routines
|
||||||
|
*/
|
||||||
|
#define CONV_SUCCESS 0
|
||||||
|
#define CONV_OVERFLOW (-1)
|
||||||
|
#define CONV_BADFMT (-2)
|
||||||
|
#define CONV_BADCKSUM (-3)
|
||||||
|
#define CONV_BADBUFLEN (-4)
|
||||||
|
|
||||||
|
#ifndef __BYTE_ORDER
|
||||||
|
#if (BSD >= 199103)
|
||||||
|
# include <machine/endian.h>
|
||||||
|
#else
|
||||||
|
#ifdef linux
|
||||||
|
# include <endian.h>
|
||||||
|
#else
|
||||||
|
#define __LITTLE_ENDIAN 1234 /* least-significant byte first (vax, pc) */
|
||||||
|
#define __BIG_ENDIAN 4321 /* most-significant byte first (IBM, net) */
|
||||||
|
#define __PDP_ENDIAN 3412 /* LSB first in word, MSW first in long (pdp)*/
|
||||||
|
|
||||||
|
#if defined(vax) || defined(ns32000) || defined(sun386) || defined(i386) || \
|
||||||
|
defined(MIPSEL) || defined(_MIPSEL) || defined(BIT_ZERO_ON_RIGHT) || \
|
||||||
|
defined(__alpha__) || defined(__alpha)
|
||||||
|
#define __BYTE_ORDER __LITTLE_ENDIAN
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(sel) || defined(pyr) || defined(mc68000) || defined(sparc) || \
|
||||||
|
defined(is68k) || defined(tahoe) || defined(ibm032) || defined(ibm370) || \
|
||||||
|
defined(MIPSEB) || defined(_MIPSEB) || defined(_IBMR2) || defined(DGUX) ||\
|
||||||
|
defined(apollo) || defined(__convex__) || defined(_CRAY) || \
|
||||||
|
defined(__hppa) || defined(__hp9000) || \
|
||||||
|
defined(__hp9000s300) || defined(__hp9000s700) || \
|
||||||
|
defined (BIT_ZERO_ON_LEFT) || defined(m68k)
|
||||||
|
#define __BYTE_ORDER __BIG_ENDIAN
|
||||||
|
#endif
|
||||||
|
#endif /* linux */
|
||||||
|
#endif /* BSD */
|
||||||
|
#endif /* __BYTE_ORDER */
|
||||||
|
|
||||||
|
#if !defined(__BYTE_ORDER) || \
|
||||||
|
(__BYTE_ORDER != __BIG_ENDIAN && __BYTE_ORDER != __LITTLE_ENDIAN && \
|
||||||
|
__BYTE_ORDER != __PDP_ENDIAN)
|
||||||
|
/* you must determine what the correct bit order is for
|
||||||
|
* your compiler - the next line is an intentional error
|
||||||
|
* which will force your compiles to bomb until you fix
|
||||||
|
* the above macros.
|
||||||
|
*/
|
||||||
|
error "Undefined or invalid __BYTE_ORDER";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Structure for query header. The order of the fields is machine- and
|
||||||
|
* compiler-dependent, depending on the byte/bit order and the layout
|
||||||
|
* of bit fields. We use bit fields only in int variables, as this
|
||||||
|
* is all ANSI requires. This requires a somewhat confusing rearrangement.
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
unsigned id :16; /* query identification number */
|
||||||
|
#if __BYTE_ORDER == __BIG_ENDIAN
|
||||||
|
/* fields in third byte */
|
||||||
|
unsigned qr: 1; /* response flag */
|
||||||
|
unsigned opcode: 4; /* purpose of message */
|
||||||
|
unsigned aa: 1; /* authoritive answer */
|
||||||
|
unsigned tc: 1; /* truncated message */
|
||||||
|
unsigned rd: 1; /* recursion desired */
|
||||||
|
/* fields in fourth byte */
|
||||||
|
unsigned ra: 1; /* recursion available */
|
||||||
|
unsigned pr: 1; /* primary server req'd (!standard) */
|
||||||
|
unsigned unused :2; /* unused bits (MBZ as of 4.9.3a3) */
|
||||||
|
unsigned rcode :4; /* response code */
|
||||||
|
#endif
|
||||||
|
#if __BYTE_ORDER == __LITTLE_ENDIAN || __BYTE_ORDER == __PDP_ENDIAN
|
||||||
|
/* fields in third byte */
|
||||||
|
unsigned rd :1; /* recursion desired */
|
||||||
|
unsigned tc :1; /* truncated message */
|
||||||
|
unsigned aa :1; /* authoritive answer */
|
||||||
|
unsigned opcode :4; /* purpose of message */
|
||||||
|
unsigned qr :1; /* response flag */
|
||||||
|
/* fields in fourth byte */
|
||||||
|
unsigned rcode :4; /* response code */
|
||||||
|
unsigned unused :2; /* unused bits (MBZ as of 4.9.3a3) */
|
||||||
|
unsigned pr :1; /* primary server req'd (!standard) */
|
||||||
|
unsigned ra :1; /* recursion available */
|
||||||
|
#endif
|
||||||
|
/* remaining bytes */
|
||||||
|
unsigned qdcount :16; /* number of question entries */
|
||||||
|
unsigned ancount :16; /* number of answer entries */
|
||||||
|
unsigned nscount :16; /* number of authority entries */
|
||||||
|
unsigned arcount :16; /* number of resource entries */
|
||||||
|
} HEADER;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Defines for handling compressed domain names
|
||||||
|
*/
|
||||||
|
#define INDIR_MASK 0xc0
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Structure for passing resource records around.
|
||||||
|
*/
|
||||||
|
struct rrec {
|
||||||
|
int16_t r_zone; /* zone number */
|
||||||
|
int16_t r_class; /* class number */
|
||||||
|
int16_t r_type; /* type number */
|
||||||
|
u_int32_t r_ttl; /* time to live */
|
||||||
|
int r_size; /* size of data area */
|
||||||
|
char *r_data; /* pointer to data */
|
||||||
|
};
|
||||||
|
|
||||||
|
//extern u_int16_t _getshort __P((const u_char *));
|
||||||
|
//extern u_int32_t _getlong __P((const u_char *));
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Inline versions of get/put short/long. Pointer is advanced.
|
||||||
|
*
|
||||||
|
* These macros demonstrate the property of C whereby it can be
|
||||||
|
* portable or it can be elegant but rarely both.
|
||||||
|
*/
|
||||||
|
#define GETSHORT(s, cp) { \
|
||||||
|
register u_char *t_cp = (u_char *)(cp); \
|
||||||
|
(s) = ((u_int16_t)t_cp[0] << 8) \
|
||||||
|
| ((u_int16_t)t_cp[1]) \
|
||||||
|
; \
|
||||||
|
(cp) += INT16SZ; \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define GETLONG(l, cp) { \
|
||||||
|
register u_char *t_cp = (u_char *)(cp); \
|
||||||
|
(l) = ((u_int32_t)t_cp[0] << 24) \
|
||||||
|
| ((u_int32_t)t_cp[1] << 16) \
|
||||||
|
| ((u_int32_t)t_cp[2] << 8) \
|
||||||
|
| ((u_int32_t)t_cp[3]) \
|
||||||
|
; \
|
||||||
|
(cp) += INT32SZ; \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define PUTSHORT(s, cp) { \
|
||||||
|
register u_int16_t t_s = (u_int16_t)(s); \
|
||||||
|
register u_char *t_cp = (u_char *)(cp); \
|
||||||
|
*t_cp++ = t_s >> 8; \
|
||||||
|
*t_cp = t_s; \
|
||||||
|
(cp) += INT16SZ; \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define PUTLONG(l, cp) { \
|
||||||
|
register u_int32_t t_l = (u_int32_t)(l); \
|
||||||
|
register u_char *t_cp = (u_char *)(cp); \
|
||||||
|
*t_cp++ = t_l >> 24; \
|
||||||
|
*t_cp++ = t_l >> 16; \
|
||||||
|
*t_cp++ = t_l >> 8; \
|
||||||
|
*t_cp = t_l; \
|
||||||
|
(cp) += INT32SZ; \
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* !_NAMESER_H_ */
|
|
@ -0,0 +1,86 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 1999 WIDE Project.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of the project nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
#ifndef _BITTYPES_H
|
||||||
|
#define _BITTYPES_H
|
||||||
|
|
||||||
|
#ifndef HAVE_U_INT8_T
|
||||||
|
|
||||||
|
#if SIZEOF_CHAR == 1
|
||||||
|
typedef unsigned char u_int8_t;
|
||||||
|
typedef signed char int8_t;
|
||||||
|
#elif SIZEOF_INT == 1
|
||||||
|
typedef unsigned int u_int8_t;
|
||||||
|
typedef signed int int8_t;
|
||||||
|
#else /* XXX */
|
||||||
|
#error "there's no appropriate type for u_int8_t"
|
||||||
|
#endif
|
||||||
|
#define HAVE_U_INT8_T 1
|
||||||
|
#define HAVE_INT8_T 1
|
||||||
|
|
||||||
|
#endif /* HAVE_U_INT8_T */
|
||||||
|
|
||||||
|
#ifndef HAVE_U_INT16_T
|
||||||
|
|
||||||
|
#if SIZEOF_SHORT == 2
|
||||||
|
typedef unsigned short u_int16_t;
|
||||||
|
typedef signed short int16_t;
|
||||||
|
#elif SIZEOF_INT == 2
|
||||||
|
typedef unsigned int u_int16_t;
|
||||||
|
typedef signed int int16_t;
|
||||||
|
#elif SIZEOF_CHAR == 2
|
||||||
|
typedef unsigned char u_int16_t;
|
||||||
|
typedef signed char int16_t;
|
||||||
|
#else /* XXX */
|
||||||
|
#error "there's no appropriate type for u_int16_t"
|
||||||
|
#endif
|
||||||
|
#define HAVE_U_INT16_T 1
|
||||||
|
#define HAVE_INT16_T 1
|
||||||
|
|
||||||
|
#endif /* HAVE_U_INT16_T */
|
||||||
|
|
||||||
|
#ifndef HAVE_U_INT32_T
|
||||||
|
|
||||||
|
#if SIZEOF_INT == 4
|
||||||
|
typedef unsigned int u_int32_t;
|
||||||
|
typedef signed int int32_t;
|
||||||
|
#elif SIZEOF_LONG == 4
|
||||||
|
typedef unsigned long u_int32_t;
|
||||||
|
typedef signed long int32_t;
|
||||||
|
#elif SIZEOF_SHORT == 4
|
||||||
|
typedef unsigned short u_int32_t;
|
||||||
|
typedef signed short int32_t;
|
||||||
|
#else /* XXX */
|
||||||
|
#error "there's no appropriate type for u_int32_t"
|
||||||
|
#endif
|
||||||
|
#define HAVE_U_INT32_T 1
|
||||||
|
#define HAVE_INT32_T 1
|
||||||
|
|
||||||
|
#endif /* HAVE_U_INT32_T */
|
||||||
|
|
||||||
|
#endif /* _BITTYPES_H */
|
|
@ -0,0 +1,37 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 1999 WIDE Project.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of the project nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
#ifndef HAVE_PORTABLE_PROTOTYPE
|
||||||
|
|
||||||
|
#if defined(__STDC__) || defined(__cplusplus)
|
||||||
|
#define __P(protos) protos /* full-blown ANSI C */
|
||||||
|
#else
|
||||||
|
#define __P(protos) () /* traditional C preprocessor */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* !HAVE_PORTABLE_PROTOTYPE */
|
|
@ -0,0 +1,56 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 1999, 2000
|
||||||
|
* Politecnico di Torino. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that: (1) source code distributions
|
||||||
|
* retain the above copyright notice and this paragraph in its entirety, (2)
|
||||||
|
* distributions including binary code include the above copyright notice and
|
||||||
|
* this paragraph in its entirety in the documentation or other materials
|
||||||
|
* provided with the distribution, and (3) all advertising materials mentioning
|
||||||
|
* features or use of this software display the following acknowledgement:
|
||||||
|
* ``This product includes software developed by the Politecnico
|
||||||
|
* di Torino, and its contributors.'' Neither the name of
|
||||||
|
* the University nor the names of its contributors may be used to endorse
|
||||||
|
* or promote products derived from this software without specific prior
|
||||||
|
* written permission.
|
||||||
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
|
||||||
|
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <net/netdb.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <arpa/nameser.h>
|
||||||
|
|
||||||
|
extern void _sethtent(int f);
|
||||||
|
extern void _endhtent(void);
|
||||||
|
extern struct hostent *_gethtent(void);
|
||||||
|
extern struct hostent *_gethtbyname(const char *name);
|
||||||
|
extern struct hostent *_gethtbyaddr(const char *addr, int len,
|
||||||
|
int type);
|
||||||
|
extern int _validuser(FILE *hostf, const char *rhost,
|
||||||
|
const char *luser, const char *ruser, int baselen);
|
||||||
|
extern int _checkhost(const char *rhost, const char *lhost, int len);
|
||||||
|
#if 0
|
||||||
|
extern void putlong(u_long l, u_char *msgp);
|
||||||
|
extern void putshort(u_short l, u_char *msgp);
|
||||||
|
extern u_int32_t _getlong(register const u_char *msgp);
|
||||||
|
extern u_int16_t _getshort(register const u_char *msgp);
|
||||||
|
extern void p_query(char *msg);
|
||||||
|
extern void fp_query(char *msg, FILE *file);
|
||||||
|
extern char *p_cdname(char *cp, char *msg, FILE *file);
|
||||||
|
extern char *p_rr(char *cp, char *msg, FILE *file);
|
||||||
|
extern char *p_type(int type);
|
||||||
|
extern char * p_class(int class);
|
||||||
|
extern char *p_time(u_long value);
|
||||||
|
#endif
|
||||||
|
extern char * hostalias(const char *name);
|
||||||
|
extern void sethostfile(char *name);
|
||||||
|
extern void _res_close (void);
|
||||||
|
extern void ruserpass(const char *host, char **aname, char **apass);
|
|
@ -0,0 +1,162 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 1993, 1994, 1997
|
||||||
|
* The Regents of the University of California. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that: (1) source code distributions
|
||||||
|
* retain the above copyright notice and this paragraph in its entirety, (2)
|
||||||
|
* distributions including binary code include the above copyright notice and
|
||||||
|
* this paragraph in its entirety in the documentation or other materials
|
||||||
|
* provided with the distribution, and (3) all advertising materials mentioning
|
||||||
|
* features or use of this software display the following acknowledgement:
|
||||||
|
* ``This product includes software developed by the University of California,
|
||||||
|
* Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
|
||||||
|
* the University nor the names of its contributors may be used to endorse
|
||||||
|
* or promote products derived from this software without specific prior
|
||||||
|
* written permission.
|
||||||
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
|
||||||
|
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
*
|
||||||
|
* @(#) $Header: /tcpdump/master/libpcap/Win32/Include/ip6_misc.h,v 1.1 2002-08-01 08:33:06 risso Exp $ (LBL)
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file contains a collage of declarations for IPv6 from FreeBSD not present in Windows
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <winsock2.h>
|
||||||
|
|
||||||
|
#ifndef __MINGW32__
|
||||||
|
#include <ws2tcpip.h>
|
||||||
|
#endif /* __MINGW32__ */
|
||||||
|
|
||||||
|
#define IN_MULTICAST(a) IN_CLASSD(a)
|
||||||
|
|
||||||
|
#define IN_EXPERIMENTAL(a) ((((u_int32_t) (a)) & 0xe0000000) == 0xe0000000)
|
||||||
|
|
||||||
|
#define IN_LOOPBACKNET 127
|
||||||
|
|
||||||
|
const struct in6_addr in6addr_any; /* :: */
|
||||||
|
const struct in6_addr in6addr_loopback; /* ::1 */
|
||||||
|
|
||||||
|
#ifdef __MINGW32__
|
||||||
|
/* IPv6 address */
|
||||||
|
struct in6_addr
|
||||||
|
{
|
||||||
|
union
|
||||||
|
{
|
||||||
|
u_int8_t u6_addr8[16];
|
||||||
|
u_int16_t u6_addr16[8];
|
||||||
|
u_int32_t u6_addr32[4];
|
||||||
|
} in6_u;
|
||||||
|
#define s6_addr in6_u.u6_addr8
|
||||||
|
#define s6_addr16 in6_u.u6_addr16
|
||||||
|
#define s6_addr32 in6_u.u6_addr32
|
||||||
|
#define s6_addr64 in6_u.u6_addr64
|
||||||
|
};
|
||||||
|
|
||||||
|
#define IN6ADDR_ANY_INIT { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }
|
||||||
|
#define IN6ADDR_LOOPBACK_INIT { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 }
|
||||||
|
#endif /* __MINGW32__ */
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __MINGW32__
|
||||||
|
typedef unsigned short sa_family_t;
|
||||||
|
|
||||||
|
#define __SOCKADDR_COMMON(sa_prefix) \
|
||||||
|
sa_family_t sa_prefix##family
|
||||||
|
|
||||||
|
/* Ditto, for IPv6. */
|
||||||
|
struct sockaddr_in6
|
||||||
|
{
|
||||||
|
__SOCKADDR_COMMON (sin6_);
|
||||||
|
u_int16_t sin6_port; /* Transport layer port # */
|
||||||
|
u_int32_t sin6_flowinfo; /* IPv6 flow information */
|
||||||
|
struct in6_addr sin6_addr; /* IPv6 address */
|
||||||
|
};
|
||||||
|
|
||||||
|
#define IN6_IS_ADDR_V4MAPPED(a) \
|
||||||
|
((((u_int32_t *) (a))[0] == 0) && (((u_int32_t *) (a))[1] == 0) && \
|
||||||
|
(((u_int32_t *) (a))[2] == htonl (0xffff)))
|
||||||
|
|
||||||
|
#define IN6_IS_ADDR_MULTICAST(a) (((u_int8_t *) (a))[0] == 0xff)
|
||||||
|
|
||||||
|
#define IN6_IS_ADDR_LINKLOCAL(a) \
|
||||||
|
((((u_int32_t *) (a))[0] & htonl (0xffc00000)) == htonl (0xfe800000))
|
||||||
|
|
||||||
|
#define IN6_IS_ADDR_LOOPBACK(a) \
|
||||||
|
(((u_int32_t *) (a))[0] == 0 && ((u_int32_t *) (a))[1] == 0 && \
|
||||||
|
((u_int32_t *) (a))[2] == 0 && ((u_int32_t *) (a))[3] == htonl (1))
|
||||||
|
#endif /* __MINGW32__ */
|
||||||
|
|
||||||
|
#define ip6_vfc ip6_ctlun.ip6_un2_vfc
|
||||||
|
#define ip6_flow ip6_ctlun.ip6_un1.ip6_un1_flow
|
||||||
|
#define ip6_plen ip6_ctlun.ip6_un1.ip6_un1_plen
|
||||||
|
#define ip6_nxt ip6_ctlun.ip6_un1.ip6_un1_nxt
|
||||||
|
#define ip6_hlim ip6_ctlun.ip6_un1.ip6_un1_hlim
|
||||||
|
#define ip6_hops ip6_ctlun.ip6_un1.ip6_un1_hlim
|
||||||
|
|
||||||
|
#define nd_rd_type nd_rd_hdr.icmp6_type
|
||||||
|
#define nd_rd_code nd_rd_hdr.icmp6_code
|
||||||
|
#define nd_rd_cksum nd_rd_hdr.icmp6_cksum
|
||||||
|
#define nd_rd_reserved nd_rd_hdr.icmp6_data32[0]
|
||||||
|
|
||||||
|
/*
|
||||||
|
* IPV6 extension headers
|
||||||
|
*/
|
||||||
|
#define IPPROTO_HOPOPTS 0 /* IPv6 hop-by-hop options */
|
||||||
|
#define IPPROTO_IPV6 41 /* IPv6 header. */
|
||||||
|
#define IPPROTO_ROUTING 43 /* IPv6 routing header */
|
||||||
|
#define IPPROTO_FRAGMENT 44 /* IPv6 fragmentation header */
|
||||||
|
#define IPPROTO_ESP 50 /* encapsulating security payload */
|
||||||
|
#define IPPROTO_AH 51 /* authentication header */
|
||||||
|
#define IPPROTO_ICMPV6 58 /* ICMPv6 */
|
||||||
|
#define IPPROTO_NONE 59 /* IPv6 no next header */
|
||||||
|
#define IPPROTO_DSTOPTS 60 /* IPv6 destination options */
|
||||||
|
#define IPPROTO_PIM 103 /* Protocol Independent Multicast. */
|
||||||
|
|
||||||
|
#define IPV6_RTHDR_TYPE_0 0
|
||||||
|
|
||||||
|
/* Option types and related macros */
|
||||||
|
#define IP6OPT_PAD1 0x00 /* 00 0 00000 */
|
||||||
|
#define IP6OPT_PADN 0x01 /* 00 0 00001 */
|
||||||
|
#define IP6OPT_JUMBO 0xC2 /* 11 0 00010 = 194 */
|
||||||
|
#define IP6OPT_JUMBO_LEN 6
|
||||||
|
#define IP6OPT_ROUTER_ALERT 0x05 /* 00 0 00101 */
|
||||||
|
|
||||||
|
#define IP6OPT_RTALERT_LEN 4
|
||||||
|
#define IP6OPT_RTALERT_MLD 0 /* Datagram contains an MLD message */
|
||||||
|
#define IP6OPT_RTALERT_RSVP 1 /* Datagram contains an RSVP message */
|
||||||
|
#define IP6OPT_RTALERT_ACTNET 2 /* contains an Active Networks msg */
|
||||||
|
#define IP6OPT_MINLEN 2
|
||||||
|
|
||||||
|
#define IP6OPT_BINDING_UPDATE 0xc6 /* 11 0 00110 */
|
||||||
|
#define IP6OPT_BINDING_ACK 0x07 /* 00 0 00111 */
|
||||||
|
#define IP6OPT_BINDING_REQ 0x08 /* 00 0 01000 */
|
||||||
|
#define IP6OPT_HOME_ADDRESS 0xc9 /* 11 0 01001 */
|
||||||
|
#define IP6OPT_EID 0x8a /* 10 0 01010 */
|
||||||
|
|
||||||
|
#define IP6OPT_TYPE(o) ((o) & 0xC0)
|
||||||
|
#define IP6OPT_TYPE_SKIP 0x00
|
||||||
|
#define IP6OPT_TYPE_DISCARD 0x40
|
||||||
|
#define IP6OPT_TYPE_FORCEICMP 0x80
|
||||||
|
#define IP6OPT_TYPE_ICMP 0xC0
|
||||||
|
|
||||||
|
#define IP6OPT_MUTABLE 0x20
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __MINGW32__
|
||||||
|
#ifndef EAI_ADDRFAMILY
|
||||||
|
struct addrinfo {
|
||||||
|
int ai_flags; /* AI_PASSIVE, AI_CANONNAME */
|
||||||
|
int ai_family; /* PF_xxx */
|
||||||
|
int ai_socktype; /* SOCK_xxx */
|
||||||
|
int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */
|
||||||
|
size_t ai_addrlen; /* length of ai_addr */
|
||||||
|
char *ai_canonname; /* canonical name for hostname */
|
||||||
|
struct sockaddr *ai_addr; /* binary address */
|
||||||
|
struct addrinfo *ai_next; /* next structure in linked list */
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
#endif /* __MINGW32__ */
|
|
@ -0,0 +1,230 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 1982, 1986, 1989, 1993
|
||||||
|
* The Regents of the University of California. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. All advertising materials mentioning features or use of this software
|
||||||
|
* must display the following acknowledgement:
|
||||||
|
* This product includes software developed by the University of
|
||||||
|
* California, Berkeley and its contributors.
|
||||||
|
* 4. Neither the name of the University nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
* @(#)if.h 8.1 (Berkeley) 6/10/93
|
||||||
|
* $FreeBSD: src/sys/net/if.h,v 1.49.2.1 1999/08/29 16:28:15 peter Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _NET_IF_H_
|
||||||
|
#define _NET_IF_H_
|
||||||
|
|
||||||
|
/*
|
||||||
|
* <net/if.h> does not depend on <sys/time.h> on most other systems. This
|
||||||
|
* helps userland compatability. (struct timeval ifi_lastchange)
|
||||||
|
*/
|
||||||
|
#ifndef KERNEL
|
||||||
|
#include <pcap-stdinc.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Structure describing information about an interface
|
||||||
|
* which may be of interest to management entities.
|
||||||
|
*/
|
||||||
|
struct if_data {
|
||||||
|
/* generic interface information */
|
||||||
|
u_char ifi_type; /* ethernet, tokenring, etc */
|
||||||
|
u_char ifi_physical; /* e.g., AUI, Thinnet, 10base-T, etc */
|
||||||
|
u_char ifi_addrlen; /* media address length */
|
||||||
|
u_char ifi_hdrlen; /* media header length */
|
||||||
|
u_char ifi_recvquota; /* polling quota for receive intrs */
|
||||||
|
u_char ifi_xmitquota; /* polling quota for xmit intrs */
|
||||||
|
u_long ifi_mtu; /* maximum transmission unit */
|
||||||
|
u_long ifi_metric; /* routing metric (external only) */
|
||||||
|
u_long ifi_baudrate; /* linespeed */
|
||||||
|
/* volatile statistics */
|
||||||
|
u_long ifi_ipackets; /* packets received on interface */
|
||||||
|
u_long ifi_ierrors; /* input errors on interface */
|
||||||
|
u_long ifi_opackets; /* packets sent on interface */
|
||||||
|
u_long ifi_oerrors; /* output errors on interface */
|
||||||
|
u_long ifi_collisions; /* collisions on csma interfaces */
|
||||||
|
u_long ifi_ibytes; /* total number of octets received */
|
||||||
|
u_long ifi_obytes; /* total number of octets sent */
|
||||||
|
u_long ifi_imcasts; /* packets received via multicast */
|
||||||
|
u_long ifi_omcasts; /* packets sent via multicast */
|
||||||
|
u_long ifi_iqdrops; /* dropped on input, this interface */
|
||||||
|
u_long ifi_noproto; /* destined for unsupported protocol */
|
||||||
|
u_long ifi_recvtiming; /* usec spent receiving when timing */
|
||||||
|
u_long ifi_xmittiming; /* usec spent xmitting when timing */
|
||||||
|
struct timeval ifi_lastchange; /* time of last administrative change */
|
||||||
|
};
|
||||||
|
|
||||||
|
/* ws2tcpip.h has interface flags: IFF_* */
|
||||||
|
#if 0
|
||||||
|
#define IFF_UP 0x1 /* interface is up */
|
||||||
|
#define IFF_BROADCAST 0x2 /* broadcast address valid */
|
||||||
|
#define IFF_DEBUG 0x4 /* turn on debugging */
|
||||||
|
#define IFF_LOOPBACK 0x8 /* is a loopback net */
|
||||||
|
#define IFF_POINTOPOINT 0x10 /* interface is point-to-point link */
|
||||||
|
/*#define IFF_NOTRAILERS 0x20 * obsolete: avoid use of trailers */
|
||||||
|
#define IFF_RUNNING 0x40 /* resources allocated */
|
||||||
|
#define IFF_NOARP 0x80 /* no address resolution protocol */
|
||||||
|
#define IFF_PROMISC 0x100 /* receive all packets */
|
||||||
|
#define IFF_ALLMULTI 0x200 /* receive all multicast packets */
|
||||||
|
#define IFF_OACTIVE 0x400 /* transmission in progress */
|
||||||
|
#define IFF_SIMPLEX 0x800 /* can't hear own transmissions */
|
||||||
|
#define IFF_LINK0 0x1000 /* per link layer defined bit */
|
||||||
|
#define IFF_LINK1 0x2000 /* per link layer defined bit */
|
||||||
|
#define IFF_LINK2 0x4000 /* per link layer defined bit */
|
||||||
|
#define IFF_ALTPHYS IFF_LINK2 /* use alternate physical connection */
|
||||||
|
#define IFF_MULTICAST 0x8000 /* supports multicast */
|
||||||
|
#endif /* 0 */
|
||||||
|
|
||||||
|
/* flags set internally only: */
|
||||||
|
#define IFF_CANTCHANGE \
|
||||||
|
(IFF_BROADCAST|IFF_POINTOPOINT|IFF_RUNNING|IFF_OACTIVE|\
|
||||||
|
IFF_SIMPLEX|IFF_MULTICAST|IFF_ALLMULTI)
|
||||||
|
|
||||||
|
#define IFQ_MAXLEN 50
|
||||||
|
#define IFNET_SLOWHZ 1 /* granularity is 1 second */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Message format for use in obtaining information about interfaces
|
||||||
|
* from getkerninfo and the routing socket
|
||||||
|
*/
|
||||||
|
struct if_msghdr {
|
||||||
|
u_short ifm_msglen; /* to skip over non-understood messages */
|
||||||
|
u_char ifm_version; /* future binary compatability */
|
||||||
|
u_char ifm_type; /* message type */
|
||||||
|
int ifm_addrs; /* like rtm_addrs */
|
||||||
|
int ifm_flags; /* value of if_flags */
|
||||||
|
u_short ifm_index; /* index for associated ifp */
|
||||||
|
struct if_data ifm_data;/* statistics and other data about if */
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Message format for use in obtaining information about interface addresses
|
||||||
|
* from getkerninfo and the routing socket
|
||||||
|
*/
|
||||||
|
struct ifa_msghdr {
|
||||||
|
u_short ifam_msglen; /* to skip over non-understood messages */
|
||||||
|
u_char ifam_version; /* future binary compatability */
|
||||||
|
u_char ifam_type; /* message type */
|
||||||
|
int ifam_addrs; /* like rtm_addrs */
|
||||||
|
int ifam_flags; /* value of ifa_flags */
|
||||||
|
u_short ifam_index; /* index for associated ifp */
|
||||||
|
int ifam_metric; /* value of ifa_metric */
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Message format for use in obtaining information about multicast addresses
|
||||||
|
* from the routing socket
|
||||||
|
*/
|
||||||
|
struct ifma_msghdr {
|
||||||
|
u_short ifmam_msglen; /* to skip over non-understood messages */
|
||||||
|
u_char ifmam_version; /* future binary compatability */
|
||||||
|
u_char ifmam_type; /* message type */
|
||||||
|
int ifmam_addrs; /* like rtm_addrs */
|
||||||
|
int ifmam_flags; /* value of ifa_flags */
|
||||||
|
u_short ifmam_index; /* index for associated ifp */
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Interface request structure used for socket
|
||||||
|
* ioctl's. All interface ioctl's must have parameter
|
||||||
|
* definitions which begin with ifr_name. The
|
||||||
|
* remainder may be interface specific.
|
||||||
|
*/
|
||||||
|
struct ifreq {
|
||||||
|
#define IFNAMSIZ 16
|
||||||
|
char ifr_name[IFNAMSIZ]; /* if name, e.g. "en0" */
|
||||||
|
union {
|
||||||
|
struct sockaddr ifru_addr;
|
||||||
|
struct sockaddr ifru_dstaddr;
|
||||||
|
struct sockaddr ifru_broadaddr;
|
||||||
|
short ifru_flags;
|
||||||
|
int ifru_metric;
|
||||||
|
int ifru_mtu;
|
||||||
|
int ifru_phys;
|
||||||
|
int ifru_media;
|
||||||
|
caddr_t ifru_data;
|
||||||
|
} ifr_ifru;
|
||||||
|
#define ifr_addr ifr_ifru.ifru_addr /* address */
|
||||||
|
#define ifr_dstaddr ifr_ifru.ifru_dstaddr /* other end of p-to-p link */
|
||||||
|
#define ifr_broadaddr ifr_ifru.ifru_broadaddr /* broadcast address */
|
||||||
|
#define ifr_flags ifr_ifru.ifru_flags /* flags */
|
||||||
|
#define ifr_metric ifr_ifru.ifru_metric /* metric */
|
||||||
|
#define ifr_mtu ifr_ifru.ifru_mtu /* mtu */
|
||||||
|
#define ifr_phys ifr_ifru.ifru_phys /* physical wire */
|
||||||
|
#define ifr_media ifr_ifru.ifru_media /* physical media */
|
||||||
|
#define ifr_data ifr_ifru.ifru_data /* for use by interface */
|
||||||
|
};
|
||||||
|
|
||||||
|
#define _SIZEOF_ADDR_IFREQ(ifr) \
|
||||||
|
((ifr).ifr_addr.sa_len > sizeof(struct sockaddr) ? \
|
||||||
|
(sizeof(struct ifreq) - sizeof(struct sockaddr) + \
|
||||||
|
(ifr).ifr_addr.sa_len) : sizeof(struct ifreq))
|
||||||
|
|
||||||
|
struct ifaliasreq {
|
||||||
|
char ifra_name[IFNAMSIZ]; /* if name, e.g. "en0" */
|
||||||
|
struct sockaddr ifra_addr;
|
||||||
|
struct sockaddr ifra_broadaddr;
|
||||||
|
struct sockaddr ifra_mask;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ifmediareq {
|
||||||
|
char ifm_name[IFNAMSIZ]; /* if name, e.g. "en0" */
|
||||||
|
int ifm_current; /* current media options */
|
||||||
|
int ifm_mask; /* don't care mask */
|
||||||
|
int ifm_status; /* media status */
|
||||||
|
int ifm_active; /* active options */
|
||||||
|
int ifm_count; /* # entries in ifm_ulist array */
|
||||||
|
int *ifm_ulist; /* media words */
|
||||||
|
};
|
||||||
|
/*
|
||||||
|
* Structure used in SIOCGIFCONF request.
|
||||||
|
* Used to retrieve interface configuration
|
||||||
|
* for machine (useful for programs which
|
||||||
|
* must know all networks accessible).
|
||||||
|
*/
|
||||||
|
struct ifconf {
|
||||||
|
int ifc_len; /* size of associated buffer */
|
||||||
|
union {
|
||||||
|
caddr_t ifcu_buf;
|
||||||
|
struct ifreq *ifcu_req;
|
||||||
|
} ifc_ifcu;
|
||||||
|
#define ifc_buf ifc_ifcu.ifcu_buf /* buffer address */
|
||||||
|
#define ifc_req ifc_ifcu.ifcu_req /* array of structures returned */
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifdef KERNEL
|
||||||
|
#ifdef MALLOC_DECLARE
|
||||||
|
MALLOC_DECLARE(M_IFADDR);
|
||||||
|
MALLOC_DECLARE(M_IFMADDR);
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* XXX - this should go away soon */
|
||||||
|
#ifdef KERNEL
|
||||||
|
#include <net/if_var.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* !_NET_IF_H_ */
|
|
@ -0,0 +1,164 @@
|
||||||
|
/*-
|
||||||
|
* Copyright (c) 1980, 1983, 1988, 1993
|
||||||
|
* The Regents of the University of California. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. All advertising materials mentioning features or use of this software
|
||||||
|
* must display the following acknowledgement:
|
||||||
|
* This product includes software developed by the University of
|
||||||
|
* California, Berkeley and its contributors.
|
||||||
|
* 4. Neither the name of the University nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
* @(#)netdb.h 8.1 (Berkeley) 6/2/93
|
||||||
|
* netdb.h,v 1.4 1995/08/14 04:05:04 hjl Exp
|
||||||
|
* -
|
||||||
|
* Portions Copyright (c) 1993 by Digital Equipment Corporation.
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies, and that
|
||||||
|
* the name of Digital Equipment Corporation not be used in advertising or
|
||||||
|
* publicity pertaining to distribution of the document or software without
|
||||||
|
* specific, written prior permission.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
|
||||||
|
* WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
|
||||||
|
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
|
||||||
|
* CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
|
||||||
|
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
|
||||||
|
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
||||||
|
* SOFTWARE.
|
||||||
|
* -
|
||||||
|
* --Copyright--
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _NETDB_H_
|
||||||
|
#define _NETDB_H_
|
||||||
|
|
||||||
|
#if defined(_POSIX_THREAD_SAFE_FUNCTIONS) || defined(_REENTRANT)
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <winsock2.h>
|
||||||
|
#include <net/paths.h>
|
||||||
|
|
||||||
|
#define _PATH_HEQUIV __PATH_ETC_INET"/hosts.equiv"
|
||||||
|
#define _PATH_HOSTS __PATH_ETC_INET"/hosts"
|
||||||
|
#define _PATH_NETWORKS __PATH_ETC_INET"/networks"
|
||||||
|
#define _PATH_PROTOCOLS __PATH_ETC_INET"/protocols"
|
||||||
|
#define _PATH_SERVICES __PATH_ETC_INET"/services"
|
||||||
|
#define _PATH_RESCONF __PATH_ETC_INET"/resolv.conf"
|
||||||
|
#define _PATH_RPC __PATH_ETC_INET"/rpc"
|
||||||
|
|
||||||
|
struct rpcent {
|
||||||
|
char *r_name; /* name of server for this rpc program */
|
||||||
|
char **r_aliases; /* alias list */
|
||||||
|
int r_number; /* rpc program number */
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifndef WIN32
|
||||||
|
#if defined(_POSIX_THREAD_SAFE_FUNCTIONS) || defined(_REENTRANT)
|
||||||
|
|
||||||
|
#define __NETDB_MAXALIASES 35
|
||||||
|
#define __NETDB_MAXADDRS 35
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Error return codes from gethostbyname() and gethostbyaddr()
|
||||||
|
* (left in extern int h_errno).
|
||||||
|
*/
|
||||||
|
#define h_errno (*__h_errno_location ())
|
||||||
|
#else
|
||||||
|
extern int h_errno;
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define NETDB_INTERNAL -1 /* see errno */
|
||||||
|
#define NETDB_SUCCESS 0 /* no problem */
|
||||||
|
|
||||||
|
//#include <features.h>
|
||||||
|
|
||||||
|
void endhostent (void);
|
||||||
|
void endnetent (void);
|
||||||
|
void endprotoent (void);
|
||||||
|
void endservent (void);
|
||||||
|
void endrpcent (void);
|
||||||
|
struct hostent *gethostent (void);
|
||||||
|
struct netent *getnetbyaddr (long, int); /* u_long? */
|
||||||
|
struct netent *getnetbyname (const char *);
|
||||||
|
struct netent *getnetent (void);
|
||||||
|
struct protoent *getprotoent (void);
|
||||||
|
struct servent *getservent (void);
|
||||||
|
struct rpcent *getrpcent (void);
|
||||||
|
struct rpcent *getrpcbyname (const char *);
|
||||||
|
struct rpcent *getrpcbynumber (int);
|
||||||
|
void herror (const char *);
|
||||||
|
void sethostent (int);
|
||||||
|
/* void sethostfile (const char *); */
|
||||||
|
void setnetent (int);
|
||||||
|
void setprotoent (int);
|
||||||
|
void setservent (int);
|
||||||
|
void setrpcent (int);
|
||||||
|
|
||||||
|
#if defined(_POSIX_THREAD_SAFE_FUNCTIONS) || defined(_REENTRANT)
|
||||||
|
struct hostent *gethostbyaddr_r (const char *__addr,
|
||||||
|
int __length, int __type,
|
||||||
|
struct hostent *__result,
|
||||||
|
char *__buffer, int __buflen, int *__h_errnop);
|
||||||
|
struct hostent *gethostbyname_r (const char * __name,
|
||||||
|
struct hostent *__result, char *__buffer,
|
||||||
|
int __buflen, int *__h_errnop);
|
||||||
|
struct hostent *gethostent_r (struct hostent *__result,
|
||||||
|
char *__buffer, int __buflen, int *__h_errnop);
|
||||||
|
struct netent *getnetbyaddr_r (long __net, int __type,
|
||||||
|
struct netent *__result, char *__buffer,
|
||||||
|
int __buflen);
|
||||||
|
struct netent *getnetbyname_r (const char * __name,
|
||||||
|
struct netent *__result, char *__buffer,
|
||||||
|
int __buflen);
|
||||||
|
struct netent *getnetent_r (struct netent *__result,
|
||||||
|
char *__buffer, int __buflen);
|
||||||
|
struct protoent *getprotobyname_r (const char * __name,
|
||||||
|
struct protoent *__result, char *__buffer,
|
||||||
|
int __buflen);
|
||||||
|
struct protoent *getprotobynumber_r (int __proto,
|
||||||
|
struct protoent *__result, char *__buffer,
|
||||||
|
int __buflen);
|
||||||
|
struct protoent *getprotoent_r (struct protoent *__result,
|
||||||
|
char *__buffer, int __buflen);
|
||||||
|
struct servent *getservbyname_r (const char * __name,
|
||||||
|
const char *__proto, struct servent *__result,
|
||||||
|
char *__buffer, int __buflen);
|
||||||
|
struct servent *getservbyport_r (int __port,
|
||||||
|
const char *__proto, struct servent *__result,
|
||||||
|
char *__buffer, int __buflen);
|
||||||
|
struct servent *getservent_r (struct servent *__result,
|
||||||
|
char *__buffer, int __buflen);
|
||||||
|
|
||||||
|
int *__h_errno_location (void);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* !_NETDB_H_ */
|
|
@ -0,0 +1,105 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 1989 The Regents of the University of California.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. All advertising materials mentioning features or use of this software
|
||||||
|
* must display the following acknowledgement:
|
||||||
|
* This product includes software developed by the University of
|
||||||
|
* California, Berkeley and its contributors.
|
||||||
|
* 4. Neither the name of the University nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
* @(#)paths.h 5.15 (Berkeley) 5/29/91
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _PATHS_H_
|
||||||
|
#define _PATHS_H_
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
#define __PATH_ETC_INET "/usr/etc/inet"
|
||||||
|
#else
|
||||||
|
#define __PATH_ETC_INET "/etc"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Default search path. */
|
||||||
|
#define _PATH_DEFPATH "/usr/local/bin:/usr/bin:/bin:."
|
||||||
|
#define _PATH_DEFPATH_ROOT "/sbin:/bin:/usr/sbin:/usr/bin"
|
||||||
|
|
||||||
|
#define _PATH_BSHELL "/bin/sh"
|
||||||
|
#define _PATH_CONSOLE "/dev/console"
|
||||||
|
#define _PATH_CSHELL "/bin/csh"
|
||||||
|
#define _PATH_DEVDB "/var/run/dev.db"
|
||||||
|
#define _PATH_DEVNULL "/dev/null"
|
||||||
|
#define _PATH_DRUM "/dev/drum"
|
||||||
|
#define _PATH_HEQUIV __PATH_ETC_INET"/hosts.equiv"
|
||||||
|
#define _PATH_KMEM "/dev/kmem"
|
||||||
|
#define _PATH_MAILDIR "/var/spool/mail"
|
||||||
|
#define _PATH_MAN "/usr/man"
|
||||||
|
#define _PATH_MEM "/dev/mem"
|
||||||
|
#define _PATH_LOGIN "/bin/login"
|
||||||
|
#define _PATH_NOLOGIN "/etc/nologin"
|
||||||
|
#define _PATH_SENDMAIL "/usr/sbin/sendmail"
|
||||||
|
#define _PATH_SHELLS "/etc/shells"
|
||||||
|
#define _PATH_TTY "/dev/tty"
|
||||||
|
#define _PATH_UNIX "/vmlinux"
|
||||||
|
#define _PATH_VI "/usr/bin/vi"
|
||||||
|
|
||||||
|
/* Provide trailing slash, since mostly used for building pathnames. */
|
||||||
|
#define _PATH_DEV "/dev/"
|
||||||
|
#define _PATH_TMP "/tmp/"
|
||||||
|
#define _PATH_VARRUN "/var/run/"
|
||||||
|
#define _PATH_VARTMP "/var/tmp/"
|
||||||
|
|
||||||
|
#define _PATH_KLOG "/proc/kmsg"
|
||||||
|
#define _PATH_LOGCONF __PATH_ETC_INET"/syslog.conf"
|
||||||
|
#if 0
|
||||||
|
#define _PATH_LOGPID __PATH_ETC_INET"/syslog.pid"
|
||||||
|
#else
|
||||||
|
#define _PATH_LOGPID "/var/run/syslog.pid"
|
||||||
|
#endif
|
||||||
|
#define _PATH_LOG "/dev/log"
|
||||||
|
#define _PATH_CONSOLE "/dev/console"
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
#define _PATH_UTMP "/var/adm/utmp"
|
||||||
|
#define _PATH_WTMP "/var/adm/wtmp"
|
||||||
|
#define _PATH_LASTLOG "/var/adm/lastlog"
|
||||||
|
#else
|
||||||
|
#define _PATH_UTMP "/var/run/utmp"
|
||||||
|
#define _PATH_WTMP "/var/log/wtmp"
|
||||||
|
#define _PATH_LASTLOG "/var/log/lastlog"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define _PATH_LOCALE "/usr/lib/locale"
|
||||||
|
|
||||||
|
#define _PATH_RWHODIR "/var/spool/rwho"
|
||||||
|
|
||||||
|
#if _MIT_POSIX_THREADS
|
||||||
|
/* For the MIT pthreads */
|
||||||
|
#define _PATH_PTY "/dev/"
|
||||||
|
#define _PATH_TZDIR "/usr/lib/zoneinfo"
|
||||||
|
#define _PATH_TZFILE "/usr/lib/zoneinfo/localtime"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* !_PATHS_H_ */
|
|
@ -0,0 +1,38 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 1999 WIDE Project.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of the project nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
struct sockaddr_storage {
|
||||||
|
#ifdef HAVE_SOCKADDR_SA_LEN
|
||||||
|
u_int8_t __ss_len;
|
||||||
|
u_int8_t __ss_family;
|
||||||
|
u_int8_t fill[126];
|
||||||
|
#else
|
||||||
|
u_int8_t __ss_family;
|
||||||
|
u_int8_t fill[127];
|
||||||
|
#endif /* HAVE_SOCKADDR_SA_LEN */
|
||||||
|
};
|
|
@ -0,0 +1,54 @@
|
||||||
|
/*-
|
||||||
|
* Copyright (c) 1990, 1993
|
||||||
|
* The Regents of the University of California. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. All advertising materials mentioning features or use of this software
|
||||||
|
* must display the following acknowledgement:
|
||||||
|
* This product includes software developed by the University of
|
||||||
|
* California, Berkeley and its contributors.
|
||||||
|
* 4. Neither the name of the University nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(LIBC_SCCS) && !defined(lint)
|
||||||
|
static char sccsid[] = "@(#)ffs.c 8.1 (Berkeley) 6/4/93";
|
||||||
|
#endif /* LIBC_SCCS and not lint */
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ffs -- vax ffs instruction
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
ffs(mask)
|
||||||
|
register int mask;
|
||||||
|
{
|
||||||
|
register int bit;
|
||||||
|
|
||||||
|
if (mask == 0)
|
||||||
|
return(0);
|
||||||
|
for (bit = 1; !(mask & 1); bit++)
|
||||||
|
mask >>= 1;
|
||||||
|
return(bit);
|
||||||
|
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,44 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 1983 Regents of the University of California.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms are permitted
|
||||||
|
* provided that the above copyright notice and this paragraph are
|
||||||
|
* duplicated in all such forms and that any documentation,
|
||||||
|
* advertising materials, and other materials related to such
|
||||||
|
* distribution and use acknowledge that the software was developed
|
||||||
|
* by the University of California, Berkeley. The name of the
|
||||||
|
* University may not be used to endorse or promote products derived
|
||||||
|
* from this software without specific prior written permission.
|
||||||
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
||||||
|
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||||
|
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(LIBC_SCCS) && !defined(lint)
|
||||||
|
static char sccsid[] = "@(#)getnetbyname.c 5.5 (Berkeley) 6/27/88";
|
||||||
|
#endif /* LIBC_SCCS and not lint */
|
||||||
|
|
||||||
|
#include "inetprivate.h"
|
||||||
|
|
||||||
|
extern int _net_stayopen;
|
||||||
|
|
||||||
|
struct netent *
|
||||||
|
getnetbyname(const char *name)
|
||||||
|
{
|
||||||
|
register struct netent *p;
|
||||||
|
register char **cp;
|
||||||
|
|
||||||
|
setnetent(_net_stayopen);
|
||||||
|
while (p = getnetent()) {
|
||||||
|
if (strcmp(p->n_name, name) == 0)
|
||||||
|
break;
|
||||||
|
for (cp = p->n_aliases; *cp != 0; cp++)
|
||||||
|
if (strcmp(*cp, name) == 0)
|
||||||
|
goto found;
|
||||||
|
}
|
||||||
|
found:
|
||||||
|
if (!_net_stayopen)
|
||||||
|
endnetent();
|
||||||
|
return (p);
|
||||||
|
}
|
|
@ -0,0 +1,119 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 1983 Regents of the University of California.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms are permitted
|
||||||
|
* provided that the above copyright notice and this paragraph are
|
||||||
|
* duplicated in all such forms and that any documentation,
|
||||||
|
* advertising materials, and other materials related to such
|
||||||
|
* distribution and use acknowledge that the software was developed
|
||||||
|
* by the University of California, Berkeley. The name of the
|
||||||
|
* University may not be used to endorse or promote products derived
|
||||||
|
* from this software without specific prior written permission.
|
||||||
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
||||||
|
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||||
|
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(LIBC_SCCS) && !defined(lint)
|
||||||
|
static char sccsid[] = "@(#)getnetent.c 5.5 (Berkeley) 6/27/88";
|
||||||
|
#endif /* LIBC_SCCS and not lint */
|
||||||
|
|
||||||
|
#include "inetprivate.h"
|
||||||
|
|
||||||
|
#define MAXALIASES 35
|
||||||
|
|
||||||
|
static char NETDB[] = _PATH_NETWORKS;
|
||||||
|
static FILE *netf = NULL;
|
||||||
|
static char line[BUFSIZ+1];
|
||||||
|
static struct netent net;
|
||||||
|
static char *net_aliases[MAXALIASES];
|
||||||
|
static char *any(char *, char *);
|
||||||
|
|
||||||
|
int _net_stayopen;
|
||||||
|
extern u_int32_t inet_network(const char *cp);
|
||||||
|
|
||||||
|
void
|
||||||
|
setnetent(f)
|
||||||
|
int f;
|
||||||
|
{
|
||||||
|
if (netf == NULL)
|
||||||
|
netf = fopen(NETDB, "r" );
|
||||||
|
else
|
||||||
|
rewind(netf);
|
||||||
|
_net_stayopen |= f;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
endnetent()
|
||||||
|
{
|
||||||
|
if (netf) {
|
||||||
|
fclose(netf);
|
||||||
|
netf = NULL;
|
||||||
|
}
|
||||||
|
_net_stayopen = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct netent *
|
||||||
|
getnetent()
|
||||||
|
{
|
||||||
|
char *p;
|
||||||
|
register char *cp, **q;
|
||||||
|
|
||||||
|
if (netf == NULL && (netf = fopen(NETDB, "r" )) == NULL)
|
||||||
|
return (NULL);
|
||||||
|
again:
|
||||||
|
p = fgets(line, BUFSIZ, netf);
|
||||||
|
if (p == NULL)
|
||||||
|
return (NULL);
|
||||||
|
if (*p == '#')
|
||||||
|
goto again;
|
||||||
|
cp = any(p, "#\n");
|
||||||
|
if (cp == NULL)
|
||||||
|
goto again;
|
||||||
|
*cp = '\0';
|
||||||
|
net.n_name = p;
|
||||||
|
cp = any(p, " \t");
|
||||||
|
if (cp == NULL)
|
||||||
|
goto again;
|
||||||
|
*cp++ = '\0';
|
||||||
|
while (*cp == ' ' || *cp == '\t')
|
||||||
|
cp++;
|
||||||
|
p = any(cp, " \t");
|
||||||
|
if (p != NULL)
|
||||||
|
*p++ = '\0';
|
||||||
|
net.n_net = inet_network(cp);
|
||||||
|
net.n_addrtype = AF_INET;
|
||||||
|
q = net.n_aliases = net_aliases;
|
||||||
|
if (p != NULL)
|
||||||
|
cp = p;
|
||||||
|
while (cp && *cp) {
|
||||||
|
if (*cp == ' ' || *cp == '\t') {
|
||||||
|
cp++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (q < &net_aliases[MAXALIASES - 1])
|
||||||
|
*q++ = cp;
|
||||||
|
cp = any(cp, " \t");
|
||||||
|
if (cp != NULL)
|
||||||
|
*cp++ = '\0';
|
||||||
|
}
|
||||||
|
*q = NULL;
|
||||||
|
return (&net);
|
||||||
|
}
|
||||||
|
|
||||||
|
static char *
|
||||||
|
any(cp, match)
|
||||||
|
register char *cp;
|
||||||
|
char *match;
|
||||||
|
{
|
||||||
|
register char *mp, c;
|
||||||
|
|
||||||
|
while (c = *cp) {
|
||||||
|
for (mp = match; *mp; mp++)
|
||||||
|
if (*mp == c)
|
||||||
|
return (cp);
|
||||||
|
cp++;
|
||||||
|
}
|
||||||
|
return ((char *)0);
|
||||||
|
}
|
|
@ -0,0 +1,121 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 1987, 1993, 1994
|
||||||
|
* The Regents of the University of California. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. All advertising materials mentioning features or use of this software
|
||||||
|
* must display the following acknowledgement:
|
||||||
|
* This product includes software developed by the University of
|
||||||
|
* California, Berkeley and its contributors.
|
||||||
|
* 4. Neither the name of the University nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(LIBC_SCCS) && !defined(lint)
|
||||||
|
static char sccsid[] = "@(#)getopt.c 8.3 (Berkeley) 4/27/95";
|
||||||
|
#endif /* LIBC_SCCS and not lint */
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
int opterr = 1, /* if error message should be printed */
|
||||||
|
optind = 1, /* index into parent argv vector */
|
||||||
|
optopt, /* character checked for validity */
|
||||||
|
optreset; /* reset getopt */
|
||||||
|
char *optarg; /* argument associated with option */
|
||||||
|
|
||||||
|
#define BADCH (int)'?'
|
||||||
|
#define BADARG (int)':'
|
||||||
|
#define EMSG ""
|
||||||
|
|
||||||
|
/*
|
||||||
|
* getopt --
|
||||||
|
* Parse argc/argv argument vector.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
getopt(nargc, nargv, ostr)
|
||||||
|
int nargc;
|
||||||
|
char * const *nargv;
|
||||||
|
const char *ostr;
|
||||||
|
{
|
||||||
|
#ifdef WIN32
|
||||||
|
char *__progname="windump";
|
||||||
|
#else
|
||||||
|
extern char *__progname;
|
||||||
|
#endif
|
||||||
|
static char *place = EMSG; /* option letter processing */
|
||||||
|
char *oli; /* option letter list index */
|
||||||
|
|
||||||
|
if (optreset || !*place) { /* update scanning pointer */
|
||||||
|
optreset = 0;
|
||||||
|
if (optind >= nargc || *(place = nargv[optind]) != '-') {
|
||||||
|
place = EMSG;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
if (place[1] && *++place == '-') { /* found "--" */
|
||||||
|
++optind;
|
||||||
|
place = EMSG;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
} /* option letter okay? */
|
||||||
|
if ((optopt = (int)*place++) == (int)':' ||
|
||||||
|
!(oli = strchr(ostr, optopt))) {
|
||||||
|
/*
|
||||||
|
* if the user didn't specify '-' as an option,
|
||||||
|
* assume it means -1.
|
||||||
|
*/
|
||||||
|
if (optopt == (int)'-')
|
||||||
|
return (-1);
|
||||||
|
if (!*place)
|
||||||
|
++optind;
|
||||||
|
if (opterr && *ostr != ':')
|
||||||
|
(void)fprintf(stderr,
|
||||||
|
"%s: illegal option -- %c\n", __progname, optopt);
|
||||||
|
return (BADCH);
|
||||||
|
}
|
||||||
|
if (*++oli != ':') { /* don't need argument */
|
||||||
|
optarg = NULL;
|
||||||
|
if (!*place)
|
||||||
|
++optind;
|
||||||
|
}
|
||||||
|
else { /* need an argument */
|
||||||
|
if (*place) /* no white space */
|
||||||
|
optarg = place;
|
||||||
|
else if (nargc <= ++optind) { /* no arg */
|
||||||
|
place = EMSG;
|
||||||
|
if (*ostr == ':')
|
||||||
|
return (BADARG);
|
||||||
|
if (opterr)
|
||||||
|
(void)fprintf(stderr,
|
||||||
|
"%s: option requires an argument -- %c\n",
|
||||||
|
__progname, optopt);
|
||||||
|
return (BADCH);
|
||||||
|
}
|
||||||
|
else /* white space */
|
||||||
|
optarg = nargv[optind];
|
||||||
|
place = EMSG;
|
||||||
|
++optind;
|
||||||
|
}
|
||||||
|
return (optopt); /* dump back option letter */
|
||||||
|
}
|
|
@ -0,0 +1,125 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 1983, 1993
|
||||||
|
* The Regents of the University of California. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. All advertising materials mentioning features or use of this software
|
||||||
|
* must display the following acknowledgement:
|
||||||
|
* This product includes software developed by the University of
|
||||||
|
* California, Berkeley and its contributors.
|
||||||
|
* 4. Neither the name of the University nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(LIBC_SCCS) && !defined(lint)
|
||||||
|
static char sccsid[] = "@(#)getservent.c 8.1 (Berkeley) 6/4/93";
|
||||||
|
#endif /* LIBC_SCCS and not lint */
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <net/netdb.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <arpa/nameser.h>
|
||||||
|
|
||||||
|
#define MAXALIASES 35
|
||||||
|
|
||||||
|
static char SERVDB[] = _PATH_SERVICES;
|
||||||
|
static FILE *servf = NULL;
|
||||||
|
static char line[BUFSIZ+1];
|
||||||
|
static struct servent serv;
|
||||||
|
static char *serv_aliases[MAXALIASES];
|
||||||
|
int _serv_stayopen;
|
||||||
|
|
||||||
|
void
|
||||||
|
setservent(f)
|
||||||
|
int f;
|
||||||
|
{
|
||||||
|
if (servf == NULL)
|
||||||
|
servf = fopen(SERVDB, "r" );
|
||||||
|
else
|
||||||
|
rewind(servf);
|
||||||
|
_serv_stayopen |= f;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
endservent()
|
||||||
|
{
|
||||||
|
if (servf) {
|
||||||
|
fclose(servf);
|
||||||
|
servf = NULL;
|
||||||
|
}
|
||||||
|
_serv_stayopen = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct servent *
|
||||||
|
getservent()
|
||||||
|
{
|
||||||
|
char *p;
|
||||||
|
register char *cp, **q;
|
||||||
|
|
||||||
|
if (servf == NULL && (servf = fopen(SERVDB, "r" )) == NULL)
|
||||||
|
return (NULL);
|
||||||
|
again:
|
||||||
|
if ((p = fgets(line, BUFSIZ, servf)) == NULL)
|
||||||
|
return (NULL);
|
||||||
|
if (*p == '#')
|
||||||
|
goto again;
|
||||||
|
cp = strpbrk(p, "#\n");
|
||||||
|
if (cp == NULL)
|
||||||
|
goto again;
|
||||||
|
*cp = '\0';
|
||||||
|
serv.s_name = p;
|
||||||
|
p = strpbrk(p, " \t");
|
||||||
|
if (p == NULL)
|
||||||
|
goto again;
|
||||||
|
*p++ = '\0';
|
||||||
|
while (*p == ' ' || *p == '\t')
|
||||||
|
p++;
|
||||||
|
cp = strpbrk(p, ",/");
|
||||||
|
if (cp == NULL)
|
||||||
|
goto again;
|
||||||
|
*cp++ = '\0';
|
||||||
|
serv.s_port = htons((u_short)atoi(p));
|
||||||
|
serv.s_proto = cp;
|
||||||
|
q = serv.s_aliases = serv_aliases;
|
||||||
|
cp = strpbrk(cp, " \t");
|
||||||
|
if (cp != NULL)
|
||||||
|
*cp++ = '\0';
|
||||||
|
while (cp && *cp) {
|
||||||
|
if (*cp == ' ' || *cp == '\t') {
|
||||||
|
cp++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (q < &serv_aliases[MAXALIASES - 1])
|
||||||
|
*q++ = cp;
|
||||||
|
cp = strpbrk(cp, " \t");
|
||||||
|
if (cp != NULL)
|
||||||
|
*cp++ = '\0';
|
||||||
|
}
|
||||||
|
*q = NULL;
|
||||||
|
return (&serv);
|
||||||
|
}
|
|
@ -0,0 +1,61 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 1995, 1996, 1997 Kungliga Tekniska Högskolan
|
||||||
|
* (Royal Institute of Technology, Stockholm, Sweden).
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* 3. All advertising materials mentioning features or use of this software
|
||||||
|
* must display the following acknowledgement:
|
||||||
|
* This product includes software developed by the Kungliga Tekniska
|
||||||
|
* Högskolan and its contributors.
|
||||||
|
*
|
||||||
|
* 4. Neither the name of the Institute nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* $Id: inet_aton.c,v 1.1 2002-08-01 08:33:10 risso Exp $ */
|
||||||
|
|
||||||
|
#ifndef lint
|
||||||
|
static const char rcsid[] =
|
||||||
|
"@(#) $Header: /tcpdump/master/libpcap/Win32/Src/inet_aton.c,v 1.1 2002-08-01 08:33:10 risso Exp $";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <pcap-stdinc.h>
|
||||||
|
|
||||||
|
/* Minimal implementation of inet_aton.
|
||||||
|
* Cannot distinguish between failure and a local broadcast address. */
|
||||||
|
|
||||||
|
#ifndef INADDR_NONE
|
||||||
|
#define INADDR_NONE 0xffffffff
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int
|
||||||
|
inet_aton(const char *cp, struct in_addr *addr)
|
||||||
|
{
|
||||||
|
addr->s_addr = inet_addr(cp);
|
||||||
|
return (addr->s_addr == INADDR_NONE) ? 0 : 1;
|
||||||
|
}
|
|
@ -0,0 +1,101 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 1983, 1993
|
||||||
|
* The Regents of the University of California. All rights reserved.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. All advertising materials mentioning features or use of this software
|
||||||
|
* must display the following acknowledgement:
|
||||||
|
* This product includes software developed by the University of
|
||||||
|
* California, Berkeley and its contributors.
|
||||||
|
* 4. Neither the name of the University nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(LIBC_SCCS) && !defined(lint)
|
||||||
|
static char sccsid[] = "@(#)inet_network.c 8.1 (Berkeley) 6/4/93";
|
||||||
|
#endif /* LIBC_SCCS and not lint */
|
||||||
|
|
||||||
|
#include "inetprivate.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Internet network address interpretation routine.
|
||||||
|
* The library routines call this routine to interpret
|
||||||
|
* network numbers.
|
||||||
|
*/
|
||||||
|
u_int32_t
|
||||||
|
inet_network(const char *cp)
|
||||||
|
{
|
||||||
|
register u_long val, base, n;
|
||||||
|
register char c;
|
||||||
|
u_long parts[4], *pp = parts;
|
||||||
|
register int i;
|
||||||
|
|
||||||
|
again:
|
||||||
|
/*
|
||||||
|
* Collect number up to ``.''.
|
||||||
|
* Values are specified as for C:
|
||||||
|
* 0x=hex, 0=octal, other=decimal.
|
||||||
|
*/
|
||||||
|
val = 0; base = 10;
|
||||||
|
/*
|
||||||
|
* The 4.4BSD version of this file also accepts 'x__' as a hexa
|
||||||
|
* number. I don't think this is correct. -- Uli
|
||||||
|
*/
|
||||||
|
if (*cp == '0') {
|
||||||
|
if (*++cp == 'x' || *cp == 'X')
|
||||||
|
base = 16, cp++;
|
||||||
|
else
|
||||||
|
base = 8;
|
||||||
|
}
|
||||||
|
while ((c = *cp)) {
|
||||||
|
if (isdigit(c)) {
|
||||||
|
val = (val * base) + (c - '0');
|
||||||
|
cp++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (base == 16 && isxdigit(c)) {
|
||||||
|
val = (val << 4) + (c + 10 - (islower(c) ? 'a' : 'A'));
|
||||||
|
cp++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (*cp == '.') {
|
||||||
|
if (pp >= parts + 4)
|
||||||
|
return (INADDR_NONE);
|
||||||
|
*pp++ = val, cp++;
|
||||||
|
goto again;
|
||||||
|
}
|
||||||
|
if (*cp && !isspace(*cp))
|
||||||
|
return (INADDR_NONE);
|
||||||
|
*pp++ = val;
|
||||||
|
n = pp - parts;
|
||||||
|
if (n > 4)
|
||||||
|
return (INADDR_NONE);
|
||||||
|
for (val = 0, i = 0; i < (int)n; i++) {
|
||||||
|
val <<= 8;
|
||||||
|
val |= parts[i] & 0xff;
|
||||||
|
}
|
||||||
|
return (val);
|
||||||
|
}
|
|
@ -0,0 +1,69 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 1999 Kungliga Tekniska Högskolan
|
||||||
|
* (Royal Institute of Technology, Stockholm, Sweden).
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* 3. All advertising materials mentioning features or use of this software
|
||||||
|
* must display the following acknowledgement:
|
||||||
|
* This product includes software developed by the Kungliga Tekniska
|
||||||
|
* Högskolan and its contributors.
|
||||||
|
*
|
||||||
|
* 4. Neither the name of the Institute nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* $Id: inet_pton.c,v 1.1 2002-08-01 08:33:11 risso Exp $ */
|
||||||
|
|
||||||
|
#ifndef lint
|
||||||
|
static const char rcsid[] =
|
||||||
|
"@(#) $Header: /tcpdump/master/libpcap/Win32/Src/inet_pton.c,v 1.1 2002-08-01 08:33:11 risso Exp $";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
#ifndef EAFNOSUPPORT
|
||||||
|
#define EAFNOSUPPORT 97 /* not present in errno.h provided with VC */
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __MINGW32__
|
||||||
|
int* _errno();
|
||||||
|
#define errno (*_errno())
|
||||||
|
#endif /* __MINGW32__ */
|
||||||
|
|
||||||
|
#include <pcap-stdinc.h>
|
||||||
|
|
||||||
|
int
|
||||||
|
inet_pton(int af, const char *src, void *dst)
|
||||||
|
{
|
||||||
|
if (af != AF_INET) {
|
||||||
|
errno = EAFNOSUPPORT;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return inet_aton (src, dst);
|
||||||
|
}
|
|
@ -40,12 +40,10 @@
|
||||||
|
|
||||||
#if !(defined(lint) || defined(KERNEL) || defined(_KERNEL))
|
#if !(defined(lint) || defined(KERNEL) || defined(_KERNEL))
|
||||||
static const char rcsid[] =
|
static const char rcsid[] =
|
||||||
"@(#) $Header: /tcpdump/master/libpcap/bpf/net/bpf_filter.c,v 1.36 2002-06-11 17:04:48 itojun Exp $ (LBL)";
|
"@(#) $Header: /tcpdump/master/libpcap/bpf/net/bpf_filter.c,v 1.37 2002-08-01 08:33:12 risso Exp $ (LBL)";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <sys/param.h>
|
#include <pcap-stdinc.h>
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/time.h>
|
|
||||||
|
|
||||||
#define SOLARIS (defined(sun) && (defined(__SVR4) || defined(__svr4__)))
|
#define SOLARIS (defined(sun) && (defined(__SVR4) || defined(__svr4__)))
|
||||||
#if defined(__hpux) || SOLARIS
|
#if defined(__hpux) || SOLARIS
|
||||||
|
@ -76,7 +74,6 @@ static const char rcsid[] =
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef LBL_ALIGN
|
#ifndef LBL_ALIGN
|
||||||
#include <netinet/in.h>
|
|
||||||
|
|
||||||
#define EXTRACT_SHORT(p) ((u_short)ntohs(*(u_short *)p))
|
#define EXTRACT_SHORT(p) ((u_short)ntohs(*(u_short *)p))
|
||||||
#define EXTRACT_LONG(p) (ntohl(*(u_int32 *)p))
|
#define EXTRACT_LONG(p) (ntohl(*(u_int32 *)p))
|
||||||
|
|
|
@ -0,0 +1,374 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 1999, 2002
|
||||||
|
* Politecnico di Torino. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that: (1) source code distributions
|
||||||
|
* retain the above copyright notice and this paragraph in its entirety, (2)
|
||||||
|
* distributions including binary code include the above copyright notice and
|
||||||
|
* this paragraph in its entirety in the documentation or other materials
|
||||||
|
* provided with the distribution, and (3) all advertising materials mentioning
|
||||||
|
* features or use of this software display the following acknowledgement:
|
||||||
|
* ``This product includes software developed by the Politecnico
|
||||||
|
* di Torino, and its contributors.'' Neither the name of
|
||||||
|
* the University nor the names of its contributors may be used to endorse
|
||||||
|
* or promote products derived from this software without specific prior
|
||||||
|
* written permission.
|
||||||
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
|
||||||
|
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <pcap.h>
|
||||||
|
#include <packet32.h>
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#ifndef SA_LEN
|
||||||
|
#ifdef HAVE_SOCKADDR_SA_LEN
|
||||||
|
#define SA_LEN(addr) ((addr)->sa_len)
|
||||||
|
#else /* HAVE_SOCKADDR_SA_LEN */
|
||||||
|
#define SA_LEN(addr) (sizeof (struct sockaddr))
|
||||||
|
#endif /* HAVE_SOCKADDR_SA_LEN */
|
||||||
|
#endif /* SA_LEN */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Add an entry to the list of addresses for an interface.
|
||||||
|
* "curdev" is the entry for that interface.
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
add_addr_to_list(pcap_if_t *curdev, struct sockaddr *addr,
|
||||||
|
struct sockaddr *netmask, struct sockaddr *broadaddr,
|
||||||
|
struct sockaddr *dstaddr, char *errbuf)
|
||||||
|
{
|
||||||
|
pcap_addr_t *curaddr, *prevaddr, *nextaddr;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Allocate the new entry and fill it in.
|
||||||
|
*/
|
||||||
|
curaddr = (pcap_addr_t*)malloc(sizeof(pcap_addr_t));
|
||||||
|
if (curaddr == NULL) {
|
||||||
|
(void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
|
||||||
|
"malloc: %s", pcap_strerror(errno));
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
curaddr->next = NULL;
|
||||||
|
if (addr != NULL) {
|
||||||
|
curaddr->addr = (struct sockaddr*)dup_sockaddr(addr, SA_LEN(addr));
|
||||||
|
if (curaddr->addr == NULL) {
|
||||||
|
(void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
|
||||||
|
"malloc: %s", pcap_strerror(errno));
|
||||||
|
free(curaddr);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
curaddr->addr = NULL;
|
||||||
|
|
||||||
|
if (netmask != NULL) {
|
||||||
|
curaddr->netmask = (struct sockaddr*)dup_sockaddr(netmask, SA_LEN(netmask));
|
||||||
|
if (curaddr->netmask == NULL) {
|
||||||
|
(void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
|
||||||
|
"malloc: %s", pcap_strerror(errno));
|
||||||
|
free(curaddr);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
curaddr->netmask = NULL;
|
||||||
|
|
||||||
|
if (broadaddr != NULL) {
|
||||||
|
curaddr->broadaddr = (struct sockaddr*)dup_sockaddr(broadaddr, SA_LEN(broadaddr));
|
||||||
|
if (curaddr->broadaddr == NULL) {
|
||||||
|
(void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
|
||||||
|
"malloc: %s", pcap_strerror(errno));
|
||||||
|
free(curaddr);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
curaddr->broadaddr = NULL;
|
||||||
|
|
||||||
|
if (dstaddr != NULL) {
|
||||||
|
curaddr->dstaddr = (struct sockaddr*)dup_sockaddr(dstaddr, SA_LEN(dstaddr));
|
||||||
|
if (curaddr->dstaddr == NULL) {
|
||||||
|
(void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
|
||||||
|
"malloc: %s", pcap_strerror(errno));
|
||||||
|
free(curaddr);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
curaddr->dstaddr = NULL;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Find the end of the list of addresses.
|
||||||
|
*/
|
||||||
|
for (prevaddr = curdev->addresses; prevaddr != NULL; prevaddr = nextaddr) {
|
||||||
|
nextaddr = prevaddr->next;
|
||||||
|
if (nextaddr == NULL) {
|
||||||
|
/*
|
||||||
|
* This is the end of the list.
|
||||||
|
*/
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (prevaddr == NULL) {
|
||||||
|
/*
|
||||||
|
* The list was empty; this is the first member.
|
||||||
|
*/
|
||||||
|
curdev->addresses = curaddr;
|
||||||
|
} else {
|
||||||
|
/*
|
||||||
|
* "prevaddr" is the last member of the list; append
|
||||||
|
* this member to it.
|
||||||
|
*/
|
||||||
|
prevaddr->next = curaddr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int
|
||||||
|
pcap_add_if_win32(pcap_if_t **devlist, char *name, const char *desc,
|
||||||
|
char *errbuf)
|
||||||
|
{
|
||||||
|
pcap_if_t *curdev;
|
||||||
|
npf_if_addr if_addrs[16];
|
||||||
|
LONG if_addr_size;
|
||||||
|
int res = 0;
|
||||||
|
struct sockaddr_in *addr, *netmask;
|
||||||
|
|
||||||
|
if_addr_size = 16;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Add an entry for this interface, with no addresses.
|
||||||
|
*/
|
||||||
|
if (add_or_find_if(&curdev, devlist, (char *)name, 0, (char *)desc,
|
||||||
|
errbuf) == -1) {
|
||||||
|
/*
|
||||||
|
* Failure.
|
||||||
|
*/
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get the list of addresses for the interface.
|
||||||
|
*
|
||||||
|
* XXX - what about IPv6?
|
||||||
|
*/
|
||||||
|
if (!PacketGetNetInfoEx((void *)name, if_addrs, &if_addr_size)) {
|
||||||
|
/*
|
||||||
|
* Failure.
|
||||||
|
*/
|
||||||
|
|
||||||
|
addr=(struct sockaddr_in*)malloc(sizeof(struct sockaddr_in));
|
||||||
|
netmask=(struct sockaddr_in*)malloc(sizeof(struct sockaddr_in));
|
||||||
|
|
||||||
|
addr->sin_family = AF_INET;
|
||||||
|
addr->sin_addr.s_addr = 0;
|
||||||
|
netmask->sin_family = AF_INET;
|
||||||
|
netmask->sin_addr.s_addr = 0;
|
||||||
|
|
||||||
|
return (add_addr_to_list(curdev,
|
||||||
|
(struct sockaddr*)addr,
|
||||||
|
(struct sockaddr*)netmask,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
errbuf));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Now add the addresses.
|
||||||
|
*/
|
||||||
|
while (if_addr_size-- > 0) {
|
||||||
|
/*
|
||||||
|
* "curdev" is an entry for this interface; add an entry for
|
||||||
|
* this address to its list of addresses.
|
||||||
|
*/
|
||||||
|
if(curdev == NULL)
|
||||||
|
break;
|
||||||
|
res = add_addr_to_list(curdev,
|
||||||
|
(struct sockaddr *)&if_addrs[if_addr_size].IPAddress,
|
||||||
|
(struct sockaddr *)&if_addrs[if_addr_size].SubnetMask,
|
||||||
|
(struct sockaddr *)&if_addrs[if_addr_size].Broadcast,
|
||||||
|
NULL,
|
||||||
|
errbuf);
|
||||||
|
if (res == -1) {
|
||||||
|
/*
|
||||||
|
* Failure.
|
||||||
|
*/
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (res);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get a list of all interfaces that are up and that we can open.
|
||||||
|
* Returns -1 on error, 0 otherwise.
|
||||||
|
* The list, as returned through "alldevsp", may be null if no interfaces
|
||||||
|
* were up and could be opened.
|
||||||
|
*
|
||||||
|
* Win32 implementation, based on WinPcap
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
pcap_findalldevs(pcap_if_t **alldevsp, char *errbuf)
|
||||||
|
{
|
||||||
|
pcap_if_t *devlist = NULL;
|
||||||
|
DWORD dwVersion;
|
||||||
|
DWORD dwWindowsMajorVersion;
|
||||||
|
int ret = 0;
|
||||||
|
const char *desc;
|
||||||
|
|
||||||
|
dwVersion = GetVersion(); /* get the OS version */
|
||||||
|
dwWindowsMajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion)));
|
||||||
|
if (dwVersion >= 0x80000000 && dwWindowsMajorVersion >= 4) {
|
||||||
|
/*
|
||||||
|
* Windows 95, 98, ME.
|
||||||
|
*/
|
||||||
|
char AdaptersName[8192];
|
||||||
|
ULONG NameLength = 8192;
|
||||||
|
char *name;
|
||||||
|
|
||||||
|
if (!PacketGetAdapterNames(AdaptersName, &NameLength)) {
|
||||||
|
snprintf(errbuf, PCAP_ERRBUF_SIZE,
|
||||||
|
"PacketGetAdapterNames: %s",
|
||||||
|
pcap_win32strerror());
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* "PacketGetAdapterNames()" returned a list of
|
||||||
|
* null-terminated ASCII interface name strings,
|
||||||
|
* terminated by a null string, followed by a list
|
||||||
|
* of null-terminated ASCII interface description
|
||||||
|
* strings, terminated by a null string.
|
||||||
|
* This means there are two ASCII nulls at the end
|
||||||
|
* of the first list.
|
||||||
|
*
|
||||||
|
* Find the end of the first list; that's the
|
||||||
|
* beginning of the second list.
|
||||||
|
*/
|
||||||
|
desc = &AdaptersName[0];
|
||||||
|
while (*desc != '\0' || *(desc + 1) != '\0')
|
||||||
|
desc++;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Found it - "desc" points to the first of the two
|
||||||
|
* nulls at the end of the list of names, so the
|
||||||
|
* first byte of the list of descriptions is two bytes
|
||||||
|
* after it.
|
||||||
|
*/
|
||||||
|
desc += 2;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Loop over the elements in the first list.
|
||||||
|
*/
|
||||||
|
name = &AdaptersName[0];
|
||||||
|
while (*name != '\0') {
|
||||||
|
/*
|
||||||
|
* Add an entry for this interface.
|
||||||
|
*/
|
||||||
|
if (pcap_add_if_win32(&devlist, name, desc,
|
||||||
|
errbuf) == -1) {
|
||||||
|
/*
|
||||||
|
* Failure.
|
||||||
|
*/
|
||||||
|
ret = -1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
name += strlen(name) + 1;
|
||||||
|
desc += strlen(desc) + 1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
/*
|
||||||
|
* Windows NT (NT 4.0, W2K, WXP).
|
||||||
|
*/
|
||||||
|
WCHAR AdaptersName[8192];
|
||||||
|
ULONG NameLength = 8192;
|
||||||
|
const WCHAR *t;
|
||||||
|
WCHAR *uc_name;
|
||||||
|
char ascii_name[8192];
|
||||||
|
char ascii_desc[8192];
|
||||||
|
char *p;
|
||||||
|
|
||||||
|
if (!PacketGetAdapterNames((PTSTR)AdaptersName, &NameLength)) {
|
||||||
|
snprintf(errbuf, PCAP_ERRBUF_SIZE,
|
||||||
|
"PacketGetAdapterNames: %s",
|
||||||
|
pcap_win32strerror());
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* "PacketGetAdapterNames()" returned a list of
|
||||||
|
* null-terminated Unicode interface name strings,
|
||||||
|
* terminated by a null string, followed by a list
|
||||||
|
* of null-terminated ASCII interface description
|
||||||
|
* strings, terminated by a null string.
|
||||||
|
* This means there are two Unicode nulls at the end
|
||||||
|
* of the first list.
|
||||||
|
*
|
||||||
|
* Find the end of the first list; that's the
|
||||||
|
* beginning of the second list.
|
||||||
|
*/
|
||||||
|
t = &AdaptersName[0];
|
||||||
|
while (*t != '\0' || *(t + 1) != '\0')
|
||||||
|
t++;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Found it - "t" points to the first of the two
|
||||||
|
* nulls at the end of the list of names, so the
|
||||||
|
* first byte of the list of descriptions is two wide
|
||||||
|
* characters after it.
|
||||||
|
*/
|
||||||
|
t += 2;
|
||||||
|
desc = (const char *)t;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Loop over the elements in the first list.
|
||||||
|
*
|
||||||
|
* We assume all characters in the name string are valid
|
||||||
|
* ASCII characters.
|
||||||
|
*/
|
||||||
|
uc_name = &AdaptersName[0];
|
||||||
|
while (*uc_name != '\0') {
|
||||||
|
p = ascii_name;
|
||||||
|
while ((*p++ = (char)*uc_name++) != '\0')
|
||||||
|
;
|
||||||
|
p = ascii_desc;
|
||||||
|
while ((*p++ = *desc++) != '\0')
|
||||||
|
;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Add an entry for this interface.
|
||||||
|
*/
|
||||||
|
if (pcap_add_if_win32(&devlist, ascii_name,
|
||||||
|
ascii_desc, errbuf) == -1) {
|
||||||
|
/*
|
||||||
|
* Failure.
|
||||||
|
*/
|
||||||
|
ret = -1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ret == -1) {
|
||||||
|
/*
|
||||||
|
* We had an error; free the list we've been constructing.
|
||||||
|
*/
|
||||||
|
if (devlist != NULL) {
|
||||||
|
pcap_freealldevs(devlist);
|
||||||
|
devlist = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
*alldevsp = devlist;
|
||||||
|
return (ret);
|
||||||
|
}
|
14
gencode.c
14
gencode.c
|
@ -21,16 +21,19 @@
|
||||||
*/
|
*/
|
||||||
#ifndef lint
|
#ifndef lint
|
||||||
static const char rcsid[] =
|
static const char rcsid[] =
|
||||||
"@(#) $Header: /tcpdump/master/libpcap/gencode.c,v 1.169 2002-07-11 09:06:32 guy Exp $ (LBL)";
|
"@(#) $Header: /tcpdump/master/libpcap/gencode.c,v 1.170 2002-08-01 08:33:01 risso Exp $ (LBL)";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <pcap-stdinc.h>
|
||||||
#include <sys/socket.h>
|
|
||||||
#include <sys/time.h>
|
#ifdef __MINGW32__
|
||||||
|
#include "IP6_misc.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef __NetBSD__
|
#ifdef __NetBSD__
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#endif
|
#endif
|
||||||
|
@ -39,8 +42,6 @@ struct mbuf; /* Squelch compiler warnings on some platforms for */
|
||||||
struct rtentry; /* declarations in <net/if.h> */
|
struct rtentry; /* declarations in <net/if.h> */
|
||||||
#include <net/if.h>
|
#include <net/if.h>
|
||||||
|
|
||||||
#include <netinet/in.h>
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <memory.h>
|
#include <memory.h>
|
||||||
|
@ -59,7 +60,6 @@ struct rtentry; /* declarations in <net/if.h> */
|
||||||
#include "sll.h"
|
#include "sll.h"
|
||||||
#include "arcnet.h"
|
#include "arcnet.h"
|
||||||
#ifdef INET6
|
#ifdef INET6
|
||||||
#include <netdb.h> /* for "struct addrinfo" */
|
|
||||||
#endif /*INET6*/
|
#endif /*INET6*/
|
||||||
#include <pcap-namedb.h>
|
#include <pcap-namedb.h>
|
||||||
|
|
||||||
|
|
15
grammar.y
15
grammar.y
|
@ -22,16 +22,15 @@
|
||||||
*/
|
*/
|
||||||
#ifndef lint
|
#ifndef lint
|
||||||
static const char rcsid[] =
|
static const char rcsid[] =
|
||||||
"@(#) $Header: /tcpdump/master/libpcap/grammar.y,v 1.72 2002-07-11 09:06:35 guy Exp $ (LBL)";
|
"@(#) $Header: /tcpdump/master/libpcap/grammar.y,v 1.73 2002-08-01 08:33:02 risso Exp $ (LBL)";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <pcap-stdinc.h>
|
||||||
#include <sys/time.h>
|
|
||||||
#include <sys/socket.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#if __STDC__
|
#if __STDC__
|
||||||
|
@ -39,10 +38,6 @@ struct mbuf;
|
||||||
struct rtentry;
|
struct rtentry;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <net/if.h>
|
|
||||||
|
|
||||||
#include <netinet/in.h>
|
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "pcap-int.h"
|
#include "pcap-int.h"
|
||||||
|
@ -110,7 +105,7 @@ pcap_parse()
|
||||||
%type <blk> atmfieldvalue atmvalue atmlistvalue
|
%type <blk> atmfieldvalue atmvalue atmlistvalue
|
||||||
|
|
||||||
%token DST SRC HOST GATEWAY
|
%token DST SRC HOST GATEWAY
|
||||||
%token NET MASK PORT LESS GREATER PROTO PROTOCHAIN BYTE
|
%token NET MASK PORT LESS GREATER PROTO PROTOCHAIN CBYTE
|
||||||
%token ARP RARP IP SCTP TCP UDP ICMP IGMP IGRP PIM VRRP
|
%token ARP RARP IP SCTP TCP UDP ICMP IGMP IGRP PIM VRRP
|
||||||
%token ATALK AARP DECNET LAT SCA MOPRC MOPDL
|
%token ATALK AARP DECNET LAT SCA MOPRC MOPDL
|
||||||
%token TK_BROADCAST TK_MULTICAST
|
%token TK_BROADCAST TK_MULTICAST
|
||||||
|
@ -305,7 +300,7 @@ other: pqual TK_BROADCAST { $$ = gen_broadcast($1); }
|
||||||
| pqual TK_MULTICAST { $$ = gen_multicast($1); }
|
| pqual TK_MULTICAST { $$ = gen_multicast($1); }
|
||||||
| LESS NUM { $$ = gen_less($2); }
|
| LESS NUM { $$ = gen_less($2); }
|
||||||
| GREATER NUM { $$ = gen_greater($2); }
|
| GREATER NUM { $$ = gen_greater($2); }
|
||||||
| BYTE NUM byteop NUM { $$ = gen_byteop($3, $2, $4); }
|
| CBYTE NUM byteop NUM { $$ = gen_byteop($3, $2, $4); }
|
||||||
| INBOUND { $$ = gen_inbound(0); }
|
| INBOUND { $$ = gen_inbound(0); }
|
||||||
| OUTBOUND { $$ = gen_inbound(1); }
|
| OUTBOUND { $$ = gen_inbound(1); }
|
||||||
| VLAN pnum { $$ = gen_vlan($2); }
|
| VLAN pnum { $$ = gen_vlan($2); }
|
||||||
|
|
92
inet.c
92
inet.c
|
@ -34,26 +34,21 @@
|
||||||
|
|
||||||
#ifndef lint
|
#ifndef lint
|
||||||
static const char rcsid[] =
|
static const char rcsid[] =
|
||||||
"@(#) $Header: /tcpdump/master/libpcap/inet.c,v 1.50 2002-07-30 08:12:14 guy Exp $ (LBL)";
|
"@(#) $Header: /tcpdump/master/libpcap/inet.c,v 1.51 2002-08-01 08:33:02 risso Exp $ (LBL)";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <sys/param.h>
|
#include <pcap-stdinc.h>
|
||||||
#include <sys/file.h>
|
|
||||||
#include <sys/ioctl.h>
|
|
||||||
#include <sys/socket.h>
|
|
||||||
#ifdef HAVE_SYS_SOCKIO_H
|
#ifdef HAVE_SYS_SOCKIO_H
|
||||||
#include <sys/sockio.h>
|
#include <sys/sockio.h>
|
||||||
#endif
|
#endif
|
||||||
#include <sys/time.h> /* concession to AIX */
|
|
||||||
|
|
||||||
struct mbuf; /* Squelch compiler warnings on some platforms for */
|
struct mbuf; /* Squelch compiler warnings on some platforms for */
|
||||||
struct rtentry; /* declarations in <net/if.h> */
|
struct rtentry; /* declarations in <net/if.h> */
|
||||||
#include <net/if.h>
|
#include <net/if.h>
|
||||||
#include <netinet/in.h>
|
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
@ -61,7 +56,6 @@ struct rtentry; /* declarations in <net/if.h> */
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
|
||||||
#ifdef HAVE_LIMITS_H
|
#ifdef HAVE_LIMITS_H
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#else
|
#else
|
||||||
|
@ -85,7 +79,7 @@ struct rtentry; /* declarations in <net/if.h> */
|
||||||
(isdigit((unsigned char)((name)[2])) || (name)[2] == '\0'))
|
(isdigit((unsigned char)((name)[2])) || (name)[2] == '\0'))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static struct sockaddr *
|
struct sockaddr *
|
||||||
dup_sockaddr(struct sockaddr *sa, size_t sa_len)
|
dup_sockaddr(struct sockaddr *sa, size_t sa_len)
|
||||||
{
|
{
|
||||||
struct sockaddr *newsa;
|
struct sockaddr *newsa;
|
||||||
|
@ -121,7 +115,7 @@ get_instance(char *name)
|
||||||
return (n);
|
return (n);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
int
|
||||||
add_or_find_if(pcap_if_t **curdev_ret, pcap_if_t **alldevs, char *name,
|
add_or_find_if(pcap_if_t **curdev_ret, pcap_if_t **alldevs, char *name,
|
||||||
u_int flags, const char *description, char *errbuf)
|
u_int flags, const char *description, char *errbuf)
|
||||||
{
|
{
|
||||||
|
@ -458,6 +452,8 @@ pcap_freealldevs(pcap_if_t *alldevs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef WIN32
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Return the name of a network interface attached to the system, or NULL
|
* Return the name of a network interface attached to the system, or NULL
|
||||||
* if none can be found. The interface must be configured up; the
|
* if none can be found. The interface must be configured up; the
|
||||||
|
@ -575,3 +571,79 @@ pcap_lookupnet(device, netp, maskp, errbuf)
|
||||||
*netp &= *maskp;
|
*netp &= *maskp;
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#else /* WIN32 */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Return the name of a network interface attached to the system, or NULL
|
||||||
|
* if none can be found. The interface must be configured up; the
|
||||||
|
* lowest unit number is preferred; loopback is ignored.
|
||||||
|
*/
|
||||||
|
char *
|
||||||
|
pcap_lookupdev(errbuf)
|
||||||
|
register char *errbuf;
|
||||||
|
{
|
||||||
|
DWORD dwVersion;
|
||||||
|
DWORD dwWindowsMajorVersion;
|
||||||
|
dwVersion = GetVersion(); /* get the OS version */
|
||||||
|
dwWindowsMajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion)));
|
||||||
|
|
||||||
|
if (dwVersion >= 0x80000000 && dwWindowsMajorVersion >= 4) {
|
||||||
|
/*
|
||||||
|
* Windows 95, 98, ME.
|
||||||
|
*/
|
||||||
|
ULONG NameLength = 8192;
|
||||||
|
static char AdaptersName[8192];
|
||||||
|
|
||||||
|
PacketGetAdapterNames(AdaptersName,&NameLength);
|
||||||
|
|
||||||
|
return (AdaptersName);
|
||||||
|
} else {
|
||||||
|
/*
|
||||||
|
* Windows NT (NT 4.0, W2K, WXP).
|
||||||
|
*/
|
||||||
|
ULONG NameLength = 8192;
|
||||||
|
static WCHAR AdaptersName[8192];
|
||||||
|
|
||||||
|
PacketGetAdapterNames((PTSTR)AdaptersName,&NameLength);
|
||||||
|
|
||||||
|
return (char *)(AdaptersName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
pcap_lookupnet(device, netp, maskp, errbuf)
|
||||||
|
register char *device;
|
||||||
|
register bpf_u_int32 *netp, *maskp;
|
||||||
|
register char *errbuf;
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* We need only the first address, so we allocate a single
|
||||||
|
* npf_if_addr structure and we set if_addr_size to 1.
|
||||||
|
*/
|
||||||
|
npf_if_addr if_addrs;
|
||||||
|
LONG if_addr_size = 1;
|
||||||
|
struct sockaddr_in *t_addr;
|
||||||
|
|
||||||
|
if (!PacketGetNetInfoEx((void *)device, &if_addrs, &if_addr_size)) {
|
||||||
|
*netp = *maskp = 0;
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
t_addr = (struct sockaddr_in *) &(if_addrs.IPAddress);
|
||||||
|
*netp = t_addr->sin_addr.S_un.S_addr;
|
||||||
|
t_addr = (struct sockaddr_in *) &(if_addrs.SubnetMask);
|
||||||
|
*maskp = t_addr->sin_addr.S_un.S_addr;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* XXX - will we ever get back a 0 netmask?
|
||||||
|
* If so, we should presumably make the "if (*maskp == 0)" code
|
||||||
|
* above common, rather than non-Win32-specific.
|
||||||
|
*/
|
||||||
|
|
||||||
|
*netp &= *maskp;
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* WIN32 */
|
21
nametoaddr.c
21
nametoaddr.c
|
@ -24,19 +24,19 @@
|
||||||
|
|
||||||
#ifndef lint
|
#ifndef lint
|
||||||
static const char rcsid[] =
|
static const char rcsid[] =
|
||||||
"@(#) $Header: /tcpdump/master/libpcap/nametoaddr.c,v 1.64 2002-06-11 17:04:45 itojun Exp $ (LBL)";
|
"@(#) $Header: /tcpdump/master/libpcap/nametoaddr.c,v 1.65 2002-08-01 08:33:03 risso Exp $ (LBL)";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <sys/param.h>
|
#include <pcap-stdinc.h>
|
||||||
#include <sys/types.h> /* concession to AIX */
|
|
||||||
#include <sys/socket.h>
|
#ifdef __MINGW32__
|
||||||
#include <sys/time.h>
|
#include "IP6_misc.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <netinet/in.h>
|
|
||||||
#ifdef HAVE_ETHER_HOSTTON
|
#ifdef HAVE_ETHER_HOSTTON
|
||||||
#ifdef HAVE_NETINET_IF_ETHER_H
|
#ifdef HAVE_NETINET_IF_ETHER_H
|
||||||
struct mbuf; /* Squelch compiler warnings on some platforms for */
|
struct mbuf; /* Squelch compiler warnings on some platforms for */
|
||||||
|
@ -45,8 +45,6 @@ struct rtentry; /* declarations in <net/if.h> */
|
||||||
#include <netinet/if_ether.h>
|
#include <netinet/if_ether.h>
|
||||||
#endif /* HAVE_NETINET_IF_ETHER_H */
|
#endif /* HAVE_NETINET_IF_ETHER_H */
|
||||||
#endif /* HAVE_ETHER_HOSTTON */
|
#endif /* HAVE_ETHER_HOSTTON */
|
||||||
#include <arpa/inet.h>
|
|
||||||
#include <netdb.h>
|
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
@ -123,12 +121,19 @@ pcap_nametoaddrinfo(const char *name)
|
||||||
bpf_u_int32
|
bpf_u_int32
|
||||||
pcap_nametonetaddr(const char *name)
|
pcap_nametonetaddr(const char *name)
|
||||||
{
|
{
|
||||||
|
#ifndef WIN32
|
||||||
struct netent *np;
|
struct netent *np;
|
||||||
|
|
||||||
if ((np = getnetbyname(name)) != NULL)
|
if ((np = getnetbyname(name)) != NULL)
|
||||||
return np->n_net;
|
return np->n_net;
|
||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
|
#else
|
||||||
|
/*
|
||||||
|
* There's no "getnetbyname()" on Windows.
|
||||||
|
*/
|
||||||
|
return 0;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
22
pcap-int.h
22
pcap-int.h
|
@ -30,7 +30,7 @@
|
||||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* @(#) $Header: /tcpdump/master/libpcap/pcap-int.h,v 1.37 2002-07-30 08:12:14 guy Exp $ (LBL)
|
* @(#) $Header: /tcpdump/master/libpcap/pcap-int.h,v 1.38 2002-08-01 08:33:03 risso Exp $ (LBL)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef pcap_int_h
|
#ifndef pcap_int_h
|
||||||
|
@ -42,6 +42,10 @@ extern "C" {
|
||||||
|
|
||||||
#include <pcap.h>
|
#include <pcap.h>
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
#include <packet32.h>
|
||||||
|
#endif /* WIN32 */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Savefile
|
* Savefile
|
||||||
*/
|
*/
|
||||||
|
@ -75,7 +79,14 @@ struct pcap_md {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct pcap {
|
struct pcap {
|
||||||
|
#ifdef WIN32
|
||||||
|
ADAPTER *adapter;
|
||||||
|
LPPACKET Packet;
|
||||||
|
int timeout;
|
||||||
|
int nonblock;
|
||||||
|
#else
|
||||||
int fd;
|
int fd;
|
||||||
|
#endif /* WIN32 */
|
||||||
int snapshot;
|
int snapshot;
|
||||||
int linktype;
|
int linktype;
|
||||||
int tzoff; /* timezone offset */
|
int tzoff; /* timezone offset */
|
||||||
|
@ -178,6 +189,11 @@ int yylex(void);
|
||||||
int pcap_offline_read(pcap_t *, int, pcap_handler, u_char *);
|
int pcap_offline_read(pcap_t *, int, pcap_handler, u_char *);
|
||||||
int pcap_read(pcap_t *, int cnt, pcap_handler, u_char *);
|
int pcap_read(pcap_t *, int cnt, pcap_handler, u_char *);
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
/* sf_next_packet must be exported for pcap_read_ex */
|
||||||
|
int sf_next_packet(pcap_t *, struct pcap_pkthdr *, u_char *, int);
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Ultrix, DEC OSF/1^H^H^H^H^H^H^H^H^HDigital UNIX^H^H^H^H^H^H^H^H^H^H^H^H
|
* Ultrix, DEC OSF/1^H^H^H^H^H^H^H^H^HDigital UNIX^H^H^H^H^H^H^H^H^H^H^H^H
|
||||||
* Tru64 UNIX, and NetBSD pad to make everything line up on a nice boundary.
|
* Tru64 UNIX, and NetBSD pad to make everything line up on a nice boundary.
|
||||||
|
@ -213,6 +229,10 @@ int pcap_add_if(pcap_if_t **, char *, u_int, const char *, char *);
|
||||||
void pcap_close_linux(pcap_t *);
|
void pcap_close_linux(pcap_t *);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
char *pcap_win32strerror(void);
|
||||||
|
#endif
|
||||||
|
|
||||||
/* XXX */
|
/* XXX */
|
||||||
extern int pcap_fddipad;
|
extern int pcap_fddipad;
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,63 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2002
|
||||||
|
* Politecnico di Torino. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that: (1) source code distributions
|
||||||
|
* retain the above copyright notice and this paragraph in its entirety, (2)
|
||||||
|
* distributions including binary code include the above copyright notice and
|
||||||
|
* this paragraph in its entirety in the documentation or other materials
|
||||||
|
* provided with the distribution, and (3) all advertising materials mentioning
|
||||||
|
* features or use of this software display the following acknowledgement:
|
||||||
|
* ``This product includes software developed by the Politecnico
|
||||||
|
* di Torino, and its contributors.'' Neither the name of
|
||||||
|
* the University nor the names of its contributors may be used to endorse
|
||||||
|
* or promote products derived from this software without specific prior
|
||||||
|
* written permission.
|
||||||
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
|
||||||
|
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
*/
|
||||||
|
#ifdef WIN32
|
||||||
|
|
||||||
|
#define SIZEOF_CHAR 1
|
||||||
|
#define SIZEOF_SHORT 2
|
||||||
|
#define SIZEOF_INT 4
|
||||||
|
|
||||||
|
#define _WINSOCKAPI_
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
|
#include <winsock2.h>
|
||||||
|
#include "bittypes.h"
|
||||||
|
#include <time.h>
|
||||||
|
#include <io.h>
|
||||||
|
|
||||||
|
#ifndef __MINGW32__
|
||||||
|
#include "IP6_misc.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define caddr_t char*
|
||||||
|
|
||||||
|
#define snprintf _snprintf
|
||||||
|
#define vsnprintf _vsnprintf
|
||||||
|
#define inline __inline
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <netdb.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <sys/param.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
#include <sys/timeb.h>
|
||||||
|
#include <sys/file.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#include <net/if.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#ifdef HAVE_SYS_SOCKIO_H
|
||||||
|
#include <sys/sockio.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,317 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 1999, 2000
|
||||||
|
* Politecnico di Torino. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that: (1) source code distributions
|
||||||
|
* retain the above copyright notice and this paragraph in its entirety, (2)
|
||||||
|
* distributions including binary code include the above copyright notice and
|
||||||
|
* this paragraph in its entirety in the documentation or other materials
|
||||||
|
* provided with the distribution, and (3) all advertising materials mentioning
|
||||||
|
* features or use of this software display the following acknowledgement:
|
||||||
|
* ``This product includes software developed by the Politecnico
|
||||||
|
* di Torino, and its contributors.'' Neither the name of
|
||||||
|
* the University nor the names of its contributors may be used to endorse
|
||||||
|
* or promote products derived from this software without specific prior
|
||||||
|
* written permission.
|
||||||
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
|
||||||
|
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <pcap-int.h>
|
||||||
|
#include <packet32.h>
|
||||||
|
#include <Ntddndis.h>
|
||||||
|
#ifdef __MINGW32__
|
||||||
|
int* _errno();
|
||||||
|
#define errno (*_errno())
|
||||||
|
#endif /* __MINGW32__ */
|
||||||
|
|
||||||
|
#define PcapBufSize 256000 /*dimension of the buffer in the pcap_t structure*/
|
||||||
|
#define SIZE_BUF 1000000
|
||||||
|
|
||||||
|
/*start winsock*/
|
||||||
|
int
|
||||||
|
wsockinit()
|
||||||
|
{
|
||||||
|
WORD wVersionRequested;
|
||||||
|
WSADATA wsaData;
|
||||||
|
int err;
|
||||||
|
wVersionRequested = MAKEWORD( 1, 1);
|
||||||
|
err = WSAStartup( wVersionRequested, &wsaData );
|
||||||
|
if ( err != 0 )
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
pcap_stats(pcap_t *p, struct pcap_stat *ps)
|
||||||
|
{
|
||||||
|
|
||||||
|
if(PacketGetStats(p->adapter, (struct bpf_stat*)ps) != TRUE){
|
||||||
|
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "PacketGetStats error: %s", pcap_win32strerror());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
pcap_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
|
||||||
|
{
|
||||||
|
int cc;
|
||||||
|
int n = 0;
|
||||||
|
register u_char *bp, *ep;
|
||||||
|
|
||||||
|
cc = p->cc;
|
||||||
|
if (p->cc == 0) {
|
||||||
|
|
||||||
|
/* capture the packets */
|
||||||
|
if(PacketReceivePacket(p->adapter,p->Packet,TRUE)==FALSE){
|
||||||
|
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "read error: PacketReceivePacket failed");
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
cc = p->Packet->ulBytesReceived;
|
||||||
|
|
||||||
|
bp = p->Packet->Buffer;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
bp = p->bp;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Loop through each packet.
|
||||||
|
*/
|
||||||
|
#define bhp ((struct bpf_hdr *)bp)
|
||||||
|
ep = bp + cc;
|
||||||
|
while (bp < ep) {
|
||||||
|
register int caplen, hdrlen;
|
||||||
|
caplen = bhp->bh_caplen;
|
||||||
|
hdrlen = bhp->bh_hdrlen;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* XXX A bpf_hdr matches a pcap_pkthdr.
|
||||||
|
*/
|
||||||
|
(*callback)(user, (struct pcap_pkthdr*)bp, bp + hdrlen);
|
||||||
|
bp += BPF_WORDALIGN(caplen + hdrlen);
|
||||||
|
if (++n >= cnt && cnt > 0) {
|
||||||
|
p->bp = bp;
|
||||||
|
p->cc = ep - bp;
|
||||||
|
return (n);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#undef bhp
|
||||||
|
p->cc = 0;
|
||||||
|
return (n);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
pcap_t *
|
||||||
|
pcap_open_live(char *device, int snaplen, int promisc, int to_ms, char *ebuf)
|
||||||
|
{
|
||||||
|
register pcap_t *p;
|
||||||
|
NetType type;
|
||||||
|
|
||||||
|
/* Init WinSock */
|
||||||
|
wsockinit();
|
||||||
|
|
||||||
|
p = (pcap_t *)malloc(sizeof(*p));
|
||||||
|
if (p == NULL) {
|
||||||
|
snprintf(ebuf, PCAP_ERRBUF_SIZE, "malloc: %s", pcap_strerror(errno));
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
memset(p, 0, sizeof(*p));
|
||||||
|
p->adapter=NULL;
|
||||||
|
|
||||||
|
p->adapter=PacketOpenAdapter(device);
|
||||||
|
if (p->adapter==NULL) {
|
||||||
|
snprintf(ebuf, PCAP_ERRBUF_SIZE, "Error opening adapter: %s", pcap_win32strerror());
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*get network type*/
|
||||||
|
if(PacketGetNetType (p->adapter,&type)==FALSE)
|
||||||
|
{
|
||||||
|
snprintf(ebuf, PCAP_ERRBUF_SIZE, "Cannot determine the network type: %s", pcap_win32strerror());
|
||||||
|
goto bad;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*Set the linktype*/
|
||||||
|
switch (type.LinkType) {
|
||||||
|
|
||||||
|
case NdisMediumWan:
|
||||||
|
p->linktype = DLT_EN10MB;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case NdisMedium802_3:
|
||||||
|
p->linktype = DLT_EN10MB;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case NdisMediumFddi:
|
||||||
|
p->linktype = DLT_FDDI;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case NdisMedium802_5:
|
||||||
|
p->linktype = DLT_IEEE802;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case NdisMediumArcnet878_2:
|
||||||
|
p->linktype = DLT_ARCNET;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case NdisMediumAtm:
|
||||||
|
p->linktype = DLT_ATM_RFC1483;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
p->linktype = DLT_EN10MB; /*an unknown adapter is assumed to be ethernet*/
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set promisquous mode */
|
||||||
|
if (promisc) PacketSetHwFilter(p->adapter,NDIS_PACKET_TYPE_PROMISCUOUS);
|
||||||
|
else PacketSetHwFilter(p->adapter,NDIS_PACKET_TYPE_ALL_LOCAL);
|
||||||
|
|
||||||
|
/* Set the buffer size */
|
||||||
|
p->bufsize = PcapBufSize;
|
||||||
|
|
||||||
|
p->buffer = (u_char *)malloc(PcapBufSize);
|
||||||
|
if (p->buffer == NULL) {
|
||||||
|
snprintf(ebuf, PCAP_ERRBUF_SIZE, "malloc: %s", pcap_strerror(errno));
|
||||||
|
goto bad;
|
||||||
|
}
|
||||||
|
|
||||||
|
p->snapshot = snaplen;
|
||||||
|
|
||||||
|
/* allocate Packet structure used during the capture */
|
||||||
|
if((p->Packet = PacketAllocatePacket())==NULL){
|
||||||
|
snprintf(ebuf, PCAP_ERRBUF_SIZE, "failed to allocate the PACKET structure");
|
||||||
|
goto bad;
|
||||||
|
}
|
||||||
|
|
||||||
|
PacketInitPacket(p->Packet,(BYTE*)p->buffer,p->bufsize);
|
||||||
|
|
||||||
|
/* allocate the standard buffer in the driver */
|
||||||
|
if(PacketSetBuff( p->adapter, SIZE_BUF)==FALSE)
|
||||||
|
{
|
||||||
|
snprintf(ebuf, PCAP_ERRBUF_SIZE,"driver error: not enough memory to allocate the kernel buffer\n");
|
||||||
|
goto bad;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* tell the driver to copy the buffer only if it contains at least 16K */
|
||||||
|
if(PacketSetMinToCopy(p->adapter,16000)==FALSE)
|
||||||
|
{
|
||||||
|
snprintf(ebuf, PCAP_ERRBUF_SIZE,"Error calling PacketSetMinToCopy: %s\n", pcap_win32strerror());
|
||||||
|
goto bad;
|
||||||
|
}
|
||||||
|
|
||||||
|
PacketSetReadTimeout(p->adapter, to_ms);
|
||||||
|
|
||||||
|
return (p);
|
||||||
|
bad:
|
||||||
|
if (p->adapter)
|
||||||
|
PacketCloseAdapter(p->adapter);
|
||||||
|
if (p->buffer != NULL)
|
||||||
|
free(p->buffer);
|
||||||
|
free(p);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
pcap_setfilter(pcap_t *p, struct bpf_program *fp)
|
||||||
|
{
|
||||||
|
if(p->adapter==NULL){
|
||||||
|
/* Offline capture: make our own copy of the filter */
|
||||||
|
if (install_bpf_program(p, fp) < 0)
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
else if(PacketSetBpf(p->adapter,fp)==FALSE){
|
||||||
|
/* kernel filter not installed. */
|
||||||
|
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "Driver error: cannot set bpf filter: %s", pcap_win32strerror());
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Set the driver working mode */
|
||||||
|
int
|
||||||
|
pcap_setmode(pcap_t *p, int mode){
|
||||||
|
|
||||||
|
if (p->adapter==NULL)
|
||||||
|
{
|
||||||
|
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "impossible to set mode while reading from a file");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(PacketSetMode(p->adapter,mode)==FALSE)
|
||||||
|
{
|
||||||
|
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "driver error: working mode not recognized");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Send a packet to the network */
|
||||||
|
int
|
||||||
|
pcap_sendpacket(pcap_t *p, u_char *buf, int size){
|
||||||
|
LPPACKET PacketToSend;
|
||||||
|
|
||||||
|
if (p->adapter==NULL)
|
||||||
|
{
|
||||||
|
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "Writing a packet is allowed only on a physical adapter");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
PacketToSend=PacketAllocatePacket();
|
||||||
|
PacketInitPacket(PacketToSend,buf,size);
|
||||||
|
if(PacketSendPacket(p->adapter,PacketToSend,TRUE) == FALSE){
|
||||||
|
PacketFreePacket(PacketToSend);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
PacketFreePacket(PacketToSend);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set the dimension of the kernel-level capture buffer */
|
||||||
|
int
|
||||||
|
pcap_setbuff(pcap_t *p, int dim)
|
||||||
|
{
|
||||||
|
if (p->adapter==NULL)
|
||||||
|
{
|
||||||
|
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "The kernel buffer size cannot be set while reading from a file");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(PacketSetBuff(p->adapter,dim)==FALSE)
|
||||||
|
{
|
||||||
|
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "driver error: not enough memory to allocate the kernel buffer");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*set the minimum amount of data that will release a read call*/
|
||||||
|
int
|
||||||
|
pcap_setmintocopy(pcap_t *p, int size)
|
||||||
|
{
|
||||||
|
if (p->adapter==NULL)
|
||||||
|
{
|
||||||
|
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "Impossible to set the mintocopy parameter on an offline capture");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(PacketSetMinToCopy(p->adapter, size)==FALSE)
|
||||||
|
{
|
||||||
|
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "driver error: unable to set the requested mintocopy size");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
85
pcap.c
85
pcap.c
|
@ -33,19 +33,18 @@
|
||||||
|
|
||||||
#ifndef lint
|
#ifndef lint
|
||||||
static const char rcsid[] =
|
static const char rcsid[] =
|
||||||
"@(#) $Header: /tcpdump/master/libpcap/pcap.c,v 1.39 2002-06-11 17:04:47 itojun Exp $ (LBL)";
|
"@(#) $Header: /tcpdump/master/libpcap/pcap.c,v 1.40 2002-08-01 08:33:04 risso Exp $ (LBL)";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <pcap-stdinc.h>
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
|
@ -155,7 +154,14 @@ pcap_file(pcap_t *p)
|
||||||
int
|
int
|
||||||
pcap_fileno(pcap_t *p)
|
pcap_fileno(pcap_t *p)
|
||||||
{
|
{
|
||||||
|
#ifndef WIN32
|
||||||
return (p->fd);
|
return (p->fd);
|
||||||
|
#else
|
||||||
|
if (p->adapter != NULL)
|
||||||
|
return ((int)(DWORD)p->adapter->hFile);
|
||||||
|
else
|
||||||
|
return (-1);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -178,7 +184,9 @@ pcap_geterr(pcap_t *p)
|
||||||
int
|
int
|
||||||
pcap_getnonblock(pcap_t *p, char *errbuf)
|
pcap_getnonblock(pcap_t *p, char *errbuf)
|
||||||
{
|
{
|
||||||
|
#ifndef WIN32
|
||||||
int fdflags;
|
int fdflags;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (p->sf.rfile != NULL) {
|
if (p->sf.rfile != NULL) {
|
||||||
/*
|
/*
|
||||||
|
@ -187,6 +195,7 @@ pcap_getnonblock(pcap_t *p, char *errbuf)
|
||||||
*/
|
*/
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
#ifndef WIN32
|
||||||
fdflags = fcntl(p->fd, F_GETFL, 0);
|
fdflags = fcntl(p->fd, F_GETFL, 0);
|
||||||
if (fdflags == -1) {
|
if (fdflags == -1) {
|
||||||
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "F_GETFL: %s",
|
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "F_GETFL: %s",
|
||||||
|
@ -197,12 +206,19 @@ pcap_getnonblock(pcap_t *p, char *errbuf)
|
||||||
return (1);
|
return (1);
|
||||||
else
|
else
|
||||||
return (0);
|
return (0);
|
||||||
|
#else
|
||||||
|
return (p->nonblock);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
pcap_setnonblock(pcap_t *p, int nonblock, char *errbuf)
|
pcap_setnonblock(pcap_t *p, int nonblock, char *errbuf)
|
||||||
{
|
{
|
||||||
|
#ifndef WIN32
|
||||||
int fdflags;
|
int fdflags;
|
||||||
|
#else
|
||||||
|
int newtimeout;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (p->sf.rfile != NULL) {
|
if (p->sf.rfile != NULL) {
|
||||||
/*
|
/*
|
||||||
|
@ -211,6 +227,7 @@ pcap_setnonblock(pcap_t *p, int nonblock, char *errbuf)
|
||||||
*/
|
*/
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
#ifndef WIN32
|
||||||
fdflags = fcntl(p->fd, F_GETFL, 0);
|
fdflags = fcntl(p->fd, F_GETFL, 0);
|
||||||
if (fdflags == -1) {
|
if (fdflags == -1) {
|
||||||
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "F_GETFL: %s",
|
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "F_GETFL: %s",
|
||||||
|
@ -226,9 +243,60 @@ pcap_setnonblock(pcap_t *p, int nonblock, char *errbuf)
|
||||||
pcap_strerror(errno));
|
pcap_strerror(errno));
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
if (nonblock) {
|
||||||
|
/*
|
||||||
|
* Set the read timeout to -1 for non-blocking mode.
|
||||||
|
*/
|
||||||
|
newtimeout = -1;
|
||||||
|
} else {
|
||||||
|
/*
|
||||||
|
* Restore the timeout set when the device was opened.
|
||||||
|
* (Note that this may be -1, in which case we're not
|
||||||
|
* really leaving non-blocking mode.)
|
||||||
|
*/
|
||||||
|
newtimeout = p->timeout;
|
||||||
|
}
|
||||||
|
if (!PacketSetReadTimeout(p->adapter, newtimeout)) {
|
||||||
|
snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||||
|
"PacketSetReadTimeout: %s", pcap_win32strerror());
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
p->nonblock = (newtimeout == -1);
|
||||||
|
#endif
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
/*
|
||||||
|
* Generate a string for the last Win32-specific error (i.e. an error generated when
|
||||||
|
* calling a Win32 API).
|
||||||
|
* For errors occurred during standard C calls, we still use pcap_strerror()
|
||||||
|
*/
|
||||||
|
char *
|
||||||
|
pcap_win32strerror(void)
|
||||||
|
{
|
||||||
|
DWORD error;
|
||||||
|
static char errbuf[PCAP_ERRBUF_SIZE+1];
|
||||||
|
int errlen;
|
||||||
|
|
||||||
|
error = GetLastError();
|
||||||
|
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, error, 0, errbuf,
|
||||||
|
PCAP_ERRBUF_SIZE, NULL);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* "FormatMessage()" "helpfully" sticks CR/LF at the end of the
|
||||||
|
* message. Get rid of it.
|
||||||
|
*/
|
||||||
|
errlen = strlen(errbuf);
|
||||||
|
if (errlen >= 2) {
|
||||||
|
errbuf[errlen - 1] = '\0';
|
||||||
|
errbuf[errlen - 2] = '\0';
|
||||||
|
}
|
||||||
|
return (errbuf);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Not all systems have strerror().
|
* Not all systems have strerror().
|
||||||
*/
|
*/
|
||||||
|
@ -258,7 +326,11 @@ pcap_open_dead(int linktype, int snaplen)
|
||||||
if (p == NULL)
|
if (p == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
memset (p, 0, sizeof(*p));
|
memset (p, 0, sizeof(*p));
|
||||||
|
#ifndef WIN32
|
||||||
p->fd = -1;
|
p->fd = -1;
|
||||||
|
#else
|
||||||
|
p->adapter = NULL;
|
||||||
|
#endif /* WIN32 */
|
||||||
p->snapshot = snaplen;
|
p->snapshot = snaplen;
|
||||||
p->linktype = linktype;
|
p->linktype = linktype;
|
||||||
return p;
|
return p;
|
||||||
|
@ -268,12 +340,19 @@ void
|
||||||
pcap_close(pcap_t *p)
|
pcap_close(pcap_t *p)
|
||||||
{
|
{
|
||||||
/*XXX*/
|
/*XXX*/
|
||||||
|
#ifndef WIN32
|
||||||
if (p->fd >= 0) {
|
if (p->fd >= 0) {
|
||||||
#ifdef linux
|
#ifdef linux
|
||||||
pcap_close_linux(p);
|
pcap_close_linux(p);
|
||||||
#endif
|
#endif
|
||||||
close(p->fd);
|
close(p->fd);
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
if (p->adapter != NULL) {
|
||||||
|
PacketCloseAdapter(p->adapter);
|
||||||
|
p->adapter = NULL;
|
||||||
|
}
|
||||||
|
#endif /* WIN32 */
|
||||||
if (p->sf.rfile != NULL) {
|
if (p->sf.rfile != NULL) {
|
||||||
if (p->sf.rfile != stdin)
|
if (p->sf.rfile != stdin)
|
||||||
(void)fclose(p->sf.rfile);
|
(void)fclose(p->sf.rfile);
|
||||||
|
|
28
pcap.h
28
pcap.h
|
@ -31,14 +31,13 @@
|
||||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* @(#) $Header: /tcpdump/master/libpcap/pcap.h,v 1.35 2002-07-20 23:50:21 guy Exp $ (LBL)
|
* @(#) $Header: /tcpdump/master/libpcap/pcap.h,v 1.36 2002-08-01 08:33:04 risso Exp $ (LBL)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef lib_pcap_h
|
#ifndef lib_pcap_h
|
||||||
#define lib_pcap_h
|
#define lib_pcap_h
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <pcap-stdinc.h>
|
||||||
#include <sys/time.h>
|
|
||||||
|
|
||||||
#include <net/bpf.h>
|
#include <net/bpf.h>
|
||||||
|
|
||||||
|
@ -129,6 +128,9 @@ struct pcap_stat {
|
||||||
u_int ps_recv; /* number of packets received */
|
u_int ps_recv; /* number of packets received */
|
||||||
u_int ps_drop; /* number of packets dropped */
|
u_int ps_drop; /* number of packets dropped */
|
||||||
u_int ps_ifdrop; /* drops by interface XXX not yet supported */
|
u_int ps_ifdrop; /* drops by interface XXX not yet supported */
|
||||||
|
#ifdef WIN32
|
||||||
|
u_int bs_capt; /* number of packets that reach the application */
|
||||||
|
#endif /* WIN32 */
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -203,6 +205,26 @@ int bpf_validate(struct bpf_insn *f, int len);
|
||||||
char *bpf_image(struct bpf_insn *, int);
|
char *bpf_image(struct bpf_insn *, int);
|
||||||
void bpf_dump(struct bpf_program *, int);
|
void bpf_dump(struct bpf_program *, int);
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
/*
|
||||||
|
* Win32 definitions
|
||||||
|
*/
|
||||||
|
|
||||||
|
int pcap_setbuff(pcap_t *p, int dim);
|
||||||
|
int pcap_setmode(pcap_t *p, int mode);
|
||||||
|
int pcap_sendpacket(pcap_t *p, u_char *buf, int size);
|
||||||
|
int pcap_setmintocopy(pcap_t *p, int size);
|
||||||
|
|
||||||
|
#ifdef WPCAP
|
||||||
|
/* Include file with the wpcap-specific extensions */
|
||||||
|
#include <Win32-Extensions.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define MODE_CAPT 0
|
||||||
|
#define MODE_STAT 1
|
||||||
|
|
||||||
|
#endif /* WIN32 */
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
31
savefile.c
31
savefile.c
|
@ -30,7 +30,7 @@
|
||||||
|
|
||||||
#ifndef lint
|
#ifndef lint
|
||||||
static const char rcsid[] =
|
static const char rcsid[] =
|
||||||
"@(#) $Header: /tcpdump/master/libpcap/savefile.c,v 1.64 2002-07-11 09:06:46 guy Exp $ (LBL)";
|
"@(#) $Header: /tcpdump/master/libpcap/savefile.c,v 1.65 2002-08-01 08:33:04 risso Exp $ (LBL)";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
|
@ -376,12 +376,20 @@ pcap_open_offline(const char *fname, char *errbuf)
|
||||||
/*
|
/*
|
||||||
* Set this field so we don't close stdin in pcap_close!
|
* Set this field so we don't close stdin in pcap_close!
|
||||||
*/
|
*/
|
||||||
|
#ifndef WIN32
|
||||||
p->fd = -1;
|
p->fd = -1;
|
||||||
|
#else
|
||||||
|
p->adapter = NULL;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (fname[0] == '-' && fname[1] == '\0')
|
if (fname[0] == '-' && fname[1] == '\0')
|
||||||
fp = stdin;
|
fp = stdin;
|
||||||
else {
|
else {
|
||||||
|
#ifndef WIN32
|
||||||
fp = fopen(fname, "r");
|
fp = fopen(fname, "r");
|
||||||
|
#else
|
||||||
|
fp = fopen(fname, "rb");
|
||||||
|
#endif
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
snprintf(errbuf, PCAP_ERRBUF_SIZE, "%s: %s", fname,
|
snprintf(errbuf, PCAP_ERRBUF_SIZE, "%s: %s", fname,
|
||||||
pcap_strerror(errno));
|
pcap_strerror(errno));
|
||||||
|
@ -422,7 +430,12 @@ pcap_open_offline(const char *fname, char *errbuf)
|
||||||
p->snapshot = hdr.snaplen;
|
p->snapshot = hdr.snaplen;
|
||||||
p->linktype = linktype_to_dlt(hdr.linktype);
|
p->linktype = linktype_to_dlt(hdr.linktype);
|
||||||
p->sf.rfile = fp;
|
p->sf.rfile = fp;
|
||||||
|
#ifndef WIN32
|
||||||
p->bufsize = hdr.snaplen;
|
p->bufsize = hdr.snaplen;
|
||||||
|
#else
|
||||||
|
/* Allocate the space for pcap_pkthdr as well. It will be used by pcap_read_ex */
|
||||||
|
p->bufsize = hdr.snaplen+sizeof(struct pcap_pkthdr);
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Align link header as required for proper data alignment */
|
/* Align link header as required for proper data alignment */
|
||||||
/* XXX should handle all types */
|
/* XXX should handle all types */
|
||||||
|
@ -468,7 +481,11 @@ pcap_open_offline(const char *fname, char *errbuf)
|
||||||
* and the contents in buf. Return 0 on success, SFERR_EOF if there were
|
* and the contents in buf. Return 0 on success, SFERR_EOF if there were
|
||||||
* no more packets, and SFERR_TRUNC if a partial packet was encountered.
|
* no more packets, and SFERR_TRUNC if a partial packet was encountered.
|
||||||
*/
|
*/
|
||||||
|
#ifdef WIN32
|
||||||
|
int
|
||||||
|
#else
|
||||||
static int
|
static int
|
||||||
|
#endif
|
||||||
sf_next_packet(pcap_t *p, struct pcap_pkthdr *hdr, u_char *buf, int buflen)
|
sf_next_packet(pcap_t *p, struct pcap_pkthdr *hdr, u_char *buf, int buflen)
|
||||||
{
|
{
|
||||||
struct pcap_sf_patched_pkthdr sf_hdr;
|
struct pcap_sf_patched_pkthdr sf_hdr;
|
||||||
|
@ -634,10 +651,18 @@ pcap_dump_open(pcap_t *p, const char *fname)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fname[0] == '-' && fname[1] == '\0')
|
if (fname[0] == '-' && fname[1] == '\0') {
|
||||||
f = stdout;
|
f = stdout;
|
||||||
else {
|
#ifdef WIN32
|
||||||
|
_setmode(_fileno(f), _O_BINARY);
|
||||||
|
#endif
|
||||||
|
} else {
|
||||||
|
#ifndef WIN32
|
||||||
f = fopen(fname, "w");
|
f = fopen(fname, "w");
|
||||||
|
#else
|
||||||
|
f = fopen(fname, "wb");
|
||||||
|
setbuf(f, NULL); /* XXX - why? */
|
||||||
|
#endif
|
||||||
if (f == NULL) {
|
if (f == NULL) {
|
||||||
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "%s: %s",
|
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "%s: %s",
|
||||||
fname, pcap_strerror(errno));
|
fname, pcap_strerror(errno));
|
||||||
|
|
12
scanner.l
12
scanner.l
|
@ -22,7 +22,7 @@
|
||||||
|
|
||||||
#ifndef lint
|
#ifndef lint
|
||||||
static const char rcsid[] =
|
static const char rcsid[] =
|
||||||
"@(#) $Header: /tcpdump/master/libpcap/scanner.l,v 1.87 2002-07-27 18:41:23 guy Exp $ (LBL)";
|
"@(#) $Header: /tcpdump/master/libpcap/scanner.l,v 1.88 2002-08-01 08:33:05 risso Exp $ (LBL)";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
|
@ -36,8 +36,12 @@ static const char rcsid[] =
|
||||||
|
|
||||||
#include "gencode.h"
|
#include "gencode.h"
|
||||||
#ifdef INET6
|
#ifdef INET6
|
||||||
#include <sys/socket.h> /* for "struct sockaddr" in "struct addrinfo" */
|
#include <pcap-stdinc.h>
|
||||||
#include <netdb.h> /* for "struct addrinfo" */
|
|
||||||
|
#ifdef __MINGW32__
|
||||||
|
#include "IP6_misc.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Workaround for AIX 4.3 */
|
/* Workaround for AIX 4.3 */
|
||||||
#if !defined(AI_NUMERICHOST)
|
#if !defined(AI_NUMERICHOST)
|
||||||
#define AI_NUMERICHOST 0x04
|
#define AI_NUMERICHOST 0x04
|
||||||
|
@ -230,7 +234,7 @@ gateway return GATEWAY;
|
||||||
|
|
||||||
less return LESS;
|
less return LESS;
|
||||||
greater return GREATER;
|
greater return GREATER;
|
||||||
byte return BYTE;
|
byte return CBYTE;
|
||||||
broadcast return TK_BROADCAST;
|
broadcast return TK_BROADCAST;
|
||||||
multicast return TK_MULTICAST;
|
multicast return TK_MULTICAST;
|
||||||
|
|
||||||
|
|
Reference in New Issue