dhcp.h
上传用户:luoyougen
上传日期:2008-05-12
资源大小:23136k
文件大小:11k
源码类别:

VxWorks

开发平台:

C/C++

  1. /* dhcp.h - Common DHCP include file for server, relay agent, and client */
  2. /* Copyright 1984 - 2001 Wind River Systems, Inc. */
  3. /*
  4. modification history
  5. ---------------------
  6. 01j,23apr02,wap  Add prototype for dhcpTime() (SPR #68900)
  7. 01i,27jun01,ppp  removed MIN LEASE since it is not supported any more (SPR
  8.                  #34799)
  9. 01h,07sep00,spm  moved client-specific transmit routine to private module
  10. 01g,05apr00,spm  added entries for boot-time client shared code
  11. 01f,24nov99,spm  upgraded to RFC 2131 and removed direct link-level access
  12. 01e,04dec97,spm  added code review modifications
  13. 01d,06aug97,spm  added definitions for C++ compilation
  14. 01c,02jun97,spm  changed DHCP option tags to prevent name conflicts (SPR #8667)
  15. 01b,29jan97,spm  added little-endian support and additional DHCP defines.
  16. 01a,03oct96,spm  created by modifying WIDE project DHCP Implementation.
  17. */
  18. #ifndef __INCdhcph
  19. #define __INCdhcph
  20. #ifdef __cplusplus
  21. extern "C" {
  22. #endif
  23. /*
  24.  * WIDE Project DHCP Implementation
  25.  * Copyright (c) 1995 Akihiro Tominaga
  26.  * Copyright (c) 1995 WIDE Project
  27.  * All rights reserved.
  28.  *
  29.  * Permission to use, copy, modify and distribute this software and its
  30.  * documentation is hereby granted, provided only with the following
  31.  * conditions are satisfied:
  32.  *
  33.  * 1. Both the copyright notice and this permission notice appear in
  34.  *    all copies of the software, derivative works or modified versions,
  35.  *    and any portions thereof, and that both notices appear in
  36.  *    supporting documentation.
  37.  * 2. All advertising materials mentioning features or use of this software
  38.  *    must display the following acknowledgement:
  39.  *      This product includes software developed by WIDE Project and
  40.  *      its contributors.
  41.  * 3. Neither the name of WIDE Project nor the names of its contributors
  42.  *    may be used to endorse or promote products derived from this software
  43.  *    without specific prior written permission.
  44.  *
  45.  * THIS SOFTWARE IS PROVIDED BY THE DEVELOPER ``AS IS'' AND WIDE
  46.  * PROJECT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
  47.  * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. ALSO, THERE
  48.  * IS NO WARRANTY IMPLIED OR OTHERWISE, NOR IS SUPPORT PROVIDED.
  49.  *
  50.  * Feedback of the results generated from any improvements or
  51.  * extensions made to this software would be much appreciated.
  52.  * Any such feedback should be sent to:
  53.  * 
  54.  *  Akihiro Tominaga
  55.  *  WIDE Project
  56.  *  Keio University, Endo 5322, Kanagawa, Japan
  57.  *  (E-mail: dhcp-dist@wide.ad.jp)
  58.  *
  59.  * WIDE project has the rights to redistribute these changes.
  60.  */
  61. #include "netinet/in.h"
  62. /* Tag values for DHCP options. */
  63. #define _DHCP_PAD_TAG  ((char)   0)
  64. #define _DHCP_SUBNET_MASK_TAG  ((char)   1)
  65. #define _DHCP_TIME_OFFSET_TAG  ((char)   2)
  66. #define _DHCP_ROUTER_TAG  ((char)   3)
  67. #define _DHCP_TIME_SERVER_TAG  ((char)   4)
  68. #define _DHCP_NAME_SERVER_TAG  ((char)   5)
  69. #define _DHCP_DNS_SERVER_TAG  ((char)   6)
  70. #define _DHCP_LOG_SERVER_TAG  ((char)   7)
  71. #define _DHCP_COOKIE_SERVER_TAG  ((char)   8)
  72. #define _DHCP_LPR_SERVER_TAG ((char)   9)
  73. #define _DHCP_IMPRESS_SERVER_TAG  ((char)  10)
  74. #define _DHCP_RLS_SERVER_TAG  ((char)  11)
  75. #define _DHCP_HOSTNAME_TAG              ((char)  12)
  76. #define _DHCP_BOOTSIZE_TAG  ((char)  13)
  77. #define _DHCP_MERIT_DUMP_TAG  ((char)  14)
  78. #define _DHCP_DNS_DOMAIN_TAG  ((char)  15)
  79. #define _DHCP_SWAP_SERVER_TAG  ((char)  16)
  80. #define _DHCP_ROOT_PATH_TAG  ((char)  17)
  81. #define _DHCP_EXTENSIONS_PATH_TAG  ((char)  18)
  82. #define _DHCP_IP_FORWARD_TAG  ((char)  19)
  83. #define _DHCP_NONLOCAL_SRCROUTE_TAG  ((char)  20)
  84. #define _DHCP_POLICY_FILTER_TAG  ((char)  21)
  85. #define _DHCP_MAX_DGRAM_SIZE_TAG  ((char)  22)
  86. #define _DHCP_DEFAULT_IP_TTL_TAG  ((char)  23)
  87. #define _DHCP_MTU_AGING_TIMEOUT_TAG  ((char)  24)
  88. #define _DHCP_MTU_PLATEAU_TABLE_TAG  ((char)  25)
  89. #define _DHCP_IF_MTU_TAG  ((char)  26)
  90. #define _DHCP_ALL_SUBNET_LOCAL_TAG  ((char)  27)
  91. #define _DHCP_BRDCAST_ADDR_TAG  ((char)  28)
  92. #define _DHCP_MASK_DISCOVER_TAG  ((char)  29)
  93. #define _DHCP_MASK_SUPPLIER_TAG  ((char)  30)
  94. #define _DHCP_ROUTER_DISCOVER_TAG  ((char)  31)
  95. #define _DHCP_ROUTER_SOLICIT_TAG  ((char)  32)
  96. #define _DHCP_STATIC_ROUTE_TAG  ((char)  33)
  97. #define _DHCP_TRAILER_TAG  ((char)  34)
  98. #define _DHCP_ARP_CACHE_TIMEOUT_TAG  ((char)  35)
  99. #define _DHCP_ETHER_ENCAP_TAG  ((char)  36)
  100. #define _DHCP_DEFAULT_TCP_TTL_TAG  ((char)  37)
  101. #define _DHCP_KEEPALIVE_INTERVAL_TAG  ((char)  38)
  102. #define _DHCP_KEEPALIVE_GARBAGE_TAG  ((char)  39)
  103. #define _DHCP_NIS_DOMAIN_TAG  ((char)  40)
  104. #define _DHCP_NIS_SERVER_TAG  ((char)  41)
  105. #define _DHCP_NTP_SERVER_TAG  ((char)  42)
  106. #define _DHCP_VENDOR_SPEC_TAG  ((char)  43)
  107. #define _DHCP_NBN_SERVER_TAG  ((char)  44)
  108. #define _DHCP_NBDD_SERVER_TAG  ((char)  45)
  109. #define _DHCP_NB_NODETYPE_TAG  ((char)  46)
  110. #define _DHCP_NB_SCOPE_TAG  ((char)  47)
  111. #define _DHCP_XFONT_SERVER_TAG  ((char)  48)
  112. #define _DHCP_XDISPLAY_MANAGER_TAG  ((char)  49)
  113. #define _DHCP_REQUEST_IPADDR_TAG  ((char)  50)
  114. #define _DHCP_LEASE_TIME_TAG  ((char)  51)
  115. #define _DHCP_OPT_OVERLOAD_TAG  ((char)  52)
  116. #define _DHCP_MSGTYPE_TAG  ((char)  53)
  117. #define _DHCP_SERVER_ID_TAG  ((char)  54)
  118. #define _DHCP_REQ_LIST_TAG  ((char)  55)
  119. #define _DHCP_ERRMSG_TAG  ((char)  56)
  120. #define _DHCP_MAXMSGSIZE_TAG  ((char)  57)
  121. #define _DHCP_T1_TAG  ((char)  58) 
  122. #define _DHCP_T2_TAG  ((char)  59)
  123. #define _DHCP_CLASS_ID_TAG  ((char)  60)
  124. #define _DHCP_CLIENT_ID_TAG  ((char)  61)
  125. #define _DHCP_NISP_DOMAIN_TAG  ((char)  64)
  126. #define _DHCP_NISP_SERVER_TAG  ((char)  65)
  127. #define _DHCP_TFTP_SERVERNAME_TAG  ((char)  66)
  128. #define _DHCP_BOOTFILE_TAG  ((char)  67)
  129. #define _DHCP_MOBILEIP_HA_TAG  ((char)  68)
  130. #define _DHCP_SMTP_SERVER_TAG  ((char)  69)
  131. #define _DHCP_POP3_SERVER_TAG  ((char)  70)
  132. #define _DHCP_NNTP_SERVER_TAG  ((char)  71)
  133. #define _DHCP_DFLT_WWW_SERVER_TAG  ((char)  72)
  134. #define _DHCP_DFLT_FINGER_SERVER_TAG  ((char)  73)
  135. #define _DHCP_DFLT_IRC_SERVER_TAG  ((char)  74)
  136. #define _DHCP_STREETTALK_SERVER_TAG  ((char)  75)
  137. #define _DHCP_STDA_SERVER_TAG  ((char)  76)
  138. #define _DHCP_END_TAG  ((char) 255)
  139. #define _DHCP_LAST_OPTION  _DHCP_STDA_SERVER_TAG
  140. #define _DHCP_MAX_OPTLEN  255
  141. /* 
  142.  * Hardware type values from the arp section of the assigned numbers RFC. 
  143.  * (Frequently used as client identifier types).
  144.  */
  145. #define ETHER           1       /* Ethernet (10Mb) */
  146. #define EXPETHER        2       /* Experimental Ethernet (3Mb) */
  147. #define AX25            3       /* Amateur Radio AX.25 */
  148. #define PRONET          4       /* Proteon ProNET Token Ring */
  149. #define CHAOS           5       /* Chaos */
  150. #define IEEE802         6       /* IEEE 802 Networks */
  151. #define ARCNET          7       /* ARCNET */
  152. #define HYPERCH         8       /* Hyperchannel */
  153. #define LANSTAR         9       /* Lanstar */
  154. #define AUTONET         10      /* Autonet Short Address */
  155. #define LOCALTALK       11      /* LocalTalk */
  156. #define LOCALNET        12      /* LocalNet */
  157. #define ULTRALINK  13  /* Ultra link */
  158. #define FRAMERELAY  15  /* Frame Relay */
  159. #define SERIAL  20  /* Serial Line */
  160. #define DNS_NAME        128     /* DNS name */
  161. /* Definitions for DHCP message format. */
  162. #define MAX_HLEN      16    /* maximum length of haddr field */
  163. #define MAX_SNAME     64
  164. #define MAX_FILE     128
  165. #define DFLTOPTLEN   312
  166. #define BOOTPOPTLEN   64
  167. #define MAXOPT      0xff
  168. #define INFINITY    0xffffffff
  169. /* Definitions for ARP messages. */
  170. #define MAX_ARPLEN    (sizeof (struct arphdr) + 2 * (MAX_HLEN + 4))
  171. #define ARPHL    (sizeof (struct arphdr))
  172. #if CPU_FAMILY==I960
  173. #pragma align 1                 /* tell gcc960 not to optimize alignments */
  174. #endif  /* CPU_FAMILY==I960 */
  175. /* DHCP message format */
  176. struct dhcp
  177.     {
  178.     unsigned char       op;             /* packet type */
  179.     unsigned char       htype;          /* Link-level interface address type */
  180.     unsigned char       hlen;   /* Link-level interface address length */
  181.     unsigned char       hops;           /* Hops through DHCP relay agents */
  182.     unsigned long       xid;            /* transaction ID */
  183.     unsigned short      secs;   /* seconds since lease negotiation started */
  184.     unsigned short      flags;
  185.     struct in_addr      ciaddr;         /* Client's current IP address */
  186.     struct in_addr      yiaddr;         /* Client's assigned IP address */
  187.     struct in_addr      siaddr;         /* Address of (tftp) server */
  188.     struct in_addr      giaddr;         /* Address of relay agent */
  189.     char                chaddr [MAX_HLEN];      /* Client's hardware address */
  190.     char                sname [MAX_SNAME];      /* Host name of DHCP server */
  191.     char                file [MAX_FILE];        /* File name of boot image */
  192.     char                options [DFLTOPTLEN];   /* DHCP message options */
  193.     };
  194. struct ps_udph          /* pseudo udp header for checksum */
  195.     {
  196.     struct in_addr      srcip;
  197.     struct in_addr      dstip;
  198.     char                zero;
  199.     char                prto;
  200.     short               ulen;
  201.     };
  202. #if CPU_FAMILY==I960
  203. #pragma align 0                 /* turn off alignment requirement */
  204. #endif  /* CPU_FAMILY==I960 */
  205. /* Definitions for processing incoming DHCP messages */
  206. #define DHCP_MSG_SIZE (DFLTDHCPLEN + UDPHL + IPHL)
  207. #define MESSAGE_RING_SIZE (10 * DHCP_MSG_SIZE)
  208. #define DFLTDHCPLEN   sizeof (struct dhcp)   /* default DHCP message size */
  209. #define DFLTBOOTPLEN  (DFLTDHCPLEN - DFLTOPTLEN + BOOTPOPTLEN)
  210. #define DHCPLEN(UDP)  (ntohs(UDP->uh_ulen) - UDPHL)  /* get DHCP msg size */
  211.                                                      /* from UDP header */
  212. #define OPTBODY(TAGP)  ( ( (char *)TAGP) + 2)   /* get DHCP option contents */
  213. #define DHCPOPTLEN(TAGP) ((UINT8) * ( ((char *)TAGP) + 1)) /* option length */
  214. /* handle the word alignment */
  215. #define   GETHS(PTR)  (*((u_char *)PTR)*256 + *(((u_char *)PTR)+1))
  216. #define   GETHL(PTR)  (*((u_char *)PTR)*256*256*256 + *(((u_char *)PTR)+1)*256*256 +
  217.                        *(((u_char *)PTR)+2)*256 + *(((u_char *)PTR)+3))
  218. /* Bit operators for options flags. */
  219. #define SETBIT(a,i)   ((a)[(i) / 8] |= (1 << (7 - (i) % 8)))
  220. #define CLRBIT(a,i)   ((a)[(i) / 8] &= ~(1 << (7 - (i) % 8)))
  221. #define ISSET(a,i)    ((a)[(i) / 8] & (1 << (7 - (i) % 8)))
  222. #define ISCLR(a,i)    (((a)[(i) / 8] & (1 << (7 - (i) % 8))) == 0)
  223. #define BOOTREQUEST 1
  224. #define BOOTREPLY 2
  225. /*
  226.  * DHCP/BOOTP magic cookie defined in RFC 1048
  227.  */
  228. #define RFC1048_MAGIC { 99, 130, 83, 99 }
  229. #define MAGIC_LEN  4
  230. /* DHCP message types */
  231. #define DHCPDISCOVER           1
  232. #define DHCPOFFER              2
  233. #define DHCPREQUEST            3
  234. #define DHCPDECLINE            4
  235. #define DHCPACK                5
  236. #define DHCPNAK                6
  237. #define DHCPRELEASE            7
  238. #define DHCPINFORM             8
  239. #define BOOTP                  0
  240. /* Classification of DHCP message fields */
  241. #define FILE_ISOPT             1
  242. #define SNAME_ISOPT            2
  243. #define BOTH_AREOPT            FILE_ISOPT + SNAME_ISOPT
  244. /* Common routines for all DHCP components */
  245. IMPORT int dhcpConvert (int);
  246. IMPORT char * pickup_opt (struct dhcp *, int, char);
  247. IMPORT u_short udp_cksum (struct ps_udph *, char *, int);
  248. IMPORT time_t dhcpTime (time_t *);
  249. #ifdef __cplusplus
  250. }
  251. #endif
  252. #endif