123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409 |
- #ifndef netdissect_stdinc_h
- #define netdissect_stdinc_h
- #include <errno.h>
- #ifdef _WIN32
- #include <stdint.h>
- #include <stdio.h>
- #include <winsock2.h>
- #include <ws2tcpip.h>
- #include <ctype.h>
- #include <time.h>
- #include <io.h>
- #include <fcntl.h>
- #include <sys/types.h>
- #ifndef uint8_t
- #define uint8_t unsigned char
- #endif
- #ifndef int8_t
- #define int8_t signed char
- #endif
- #ifndef uint16_t
- #define uint16_t unsigned short
- #endif
- #ifndef int16_t
- #define int16_t signed short
- #endif
- #ifndef uint32_t
- #define uint32_t unsigned int
- #endif
- #ifndef int32_t
- #define int32_t signed int
- #endif
- #ifdef _MSC_EXTENSIONS
- #ifndef uint64_t
- #define uint64_t unsigned _int64
- #endif
- #ifndef int64_t
- #define int64_t _int64
- #endif
- #ifndef PRId64
- #define PRId64 "I64d"
- #endif
- #ifndef PRIo64
- #define PRIo64 "I64o"
- #endif
- #ifndef PRIu64
- #define PRIu64 "I64u"
- #endif
- #ifndef PRIx64
- #define PRIx64 "I64x"
- #endif
- #else
- #ifndef uint64_t
- #define uint64_t unsigned long long
- #endif
- #ifndef int64_t
- #define int64_t long long
- #endif
- #ifndef PRId64
- #define PRId64 "lld"
- #endif
- #ifndef PRIo64
- #define PRIo64 "llo"
- #endif
- #ifndef PRIu64
- #define PRIu64 "llu"
- #endif
- #ifndef PRIx64
- #define PRIx64 "llx"
- #endif
- #endif
- #define HAVE_U_INT8_T
- #define HAVE_U_INT16_T
- #define HAVE_U_INT32_T
- #define HAVE_U_INT64_T
- #ifdef _MSC_VER
- #define stat _stat
- #define open _open
- #define fstat _fstat
- #define read _read
- #define close _close
- #define O_RDONLY _O_RDONLY
- #endif
- #ifdef _MSC_VER
- #define inline __inline
- #endif
- #ifdef AF_INET6
- #define HAVE_OS_IPV6_SUPPORT
- #endif
- #ifndef INET6_ADDRSTRLEN
- #define INET6_ADDRSTRLEN 46
- #endif
- #ifndef EAFNOSUPPORT
- #define EAFNOSUPPORT WSAEAFNOSUPPORT
- #endif
- #ifndef caddr_t
- typedef char* caddr_t;
- #endif
- #define MAXHOSTNAMELEN 64
- #define snprintf _snprintf
- #define vsnprintf _vsnprintf
- #define RETSIGTYPE void
- #else
- #include <ctype.h>
- #include <unistd.h>
- #include <netdb.h>
- #if HAVE_INTTYPES_H
- #include <inttypes.h>
- #elif HAVE_STDINT_H
- #include <stdint.h>
- #endif
- #include <sys/param.h>
- #include <sys/types.h> /* concession to AIX */
- #include <sys/time.h>
- #include <sys/socket.h>
- #include <netinet/in.h>
- #ifdef TIME_WITH_SYS_TIME
- #include <time.h>
- #endif
- #include <arpa/inet.h>
- #endif
- #ifndef HAVE___ATTRIBUTE__
- #define __attribute__(x)
- #endif
- #if !(defined(_MSC_VER) && defined(UNALIGNED))
- #undef UNALIGNED
- #define UNALIGNED __attribute__((packed))
- #endif
- #if defined(_WIN32) || defined(MSDOS)
- #define FOPEN_READ_TXT "rt"
- #define FOPEN_READ_BIN "rb"
- #define FOPEN_WRITE_TXT "wt"
- #define FOPEN_WRITE_BIN "wb"
- #else
- #define FOPEN_READ_TXT "r"
- #define FOPEN_READ_BIN FOPEN_READ_TXT
- #define FOPEN_WRITE_TXT "w"
- #define FOPEN_WRITE_BIN FOPEN_WRITE_TXT
- #endif
- #if defined(__GNUC__) && defined(__i386__) && !defined(__APPLE__) && !defined(__ntohl)
- #undef ntohl
- #undef ntohs
- #undef htonl
- #undef htons
- static __inline__ unsigned long __ntohl (unsigned long x);
- static __inline__ unsigned short __ntohs (unsigned short x);
- #define ntohl(x) __ntohl(x)
- #define ntohs(x) __ntohs(x)
- #define htonl(x) __ntohl(x)
- #define htons(x) __ntohs(x)
- static __inline__ unsigned long __ntohl (unsigned long x)
- {
- __asm__ ("xchgb %b0, %h0\n\t"
- "rorl $16, %0\n\t"
- "xchgb %b0, %h0"
- : "=q" (x) : "0" (x));
- return (x);
- }
- static __inline__ unsigned short __ntohs (unsigned short x)
- {
- __asm__ ("xchgb %b0, %h0"
- : "=q" (x) : "0" (x));
- return (x);
- }
- #endif
- #ifndef HAVE_OS_IPV6_SUPPORT
- #ifndef AF_INET6
- #define AF_INET6 24
- struct in6_addr {
- union {
- __uint8_t __u6_addr8[16];
- __uint16_t __u6_addr16[8];
- __uint32_t __u6_addr32[4];
- } __u6_addr;
- };
- #endif
- #endif
- #ifndef NI_MAXHOST
- #define NI_MAXHOST 1025
- #endif
- #ifndef INET_ADDRSTRLEN
- #define INET_ADDRSTRLEN 16
- #endif
- #ifndef TRUE
- #define TRUE 1
- #endif
- #ifndef FALSE
- #define FALSE 0
- #endif
- #define XSTRINGIFY(x) #x
- #define DIAG_JOINSTR(x,y) XSTRINGIFY(x ## y)
- #define DIAG_DO_PRAGMA(x) _Pragma (#x)
- #if defined(__GNUC__) && ((__GNUC__ * 100) + __GNUC_MINOR__) >= 402
- # define DIAG_PRAGMA(x) DIAG_DO_PRAGMA(GCC diagnostic x)
- # if ((__GNUC__ * 100) + __GNUC_MINOR__) >= 406
- # define DIAG_OFF(x) DIAG_PRAGMA(push) DIAG_PRAGMA(ignored DIAG_JOINSTR(-W,x))
- # define DIAG_ON(x) DIAG_PRAGMA(pop)
- # else
- # define DIAG_OFF(x) DIAG_PRAGMA(ignored DIAG_JOINSTR(-W,x))
- # define DIAG_ON(x) DIAG_PRAGMA(warning DIAG_JOINSTR(-W,x))
- # endif
- #elif defined(__clang__) && ((__clang_major__ * 100) + __clang_minor__ >= 208)
- # define DIAG_PRAGMA(x) DIAG_DO_PRAGMA(clang diagnostic x)
- # define DIAG_OFF(x) DIAG_PRAGMA(push) DIAG_PRAGMA(ignored DIAG_JOINSTR(-W,x))
- # define DIAG_ON(x) DIAG_PRAGMA(pop)
- #else
- # define DIAG_OFF(x)
- # define DIAG_ON(x)
- #endif
- #ifdef __APPLE__
- # define USES_APPLE_DEPRECATED_API DIAG_OFF(deprecated-declarations)
- # define USES_APPLE_RST DIAG_ON(deprecated-declarations)
- #else
- # define USES_APPLE_DEPRECATED_API
- # define USES_APPLE_RST
- #endif
- #include "funcattrs.h"
- #ifndef min
- #define min(a,b) ((a)>(b)?(b):(a))
- #endif
- #ifndef max
- #define max(a,b) ((b)>(a)?(b):(a))
- #endif
- #endif
|