home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / network / src_1218.zip / ARP.H < prev    next >
C/C++ Source or Header  |  1991-02-01  |  4KB  |  124 lines

  1. #ifndef    _ARP_H
  2. #define    _ARP_H
  3.  
  4. #ifndef    _GLOBAL_H
  5. #include "global.h"
  6. #endif
  7.  
  8. #ifndef    _MBUF_H
  9. #include "mbuf.h"
  10. #endif
  11.  
  12. #ifndef    _IFACE_H
  13. #include "iface.h"
  14. #endif
  15.  
  16. #ifndef    _TIMER_H
  17. #include "timer.h"
  18. #endif
  19.  
  20. /* Lifetime of a valid ARP entry */
  21. #define    ARPLIFE        900    /* 15 minutes */
  22. /* Lifetime of a pending ARP entry */
  23. #define    PENDTIME    15    /* 15 seconds */
  24.  
  25. /* ARP definitions (see RFC 826) */
  26.  
  27. #define    ARPLEN    16        /* Size of ARP hdr, minus hardware addresses */
  28.  
  29. /* Address size definitions */
  30. #define    IPALEN    4        /* Length in bytes of an IP address */
  31. #define    MAXHWALEN    255    /* Maximum length of a hardware address */
  32.  
  33. /* ARP opcodes */
  34. #define    ARP_REQUEST    1
  35. #define    ARP_REPLY    2
  36. #define    REVARP_REQUEST    3
  37. #define    REVARP_REPLY    4
  38.  
  39. /* Hardware types */
  40. #define    ARP_NETROM    0    /* Fake for NET/ROM (never actually sent) */
  41. #define    ARP_ETHER    1    /* Assigned to 10 megabit Ethernet */
  42. #define    ARP_EETHER    2    /* Assigned to experimental Ethernet */
  43. #define    ARP_AX25    3    /* Assigned to AX.25 Level 2 */
  44. #define    ARP_PRONET    4    /* Assigned to PROnet token ring */
  45. #define    ARP_CHAOS    5    /* Assigned to Chaosnet */
  46. #define    ARP_IEEE802    6    /* Who uses this? */
  47. #define    ARP_ARCNET    7
  48. #define    ARP_APPLETALK    8
  49. extern char *Arptypes[];    /* Type fields in ASCII, defined in arpcmd */
  50. #define    NHWTYPES 9
  51.  
  52. /* Table of hardware types known to ARP */
  53. struct arp_type {
  54.     int16 hwalen;        /* Hardware length */
  55.     int16 iptype;        /* Hardware type field for IP */
  56.     int16 arptype;        /* Hardware type field for ARP */
  57.     int16 pendtime;        /* # secs to wait pending response */
  58.     char *bdcst;        /* Hardware broadcast address */
  59.     char *(*format) __ARGS((char *,char *));
  60.                 /* Function that formats addresses */
  61.     int (*scan) __ARGS((char *,char *));
  62.                 /* Reverse of format */
  63. };
  64. extern struct arp_type Arp_type[];
  65. #define    NULLATYPE    (struct arp_type *)0
  66.  
  67. /* Format of an ARP request or reply packet. From p. 3 */
  68. struct arp {
  69.     int16 hardware;            /* Hardware type */
  70.     int16 protocol;            /* Protocol type */
  71.     char hwalen;            /* Hardware address length, bytes */
  72.     char pralen;            /* Length of protocol address */
  73.     int16 opcode;            /* ARP opcode (request/reply) */
  74.     char shwaddr[MAXHWALEN];    /* Sender hardware address field */
  75.     int32 sprotaddr;        /* Sender Protocol address field */
  76.     char thwaddr[MAXHWALEN];    /* Target hardware address field */
  77.     int32 tprotaddr;        /* Target protocol address field */
  78. };
  79.         
  80. /* Format of ARP table */
  81. struct arp_tab {
  82.     struct arp_tab *next;    /* Doubly-linked list pointers */
  83.     struct arp_tab *prev;    
  84.     struct timer timer;    /* Time until aging this entry */
  85.     struct mbuf *pending;    /* Queue of datagrams awaiting resolution */
  86.     int32 ip_addr;        /* IP Address, host order */
  87.     int16 hardware;        /* Hardware type */
  88.     char state;        /* (In)complete */
  89. #define    ARP_PENDING    0
  90. #define    ARP_VALID    1
  91.     char pub;        /* Respond to requests for this entry? */
  92.     char *hw_addr;        /* Hardware address */
  93. };
  94. #define    NULLARP    (struct arp_tab *)0
  95. extern struct arp_tab *Arp_tab[];
  96.  
  97. struct arp_stat {
  98.     unsigned recv;        /* Total number of ARP packets received */
  99.     unsigned badtype;    /* Incoming requests for unsupported hardware */
  100.     unsigned badlen;    /* Incoming length field(s) didn't match types */
  101.     unsigned badaddr;    /* Bogus incoming addresses */
  102.     unsigned inreq;        /* Incoming requests for us */
  103.     unsigned replies;    /* Replies sent */
  104.     unsigned outreq;    /* Outoging requests sent */
  105. };
  106. extern struct arp_stat Arp_stat;
  107.  
  108. /* In arp.c: */
  109. struct arp_tab *arp_add __ARGS((int32 ipaddr,int16 hardware,char *hw_addr,
  110.     int pub));
  111. void arp_drop __ARGS((void *p));
  112. int arp_init __ARGS((unsigned int hwtype,int hwalen,int iptype,int arptype,
  113.     int pendtime,char *bdcst,char *(*format) __ARGS((char *,char *)),
  114.     int  (*scan) __ARGS((char *,char *)) ));
  115. void arp_input __ARGS((struct iface *iface,struct mbuf *bp));
  116. struct arp_tab *arp_lookup __ARGS((int16 hardware,int32 ipaddr));
  117. char *res_arp __ARGS((struct iface *iface,int16 hardware,int32 target,struct mbuf *bp));
  118.  
  119. /* In arphdr.c: */
  120. struct mbuf *htonarp __ARGS((struct arp *arp));
  121. int ntoharp __ARGS((struct arp *arp,struct mbuf **bpp));
  122.  
  123. #endif /* _ARP_H */
  124.