home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 3 / PDCD_3.iso / internet / tcpipsrc / h / if / ip < prev    next >
Text File  |  1995-01-19  |  5KB  |  136 lines

  1. #define NROUTE  5       /* Number of hash chains in routing table */
  2.  
  3. extern int32 ip_addr;   /* Our IP address for ICMP and source routing */
  4.  
  5. extern char ip_ttl;     /* Default time-to-live for IP datagrams */
  6.  
  7. #define IPVERSION       4
  8. /* IP header, INTERNAL representation */
  9. struct ip {
  10.         char version;           /* IP version number */
  11.         char tos;               /* Type of service */
  12.         int16 length;           /* Total length */
  13.         int16 id;               /* Identification */
  14.         int16 fl_offs;          /* Flags + fragment offset */
  15.  
  16. #define F_OFFSET        0x1fff  /* Offset field */
  17. #define DF      0x4000          /* Don't fragment flag */
  18. #define MF      0x2000          /* More Fragments flag */       
  19.  
  20.         char ttl;               /* Time to live */
  21.         char protocol;          /* Protocol */
  22.         int32 source;           /* Source address */
  23.         int32 dest;             /* Destination address */
  24.         char options[44];       /* Options field */
  25.         int16 optlen;           /* Length of options field, bytes */
  26. };
  27.  
  28. #define NULLIP  (struct ip *)0
  29. #define IPLEN   20      /* Length of standard IP header */
  30.  
  31. /* Fields in option type byte */
  32. #define OPT_COPIED      0x80    /* Copied-on-fragmentation flag */
  33. #define OPT_CLASS       0x60    /* Option class */
  34. #define OPT_NUMBER      0x1f    /* Option number */
  35.  
  36. /* IP option numbers */
  37. #define IP_EOL          0       /* End of options list */
  38. #define IP_NOOP         1       /* No Operation */
  39. #define IP_SECURITY     2       /* Security parameters */
  40. #define IP_LSROUTE      3       /* Loose Source Routing */
  41. #define IP_TIMESTAMP    4       /* Internet Timestamp */
  42. #define IP_RROUTE       7       /* Record Route */
  43. #define IP_STREAMID     8       /* Stream ID */
  44. #define IP_SSROUTE      9       /* Strict Source Routing */
  45.  
  46. /* Timestamp option flags */
  47. #define TS_ONLY         0       /* Time stamps only */
  48. #define TS_ADDRESS      1       /* Addresses + Time stamps */
  49. #define TS_PRESPEC      3       /* Prespecified addresses only */
  50.  
  51. /* IP routing table entry */
  52. struct route {
  53.         struct route *prev;     /* Linked list pointers */
  54.         struct route *next;
  55.         int32 target;           /* Target IP address */
  56.         int32 gateway;          /* IP address of local gateway for this target */
  57.         int metric;             /* Hop count, whatever */
  58.         struct interface *interface;    /* Device interface structure */
  59. };
  60. #define NULLROUTE       (struct route *)0
  61. extern struct route *routes[32][NROUTE];        /* Routing table */
  62. extern struct route r_default;                  /* Default route entry */
  63.  
  64. /* Cache for the last-used routing entry, speeds up the common case where
  65.  * we handle a burst of packets to the same destination
  66.  */
  67. struct rt_cache {
  68.         int32 target;
  69.         struct route *route;
  70. };
  71. extern struct rt_cache rt_cache;
  72.  
  73. /* Reassembly descriptor */
  74. struct reasm {
  75.         struct reasm *next;     /* Linked list pointers */
  76.         struct reasm *prev;
  77.         int32 source;           /* These four fields uniquely describe a datagram */
  78.         int32 dest;
  79.         int16 id;
  80.         char protocol;
  81.         int16 length;           /* Entire datagram length, if known */
  82.         struct timer timer;     /* Reassembly timeout timer */
  83.         struct frag *fraglist;  /* Head of data fragment chain */
  84. };
  85. #define NULLREASM       (struct reasm *)0
  86.  
  87. /* Fragment descriptor in a reassembly list */
  88. struct frag {
  89.         struct frag *prev;      /* Previous fragment on list */
  90.         struct frag *next;      /* Next fragment */
  91.         struct mbuf *buf;       /* Actual fragment data */
  92.         int16 offset;           /* Starting offset of fragment */
  93.         int16 last;             /* Ending offset of fragment */
  94. };
  95. #define NULLFRAG        (struct frag *)0
  96.  
  97. extern struct reasm *reasmq;    /* The list of reassembly descriptors */
  98.  
  99. /* IP error logging counters */
  100. struct ip_stats {
  101.         long total;             /* Total packets received */
  102.         unsigned runt;          /* Smaller than minimum size */
  103.         unsigned length;        /* IP header length field too small */
  104.         unsigned version;       /* Wrong IP version */
  105.         unsigned checksum;      /* IP header checksum errors */
  106.         unsigned badproto;      /* Unsupported protocol */
  107. };
  108. extern struct ip_stats ip_stats;
  109.  
  110. /* In IP */
  111. int ip_send(int32, int32, char, char, char, struct mbuf *, int16,
  112.             int16, char);
  113. void ip_recv(struct ip *, struct mbuf *, char);
  114.  
  115. /* IPCMD */
  116. int doip(int, char **);
  117. int doipaddr(int, char **);
  118. int dottl(int, char **);
  119. int doroute(int, char **);
  120. int doadd(int, char **);
  121. int dodrop(int, char **);
  122. int dumproute(void);
  123. int doipstat(int, char **);
  124.  
  125. /* IPDUMP */
  126. void ip_dump(struct mbuf **, int);
  127.  
  128. /* In IPROUTE */
  129. int ip_route(struct mbuf *, char);
  130. int rt_add(int32, unsigned int, int32, int, struct interface *);
  131. int rt_drop(int32, unsigned int);
  132. int16 ip_mtu(int32);
  133. struct mbuf *htonip(struct ip *, struct mbuf *);
  134. int ntohip(struct ip *, struct mbuf **);
  135. int16 eac(int32);
  136.