#ifndef _S_DHCP_H
#define _S_DHCP_H
#include <sys/types.h>
#include <netinet/in.h>
#include <netinet/in_systm.h>
#include <netinet/ip.h>
#include <netinet/udp.h>
#include <stdint.h>
struct dhcp {
u_char dp_op;
u_char dp_htype;
u_char dp_hlen;
u_char dp_hops;
u_int32_t dp_xid;
u_int16_t dp_secs;
u_int16_t dp_flags;
struct in_addr dp_ciaddr;
struct in_addr dp_yiaddr;
struct in_addr dp_siaddr;
struct in_addr dp_giaddr;
u_char dp_chaddr[16];
u_char dp_sname[64];
u_char dp_file[128];
u_char dp_options[0];
};
struct dhcp_packet {
struct ip ip;
struct udphdr udp;
struct dhcp dhcp;
};
#define DHCP_PACKET_OPTIONS_MIN 312
#define DHCP_PACKET_MIN (sizeof(struct dhcp) + DHCP_PACKET_OPTIONS_MIN)
#define DHCPDISCOVER 1
#define DHCPOFFER 2
#define DHCPREQUEST 3
#define DHCPDECLINE 4
#define DHCPACK 5
#define DHCPNAK 6
#define DHCPRELEASE 7
#define DHCPINFORM 8
typedef enum {
dhcp_msgtype_none_e = 0,
dhcp_msgtype_discover_e = DHCPDISCOVER,
dhcp_msgtype_offer_e = DHCPOFFER,
dhcp_msgtype_request_e = DHCPREQUEST,
dhcp_msgtype_decline_e = DHCPDECLINE,
dhcp_msgtype_ack_e = DHCPACK,
dhcp_msgtype_nak_e = DHCPNAK,
dhcp_msgtype_release_e = DHCPRELEASE,
dhcp_msgtype_inform_e = DHCPINFORM,
} dhcp_msgtype_t;
static __inline__ const char *
dhcp_msgtype_names(dhcp_msgtype_t type)
{
const char * names[] = {
"<none>",
"DISCOVER",
"OFFER",
"REQUEST",
"DECLINE",
"ACK",
"NAK",
"RELEASE",
"INFORM",
};
if (type >= dhcp_msgtype_none_e && type <= dhcp_msgtype_inform_e)
return (names[type]);
return ("<unknown>");
}
#define DHCP_OVERLOAD_FILE 1
#define DHCP_OVERLOAD_SNAME 2
#define DHCP_OVERLOAD_BOTH 3
typedef uint32_t dhcptag_t;
typedef int32_t dhcp_time_secs_t;
typedef dhcp_time_secs_t dhcp_interval_secs_t;
typedef dhcp_interval_secs_t dhcp_lease_t;
#define dhcp_time_hton htonl
#define dhcp_time_ntoh ntohl
#define dhcp_lease_hton htonl
#define dhcp_lease_ntoh ntohl
#define DHCP_INFINITE_LEASE ((dhcp_lease_t)-1)
#define DHCP_INFINITE_TIME ((dhcp_time_secs_t)-1)
#define DHCP_FLAGS_BROADCAST ((u_short)0x8000)
typedef enum {
dhcp_cstate_none_e = 0,
dhcp_cstate_decline_e,
dhcp_cstate_unbound_e,
dhcp_cstate_init_e,
dhcp_cstate_select_e,
dhcp_cstate_bound_e,
dhcp_cstate_init_reboot_e,
dhcp_cstate_renew_e,
dhcp_cstate_rebind_e,
dhcp_cstate_last_e = dhcp_cstate_rebind_e,
} dhcp_cstate_t;
static __inline__ const char *
dhcp_cstate_str(dhcp_cstate_t state)
{
static const char * list[] = {"<none>",
"DECLINE",
"UNBOUND",
"INIT",
"SELECT",
"BOUND",
"INIT/REBOOT",
"RENEW",
"REBIND"};
if (state <= dhcp_cstate_last_e)
return list[state];
return ("<undefined>");
}
#endif _S_DHCP_H