Convert DHCP option code numbers to an enum.
Convert many remaining /**/ comments to // where it makes for less visual clutter.
This commit is contained in:
parent
9224374d98
commit
801ec356f4
30
ndhc/arp.h
30
ndhc/arp.h
@ -31,22 +31,22 @@
|
||||
#include "dhcp.h"
|
||||
|
||||
struct arpMsg {
|
||||
/* Ethernet header */
|
||||
uint8_t h_dest[6]; /* 00 destination ether addr */
|
||||
uint8_t h_source[6]; /* 06 source ether addr */
|
||||
uint16_t h_proto; /* 0c packet type ID field */
|
||||
// Ethernet header
|
||||
uint8_t h_dest[6]; // 00 destination ether addr
|
||||
uint8_t h_source[6]; // 06 source ether addr
|
||||
uint16_t h_proto; // 0c packet type ID field
|
||||
|
||||
/* ARP packet */
|
||||
uint16_t htype; /* 0e hardware type (must be ARPHRD_ETHER) */
|
||||
uint16_t ptype; /* 10 protocol type (must be ETH_P_IP) */
|
||||
uint8_t hlen; /* 12 hardware address length (must be 6) */
|
||||
uint8_t plen; /* 13 protocol address length (must be 4) */
|
||||
uint16_t operation; /* 14 ARP opcode */
|
||||
uint8_t smac[6]; /* 16 sender's hardware address */
|
||||
uint8_t sip4[4]; /* 1c sender's IP address */
|
||||
uint8_t dmac[6]; /* 20 target's hardware address */
|
||||
uint8_t dip4[4]; /* 26 target's IP address */
|
||||
uint8_t pad[18]; /* 2a pad for min. ethernet payload (60 bytes) */
|
||||
// ARP packet
|
||||
uint16_t htype; // 0e hardware type (must be ARPHRD_ETHER)
|
||||
uint16_t ptype; // 10 protocol type (must be ETH_P_IP)
|
||||
uint8_t hlen; // 12 hardware address length (must be 6)
|
||||
uint8_t plen; // 13 protocol address length (must be 4)
|
||||
uint16_t operation; // 14 ARP opcode
|
||||
uint8_t smac[6]; // 16 sender's hardware address
|
||||
uint8_t sip4[4]; // 1c sender's IP address
|
||||
uint8_t dmac[6]; // 20 target's hardware address
|
||||
uint8_t dip4[4]; // 26 target's IP address
|
||||
uint8_t pad[18]; // 2a pad for min. ethernet payload (60 bytes)
|
||||
};
|
||||
|
||||
int arp_close_fd(struct client_state_t *cs);
|
||||
|
@ -43,8 +43,8 @@
|
||||
extern struct client_state_t cs;
|
||||
static char router_set;
|
||||
|
||||
/* Fill buf with the ifchd command text of option 'option'. */
|
||||
/* Returns 0 if successful, -1 if nothing was filled in. */
|
||||
// Fill buf with the ifchd command text of option 'option'.
|
||||
// Returns 0 if successful, -1 if nothing was filled in.
|
||||
static int ifchd_cmd(char *buf, size_t buflen, uint8_t *option, ssize_t optlen,
|
||||
uint8_t code)
|
||||
{
|
||||
|
@ -69,7 +69,6 @@ struct client_state_t cs = {
|
||||
};
|
||||
|
||||
struct client_config_t client_config = {
|
||||
/* Default options. */
|
||||
.interface = "eth0",
|
||||
.arp = "\0\0\0\0\0\0",
|
||||
};
|
||||
@ -200,7 +199,6 @@ int main(int argc, char **argv)
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
|
||||
/* get options */
|
||||
while (1) {
|
||||
int option_index = 0;
|
||||
c = getopt_long(argc, argv, "c:fbp:H:h:i:np:l:qr:u:C:vV:", arg_options,
|
||||
|
@ -84,12 +84,12 @@ static void sleep_if(struct client_state_t *cs)
|
||||
cs->timeout = -1;
|
||||
}
|
||||
|
||||
static int data_attr_cb(const struct nlattr *attr, void *data)
|
||||
static int nl_process_msgs_attr(const struct nlattr *attr, void *data)
|
||||
{
|
||||
const struct nlattr **tb = data;
|
||||
int type = mnl_attr_get_type(attr);
|
||||
|
||||
/* skip unsupported attribute in user-space */
|
||||
// skip unsupported attribute in user-space
|
||||
if (mnl_attr_type_valid(attr, IFLA_MAX) < 0)
|
||||
return MNL_CB_OK;
|
||||
switch (type) {
|
||||
@ -114,7 +114,7 @@ static void get_if_index_and_mac(const struct nlmsghdr *nlh,
|
||||
struct ifinfomsg *ifm,
|
||||
const struct nlattr **tb)
|
||||
{
|
||||
mnl_attr_parse(nlh, sizeof(*ifm), data_attr_cb, tb);
|
||||
mnl_attr_parse(nlh, sizeof *ifm, nl_process_msgs_attr, tb);
|
||||
if (!tb[IFLA_IFNAME])
|
||||
return;
|
||||
if (!strcmp(client_config.interface, mnl_attr_get_str(tb[IFLA_IFNAME]))) {
|
||||
@ -135,7 +135,7 @@ static void get_if_index_and_mac(const struct nlmsghdr *nlh,
|
||||
}
|
||||
}
|
||||
|
||||
static int data_cb(const struct nlmsghdr *nlh, void *data)
|
||||
static int nl_process_msgs(const struct nlmsghdr *nlh, void *data)
|
||||
{
|
||||
struct nlattr *tb[IFLA_MAX+1] = {0};
|
||||
struct ifinfomsg *ifm = mnl_nlmsg_get_payload(nlh);
|
||||
@ -204,7 +204,7 @@ void handle_nl_message(struct client_state_t *cs)
|
||||
assert(cs->nlFd != -1);
|
||||
do {
|
||||
ret = mnl_socket_recvfrom(mls, buf, sizeof buf);
|
||||
ret = mnl_cb_run(buf, ret, 0, 0, data_cb, cs);
|
||||
ret = mnl_cb_run(buf, ret, 0, 0, nl_process_msgs, cs);
|
||||
} while (ret > 0);
|
||||
if (ret == -1)
|
||||
log_line("nl callback function returned error: %s", strerror(errno));
|
||||
|
@ -22,50 +22,51 @@
|
||||
|
||||
#include "dhcp.h"
|
||||
|
||||
/* DHCP option codes (partial list) */
|
||||
#define DHCP_PADDING 0x00
|
||||
#define DHCP_SUBNET 0x01
|
||||
#define DHCP_TIME_OFFSET 0x02
|
||||
#define DHCP_ROUTER 0x03
|
||||
#define DHCP_TIME_SERVER 0x04
|
||||
#define DHCP_NAME_SERVER 0x05
|
||||
#define DHCP_DNS_SERVER 0x06
|
||||
#define DHCP_LOG_SERVER 0x07
|
||||
#define DHCP_COOKIE_SERVER 0x08
|
||||
#define DHCP_LPR_SERVER 0x09
|
||||
#define DHCP_HOST_NAME 0x0c
|
||||
#define DHCP_BOOT_SIZE 0x0d
|
||||
#define DHCP_DOMAIN_NAME 0x0f
|
||||
#define DHCP_SWAP_SERVER 0x10
|
||||
#define DHCP_ROOT_PATH 0x11
|
||||
#define DHCP_IP_TTL 0x17
|
||||
#define DHCP_MTU 0x1a
|
||||
#define DHCP_BROADCAST 0x1c
|
||||
#define DHCP_NIS_DOMAIN 0x28
|
||||
#define DHCP_NIS_SERVER 0x29
|
||||
#define DHCP_NTP_SERVER 0x2a
|
||||
#define DHCP_WINS_SERVER 0x2c
|
||||
#define DHCP_REQUESTED_IP 0x32
|
||||
#define DHCP_LEASE_TIME 0x33
|
||||
#define DHCP_OPTION_OVERLOAD 0x34
|
||||
#define DHCP_MESSAGE_TYPE 0x35
|
||||
#define DHCP_SERVER_ID 0x36
|
||||
#define DHCP_PARAM_REQ 0x37
|
||||
#define DHCP_MESSAGE 0x38
|
||||
#define DHCP_MAX_SIZE 0x39
|
||||
#define DHCP_T1 0x3a
|
||||
#define DHCP_T2 0x3b
|
||||
#define DHCP_VENDOR 0x3c
|
||||
#define DHCP_CLIENT_ID 0x3d
|
||||
#define DHCP_TFTP_SERVER_NAME 0x42
|
||||
#define DHCP_BOOT_FILE 0x43
|
||||
#define DHCP_USER_CLASS 0x4d
|
||||
#define DHCP_FQDN 0x51
|
||||
#define DHCP_DOMAIN_SEARCH 0x77
|
||||
#define DHCP_SIP_SERVERS 0x78
|
||||
#define DHCP_STATIC_ROUTES 0x79
|
||||
#define DHCP_WPAD 0xfc
|
||||
#define DHCP_END 0xff
|
||||
enum dhcp_codes {
|
||||
DHCP_PADDING = 0x00,
|
||||
DHCP_SUBNET = 0x01,
|
||||
DHCP_TIME_OFFSET = 0x02,
|
||||
DHCP_ROUTER = 0x03,
|
||||
DHCP_TIME_SERVER = 0x04,
|
||||
DHCP_NAME_SERVER = 0x05,
|
||||
DHCP_DNS_SERVER = 0x06,
|
||||
DHCP_LOG_SERVER = 0x07,
|
||||
DHCP_COOKIE_SERVER = 0x08,
|
||||
DHCP_LPR_SERVER = 0x09,
|
||||
DHCP_HOST_NAME = 0x0c,
|
||||
DHCP_BOOT_SIZE = 0x0d,
|
||||
DHCP_DOMAIN_NAME = 0x0f,
|
||||
DHCP_SWAP_SERVER = 0x10,
|
||||
DHCP_ROOT_PATH = 0x11,
|
||||
DHCP_IP_TTL = 0x17,
|
||||
DHCP_MTU = 0x1a,
|
||||
DHCP_BROADCAST = 0x1c,
|
||||
DHCP_NIS_DOMAIN = 0x28,
|
||||
DHCP_NIS_SERVER = 0x29,
|
||||
DHCP_NTP_SERVER = 0x2a,
|
||||
DHCP_WINS_SERVER = 0x2c,
|
||||
DHCP_REQUESTED_IP = 0x32,
|
||||
DHCP_LEASE_TIME = 0x33,
|
||||
DHCP_OPTION_OVERLOAD = 0x34,
|
||||
DHCP_MESSAGE_TYPE = 0x35,
|
||||
DHCP_SERVER_ID = 0x36,
|
||||
DHCP_PARAM_REQ = 0x37,
|
||||
DHCP_MESSAGE = 0x38,
|
||||
DHCP_MAX_SIZE = 0x39,
|
||||
DHCP_T1 = 0x3a,
|
||||
DHCP_T2 = 0x3b,
|
||||
DHCP_VENDOR = 0x3c,
|
||||
DHCP_CLIENT_ID = 0x3d,
|
||||
DHCP_TFTP_SERVER_NAME = 0x42,
|
||||
DHCP_BOOT_FILE = 0x43,
|
||||
DHCP_USER_CLASS = 0x4d,
|
||||
DHCP_FQDN = 0x51,
|
||||
DHCP_DOMAIN_SEARCH = 0x77,
|
||||
DHCP_SIP_SERVERS = 0x78,
|
||||
DHCP_STATIC_ROUTES = 0x79,
|
||||
DHCP_WPAD = 0xfc,
|
||||
DHCP_END = 0xff,
|
||||
};
|
||||
|
||||
enum option_type {
|
||||
OPTION_NONE = 0,
|
||||
|
@ -57,7 +57,7 @@ void background(struct client_state_t *cs)
|
||||
{
|
||||
static char called;
|
||||
if (!called) {
|
||||
called = 1; /* Do not fork again. */
|
||||
called = 1; // Do not fork again.
|
||||
if (daemon(0, 0) == -1) {
|
||||
perror("fork");
|
||||
exit(EXIT_SUCCESS);
|
||||
|
Loading…
Reference in New Issue
Block a user