1/* 2 * Copyright (c) 1999 Apple Inc. All rights reserved. 3 * 4 * @APPLE_LICENSE_HEADER_START@ 5 * 6 * This file contains Original Code and/or Modifications of Original Code 7 * as defined in and that are subject to the Apple Public Source License 8 * Version 2.0 (the 'License'). You may not use this file except in 9 * compliance with the License. Please obtain a copy of the License at 10 * http://www.opensource.apple.com/apsl/ and read it before using this 11 * file. 12 * 13 * The Original Code and all software distributed under the License are 14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 * Please see the License for the specific language governing rights and 19 * limitations under the License. 20 * 21 * @APPLE_LICENSE_HEADER_END@ 22 */ 23/* 24 * dhcp.h 25 * - definitions for DHCP (as specified in RFC2132) 26 */ 27 28#ifndef _S_DHCP_H 29#define _S_DHCP_H 30 31#include <stddef.h> 32#include <sys/types.h> 33#include <netinet/in.h> 34#include <netinet/in_systm.h> 35#include <netinet/ip.h> 36#include <netinet/udp.h> 37#include <stdint.h> 38 39struct dhcp { 40 u_char dp_op; /* packet opcode type */ 41 u_char dp_htype; /* hardware addr type */ 42 u_char dp_hlen; /* hardware addr length */ 43 u_char dp_hops; /* gateway hops */ 44 u_int32_t dp_xid; /* transaction ID */ 45 u_int16_t dp_secs; /* seconds since boot began */ 46 u_int16_t dp_flags; /* flags */ 47 struct in_addr dp_ciaddr; /* client IP address */ 48 struct in_addr dp_yiaddr; /* 'your' IP address */ 49 struct in_addr dp_siaddr; /* server IP address */ 50 struct in_addr dp_giaddr; /* gateway IP address */ 51 u_char dp_chaddr[16]; /* client hardware address */ 52 u_char dp_sname[64]; /* server host name */ 53 u_char dp_file[128]; /* boot file name */ 54 u_char dp_options[0]; /* variable-length options field */ 55}; 56 57struct dhcp_packet { 58 struct ip ip; 59 struct udphdr udp; 60 struct dhcp dhcp; 61}; 62 63#define DHCP_PACKET_OPTIONS_MIN 312 64#define DHCP_PACKET_MIN (sizeof(struct dhcp) + DHCP_PACKET_OPTIONS_MIN) 65#define DHCP_PACKET_OVERHEAD (offsetof(struct dhcp_packet, dhcp)) 66 67/* dhcp message types */ 68#define DHCPDISCOVER 1 69#define DHCPOFFER 2 70#define DHCPREQUEST 3 71#define DHCPDECLINE 4 72#define DHCPACK 5 73#define DHCPNAK 6 74#define DHCPRELEASE 7 75#define DHCPINFORM 8 76 77typedef enum { 78 dhcp_msgtype_none_e = 0, 79 dhcp_msgtype_discover_e = DHCPDISCOVER, 80 dhcp_msgtype_offer_e = DHCPOFFER, 81 dhcp_msgtype_request_e = DHCPREQUEST, 82 dhcp_msgtype_decline_e = DHCPDECLINE, 83 dhcp_msgtype_ack_e = DHCPACK, 84 dhcp_msgtype_nak_e = DHCPNAK, 85 dhcp_msgtype_release_e = DHCPRELEASE, 86 dhcp_msgtype_inform_e = DHCPINFORM, 87} dhcp_msgtype_t; 88 89static __inline__ const char * 90dhcp_msgtype_names(dhcp_msgtype_t type) 91{ 92 const char * names[] = { 93 "<none>", 94 "DISCOVER", 95 "OFFER", 96 "REQUEST", 97 "DECLINE", 98 "ACK", 99 "NAK", 100 "RELEASE", 101 "INFORM", 102 }; 103 if (type >= dhcp_msgtype_none_e && type <= dhcp_msgtype_inform_e) 104 return (names[type]); 105 return ("<unknown>"); 106} 107 108/* overloaded option values */ 109#define DHCP_OVERLOAD_FILE 1 110#define DHCP_OVERLOAD_SNAME 2 111#define DHCP_OVERLOAD_BOTH 3 112 113typedef uint32_t dhcptag_t; 114typedef uint32_t dhcp_lease_time_t; 115 116#define dhcp_time_hton htonl 117#define dhcp_time_ntoh ntohl 118#define dhcp_lease_hton htonl 119#define dhcp_lease_ntoh ntohl 120 121#define DHCP_INFINITE_LEASE ((dhcp_lease_time_t)-1) 122 123#define DHCP_FLAGS_BROADCAST ((u_short)0x8000) 124 125typedef enum { 126 dhcp_cstate_none_e = 0, 127 dhcp_cstate_decline_e, 128 dhcp_cstate_unbound_e, 129 dhcp_cstate_init_e, 130 dhcp_cstate_select_e, 131 dhcp_cstate_bound_e, 132 dhcp_cstate_init_reboot_e, 133 dhcp_cstate_renew_e, 134 dhcp_cstate_rebind_e, 135 dhcp_cstate_last_e = dhcp_cstate_rebind_e, 136} dhcp_cstate_t; 137 138static __inline__ const char * 139dhcp_cstate_str(dhcp_cstate_t state) 140{ 141 static const char * list[] = {"<none>", 142 "DECLINE", 143 "UNBOUND", 144 "INIT", 145 "SELECT", 146 "BOUND", 147 "INIT/REBOOT", 148 "RENEW", 149 "REBIND"}; 150 if (state <= dhcp_cstate_last_e) 151 return list[state]; 152 return ("<undefined>"); 153} 154 155#endif /* _S_DHCP_H */ 156