2010-11-13 17:21:57 +05:30
|
|
|
#ifndef PACKET_H_
|
|
|
|
#define PACKET_H_
|
2010-11-12 14:32:18 +05:30
|
|
|
|
|
|
|
#include <netinet/udp.h>
|
|
|
|
#include <netinet/ip.h>
|
|
|
|
|
2010-12-24 19:25:59 +05:30
|
|
|
#include "config.h"
|
|
|
|
|
2010-11-12 14:32:18 +05:30
|
|
|
struct dhcpMessage {
|
2011-03-31 04:28:09 +05:30
|
|
|
uint8_t op; // Message type: 1 = BOOTREQUEST for clients.
|
|
|
|
uint8_t htype; // ARP HW address type: always '1' for 10MB ethernet.
|
|
|
|
uint8_t hlen; // Hardware address length: always '6' for 10MB ethernet.
|
|
|
|
uint8_t hops; // Client sets to zero.
|
|
|
|
uint32_t xid; // Transaction ID: random number identifying session
|
|
|
|
uint16_t secs; // Filled by client: seconds since client began address
|
|
|
|
// aquisition or renewal process.
|
|
|
|
uint16_t flags; // DHCP flags
|
|
|
|
uint32_t ciaddr; // Client IP: only filled in if client is inBOUND, RENEW,
|
|
|
|
// or REBINDING and can reply to ARP requests
|
|
|
|
uint32_t yiaddr; // 'your' (client) IP address
|
|
|
|
uint32_t siaddr; // IP address of next server to use in bootstrap; returned
|
|
|
|
// in DHCPOFFER or DHCPACK by server
|
|
|
|
uint32_t giaddr; // relay agent IP: used when booting via relay agent
|
|
|
|
uint8_t chaddr[16]; // Client MAC address
|
|
|
|
uint8_t sname[64]; // Server host name (optional); null-terminated string
|
|
|
|
uint8_t file[128]; // boot file name, null-terminated string
|
2010-11-14 11:24:05 +05:30
|
|
|
uint32_t cookie;
|
|
|
|
uint8_t options[308]; /* 312 - cookie */
|
2010-11-12 14:32:18 +05:30
|
|
|
};
|
|
|
|
|
2010-11-14 12:23:23 +05:30
|
|
|
struct ip_udp_dhcp_packet {
|
2010-11-14 11:24:05 +05:30
|
|
|
struct iphdr ip;
|
|
|
|
struct udphdr udp;
|
|
|
|
struct dhcpMessage data;
|
2010-11-12 14:32:18 +05:30
|
|
|
};
|
|
|
|
|
2010-11-14 12:23:23 +05:30
|
|
|
struct udp_dhcp_packet {
|
|
|
|
struct udphdr udp;
|
|
|
|
struct dhcpMessage data;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
IP_UPD_DHCP_SIZE = sizeof(struct ip_udp_dhcp_packet),
|
|
|
|
UPD_DHCP_SIZE = sizeof(struct udp_dhcp_packet),
|
|
|
|
DHCP_SIZE = sizeof(struct dhcpMessage),
|
|
|
|
};
|
|
|
|
|
2010-11-12 14:32:18 +05:30
|
|
|
int get_packet(struct dhcpMessage *packet, int fd);
|
|
|
|
uint16_t checksum(void *addr, int count);
|
2010-11-14 11:24:05 +05:30
|
|
|
int raw_packet(struct dhcpMessage *payload, uint32_t source_ip,
|
|
|
|
int source_port, uint32_t dest_ip, int dest_port,
|
|
|
|
unsigned char *dest_arp, int ifindex);
|
|
|
|
int kernel_packet(struct dhcpMessage *payload, uint32_t source_ip,
|
|
|
|
int source_port, uint32_t dest_ip, int dest_port);
|
2010-12-24 20:11:52 +05:30
|
|
|
void change_listen_mode(struct client_state_t *cs, int new_mode);
|
2010-12-24 19:25:59 +05:30
|
|
|
void handle_packet(struct client_state_t *cs);
|
2010-11-12 14:32:18 +05:30
|
|
|
#endif
|