⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wattcp.h

📁 开放源码的编译器open watcom 1.6.0版的源代码
💻 H
📖 第 1 页 / 共 2 页
字号:
#ifndef __WATTCP_H
#define __WATTCP_H    

/*
 * Our basic types
 */
typedef unsigned char   BYTE;           /*  8 bits   */
typedef unsigned short  WORD;           /* 16 bits   */
typedef unsigned long   DWORD;          /* 32 bits   */
typedef unsigned int    UINT;           /* 16/32 bit */
typedef BYTE            eth_address[6];
typedef BYTE            ax25_address[7];

#define mac_address eth_address /* our emphasis is no longer on Ethernet */

typedef int (*ProtoHandler) (void *sock, BYTE *data, int len,
                             void *tcp_phdr, void *udp_hdr);

typedef int (*UserHandler)  (void *sock);

typedef int (*sol_upcall)   (void *socket, int icmp_type);

#if defined(__HIGHC__) || defined(__GNUC__)
  typedef unsigned long long  uint64;
  #define HAVE_UINT64

#elif defined(__WATCOMC__) && defined(__WATCOM_INT64__)
  typedef unsigned __int64 uint64;
  #define HAVE_UINT64
#endif

/*
 * Until C compilers support C++ namespaces, we use this
 * prefix for our namespace.
 */
#define NAMESPACE(x)    _w32_ ## x     


#include "target.h"        /* portability macros & defines */
#include "config.h"        /* options & features to include */

#if defined(USE_FORTIFY)
#include "fortify.h"       /* use Fortify malloc library */
#endif

/*
 * Sizes and protocols we use
 */
#define ETH_MAX_DATA     1500
#define ETH_MIN          60
#define ETH_MAX          (ETH_MAX_DATA + sizeof(eth_Header))

#define TOK_MAX_DATA     ETH_MAX_DATA  /* could be much larger */
#define TOK_MAX          (TOK_MAX_DATA + sizeof(tok_Header))
#define TOK_MIN          sizeof(tok_Header)

#define FDDI_MAX_DATA    ETH_MAX_DATA  /* really is 4470 */
#define FDDI_MAX         (FDDI_MAX_DATA + sizeof(fddi_Header))
#define FDDI_MIN         (3 + sizeof(fddi_Header))

#define AX25_MAX_DATA    ETH_MAX_DATA
#define AX25_MAX         (AX25_MAX_DATA + sizeof(ax25_Header))
#define AX25_MIN         sizeof(ax25_Header)

#define PPPOE_MAX_DATA   (ETH_MAX_DATA-12)  // !!
#define PPPOE_MAX        (PPPOE_MAX_DATA + sizeof(pppoe_Header))
#define PPPOE_MIN        sizeof(pppoe_Header)

#define IP_TYPE          0x0008  /* these are in network order */
#define ARP_TYPE         0x0608
#define RARP_TYPE        0x3508
#define PPPOE_DISC_TYPE  0x8863
#define PPPOE_SESS_TYPE  0x8864


#if (DOSX)
#define MAX_FRAGMENTS    45UL
#else
#define MAX_FRAGMENTS    30UL
#endif

/* This should really be a function of current MAC-driver
 */
#define MAX_IP_DATA      (ETH_MAX_DATA - sizeof(in_Header))
#define MAX_FRAG_SIZE    (MAX_FRAGMENTS * MAX_IP_DATA)

#define MAX_COOKIES      10
#define MAX_STRING       50
#define MAX_PATHLEN      80
#define MAX_HOSTLEN      80           /* most strings are limited */
#define MAX_WINDOW       32767        /* max tcp window */

#define SAFETYTCP        0x538F25A3L  /* marker signatures */
#define SAFETYUDP        0x3E45E154L

#ifndef FALSE
#define FALSE            0
#endif

#ifndef TRUE
#define TRUE             (!FALSE)
#endif

/*
 * These are IP protocol numbers (see RFC-1700)
 */
#define UDP_PROTO        17
#define TCP_PROTO        6
#define ICMP_PROTO       1
#define IGMP_PROTO       2

#define TCP_MODE_BINARY  0       /* default mode */
#define TCP_MODE_ASCII   1
#define UDP_MODE_CHK     0       /* default to having checksums */
#define UDP_MODE_NOCHK   2       /* turn off checksums */
#define TCP_MODE_NAGLE   0       /* Nagle algorithm */
#define TCP_MODE_NONAGLE 4

/*
 * These are the IP options
 */
#define IPOPT_EOL        0       /* end-of-option list */
#define IPOPT_NOP        1       /* no-operation */
#define IPOPT_RR         7       /* record packet route */
#define IPOPT_TS         68      /* timestamp */
#define IPOPT_SECURITY   130     /* provide s,c,h,tcc */
#define IPOPT_LSRR       131     /* loose source route */
#define IPOPT_SATID      136     /* satnet id */
#define IPOPT_SSRR       137     /* strict source route */
#define IPOPT_RA         148     /* router alert */

/*
 * These are the TCP options
 */
#define TCPOPT_EOL       0       /* end-of-option list */
#define TCPOPT_NOP       1       /* no-operation */
#define TCPOPT_MAXSEG    2       /* maximum segment size */
#define TCPOPT_WINDOW    3       /* window scale factor (rfc1072) */
#define TCPOPT_SACKOK    4       /* selective ack ok (rfc1072) */
#define TCPOPT_SACK      5       /* selective ack (rfc1072) */
#define TCPOPT_ECHO      6       /* echo (rfc1072) */
#define TCPOPT_ECHOREPLY 7       /* echo (rfc1072) */
#define TCPOPT_TIMESTAMP 8       /* timestamps (rfc1323) */
#define TCPOPT_CC        11      /* T/TCP CC options (rfc1644) */
#define TCPOPT_CCNEW     12      /* T/TCP CC options (rfc1644) */
#define TCPOPT_CCECHO    13      /* T/TCP CC options (rfc1644) */

#define TCP_MAX_WINSHIFT 14      /* maximum window shift */

/*
 * These are the ICMP messages. Should be same as in <netinet/ip_icmp.h>
 */
#define ICMP_ECHOREPLY     0     /* echo reply */
#define ICMP_UNREACH       3     /* dest unreachable */
#define ICMP_SOURCEQUENCH  4     /* packet lost, slow down */
#define ICMP_REDIRECT      5     /* shorter route        */
#define ICMP_ECHO          8     /* echo service         */
#define ICMP_ROUTERADVERT  9     /* router advertisement */
#define ICMP_ROUTERSOLICIT 10    /* router solicitation  */
#define ICMP_TIMXCEED      11    /* time exceeded        */
#define ICMP_PARAMPROB     12    /* ip header bad        */
#define ICMP_TSTAMP        13    /* timestamp request    */
#define ICMP_TSTAMPREPLY   14    /* timestamp reply      */
#define ICMP_IREQ          15    /* information request  */
#define ICMP_IREQREPLY     16    /* information reply    */
#define ICMP_MASKREQ       17    /* address mask request */
#define ICMP_MASKREPLY     18    /* address mask reply   */
#define ICMP_MAXTYPE       18

/*
 * UDP/TCP socket local flags (locflags) bits.
 * Mostly used to support the BSD-socket API.
 */
#define LF_NODELAY      0x0001   /* don't use Nagle       */
#define LF_NOPUSH       0x0002   /* don't push on write   */
#define LF_NOOPT        0x0004   /* don't use tcp options */
#define LF_REUSEADDR    0x0008   /* to-do !! */
#define LF_KEEPALIVE    0x0010
#define LF_LINGER       0x0020
#define LF_xxxxxxxxxxx  0x0040
#define LF_NOFRAGMENT   0x0080
#define LF_OOBINLINE    0x0100
#define LF_SNDTIMEO     0x0200
#define LF_RCVTIMEO     0x0400
#define LF_GOT_FIN      0x0800
#define LF_REQ_TSTMP    0x1000   /* have/will request timestamps */
#define LF_RCVD_TSTMP   0x2000   /* a timestamp was received in SYN */
#define LF_RCVD_SCALE   0x4000   /* a win-scale was received in SYN */

#define loBYTE(w)       (BYTE)(w)
#define hiBYTE(w)       (BYTE)((WORD)(w) >> 8)
#define ARGSUSED(foo)   (void)foo
#define DIM(x)          (sizeof(x) / sizeof((x)[0]))

/*
 * Socket-states for sock_sselect().
 * Not used by BSD-socket API
 */
#define SOCKESTABLISHED  1
#define SOCKDATAREADY    2
#define SOCKCLOSED       4


#include <sys/packon.h>  /* align structs on byte boundaries */

/*
 * The Internet (ip) Header
 */
typedef struct in_Header {
        BYTE   hdrlen : 4;     /* Watcom requires BYTE here */
        BYTE   ver    : 4;
        BYTE   tos;
        WORD   length;
        WORD   identification;
        WORD   frag_ofs;
        BYTE   ttl;
        BYTE   proto;
        WORD   checksum;
        DWORD  source;
        DWORD  destination;
      } in_Header;

#define IP_CE      0x8000     /* `in_Header.frag_ofs' masks: */
#define IP_DF      0x4000     /*   Congestion Experienced */
#define IP_MF      0x2000     /*   Don't Fragment */
#define IP_OFFMASK 0x1fff     /*   More Fragments */

#define in_GetHdrLen(ip) ((ip)->hdrlen << 2)  /* # of bytes in IP-header */

/*
 * IP packet incuding header and data
 */
typedef struct ip_Packet {    
        in_Header head;
        BYTE      data [MAX_IP_DATA];
      } ip_Packet;


/*
 * The UDP/TCP headers
 */
typedef struct udp_Header {
        WORD   srcPort;
        WORD   dstPort;
        WORD   length;
        WORD   checksum;
      } udp_Header;

typedef struct tcp_Header {
        WORD   srcPort;
        WORD   dstPort;
        DWORD  seqnum;
        DWORD  acknum;
        BYTE   unused : 4;   /* Watcom requires BYTE here */
        BYTE   offset : 4;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -