home *** CD-ROM | disk | FTP | other *** search
/ Black Box 4 / BlackBox.cdr / lan / soss.arj / INCLUDE / IP.H < prev    next >
C/C++ Source or Header  |  1991-04-11  |  3KB  |  100 lines

  1. /*  Copyright 1986 by Carnegie Mellon  */
  2. /*  Copyright 1983 by the Massachusetts Institute of Technology  */
  3.  
  4. #ifndef IP_H                /* DDP */
  5. #define IP_H    1            /* DDP */
  6.  
  7. /* Some useful things for Internet routines */
  8. #include <stdio.h>
  9. #include <types.h>
  10. #include <netbuf.h>
  11. #include <icmp.h>
  12.  
  13. /* IP header and internet names */
  14. /*typedef long in_name; */
  15.  
  16. union _ipname {
  17.     long in_lname;
  18.     struct {
  19.         byte in_net;
  20.         byte in_nets;
  21.         byte in_netss;
  22.         byte in_host; } in_lst; };
  23.  
  24. /* Internet status. Keeps track of packets gone through and errors. */
  25.  
  26. struct ipstat {
  27.     unsigned ip_rcv;    /* # ip packets received on interface */
  28.     unsigned ip_snd;    /* # ip packets xmitted  on interface */
  29.     unsigned ip_drop;    /* # ip packets dropped  on interface */
  30.     unsigned ip_ver;    /* because of:    bad version */
  31.     unsigned ip_len;    /*        bad length  */
  32.     unsigned ip_dest;    /*        bad destination */
  33.     unsigned ip_xsum;    /*        bad checksum */
  34.     };
  35.  
  36. struct ip {
  37.     unsigned char ip_ihl : 4; /* Internet header length in 32 bit words */
  38.     unsigned char ip_ver : 4; /* Header version */
  39.     byte ip_tsrv;        /* Type of service */
  40.     unshort ip_len;     /* Total packet length including header */
  41.     unshort ip_id;        /* ID for fragmentation */
  42.     unshort ip_foff : 13;    /* Fragment offset */
  43.     unshort ip_flgs : 3;    /* flags */
  44.     byte ip_time;        /* Time to live (secs) */
  45.     byte ip_prot;        /* protocol */
  46.     unshort ip_chksum;    /* Header checksum */
  47.     in_name ip_src;     /* Source name */
  48.     in_name ip_dest; };    /* Destination name */
  49.  
  50. /* Internet connection information */
  51.  
  52. struct ip_iob {
  53.     unshort c_prot;     /* protocol */
  54.     int    (*c_handle)();    /* upcalling packet handler */
  55.     NET    *c_net;     /* net driver */
  56.     int    (*du_handle)();    /* upcalling destination unreachable handler*/
  57.     };
  58.  
  59. typedef struct ip_iob *IPCONN;    /* The IP connection type */
  60.  
  61. /* Some useful definitions */
  62.  
  63. #ifdef LPKT            /* DDP/LKR */
  64. #define INETLEN 1280        /* DDP/LKR high performance packet size    */
  65. #else                /* DDP/LKR */
  66. #define INETLEN 576        /* maximum size of internet packet (bytes) */
  67. #endif                /* DDP/LKR */
  68.  
  69. #define IPHSIZ    sizeof(struct ip) /* internet header size */
  70. #define IP_VER    4        /* internet version */
  71. #define IP_IHL    5        /* IN header length in longwords */
  72. #define IP_TSRV 0        /* default type of service */
  73. #define IP_ID    0        /* kernel fills in IN id */
  74. #define IP_FLGS 0        /* no fragmentation yet */
  75. #define IP_FOFF 0        /* " " " */
  76. #define IP_TIME 255        /* maximum time to live */
  77. #define IPXSUM    0        /* initial checksum */
  78. #define IPLEN    sizeof(struct ip)    /* internet header length */
  79.  
  80. /* Some goodly macros */
  81. #define in_head(ppkt)    ((struct ip *)(ppkt)->nb_prot)
  82. #define in_data(pip)    ((char *)(pip) + ((pip)->ip_ihl << 2))
  83. #define in_options(pip) ((char *)(pip) + (IP_IHL << 2))
  84. #define in_optlen(pip)    (((pip)->ip_ihl - IP_IHL) << 2)
  85.  
  86. #define min(x,y)    ((x) < (y) ? (x) : (y))
  87. #define max(x,y)    ((x) > (y) ? (x) : (y))
  88.  
  89. /* some externals for internet et al */
  90. extern    PACKET    in_alloc();    /* IN packet buffer allocator */
  91. extern    PACKET    udp_alloc();    /* UDP packet allocator */
  92. extern    IPCONN    in_open();    /* internet connectio open */
  93. extern    in_name resolve_name(); /* internet name/address handler */
  94.  
  95. extern    NET    *inroute();    /* Do internet/local net routing */
  96. extern    in_name in_mymach();    /* my internet address */
  97.  
  98. extern    long    lswap();    /* byteswap long words */
  99. #endif                /* DDP */
  100.