Change parameters for add_option_request_list().
Make all unsigned char into uint8_t in options.[ch].
This commit is contained in:
parent
ddf9daf8e4
commit
5d7bcbb2d4
@ -127,7 +127,7 @@ int send_discover(uint32_t xid, uint32_t requested)
|
|||||||
/* Request a RFC-specified max size to work around buggy servers. */
|
/* Request a RFC-specified max size to work around buggy servers. */
|
||||||
add_u32_option(packet.options, DHCP_OPTIONS_BUFSIZE,
|
add_u32_option(packet.options, DHCP_OPTIONS_BUFSIZE,
|
||||||
DHCP_MAX_SIZE, htons(576));
|
DHCP_MAX_SIZE, htons(576));
|
||||||
add_option_request_list(&packet);
|
add_option_request_list(packet.options, DHCP_OPTIONS_BUFSIZE);
|
||||||
log_line("Sending discover...");
|
log_line("Sending discover...");
|
||||||
return bcast_raw_packet(&packet);
|
return bcast_raw_packet(&packet);
|
||||||
}
|
}
|
||||||
@ -145,7 +145,7 @@ int send_selecting(uint32_t xid, uint32_t server, uint32_t requested)
|
|||||||
requested);
|
requested);
|
||||||
add_u32_option(packet.options, DHCP_OPTIONS_BUFSIZE, DHCP_SERVER_ID, server);
|
add_u32_option(packet.options, DHCP_OPTIONS_BUFSIZE, DHCP_SERVER_ID, server);
|
||||||
|
|
||||||
add_option_request_list(&packet);
|
add_option_request_list(packet.options, DHCP_OPTIONS_BUFSIZE);
|
||||||
addr.s_addr = requested;
|
addr.s_addr = requested;
|
||||||
log_line("Sending select for %s...", inet_ntoa(addr));
|
log_line("Sending select for %s...", inet_ntoa(addr));
|
||||||
return bcast_raw_packet(&packet);
|
return bcast_raw_packet(&packet);
|
||||||
@ -160,7 +160,7 @@ int send_renew(uint32_t xid, uint32_t server, uint32_t ciaddr)
|
|||||||
packet.xid = xid;
|
packet.xid = xid;
|
||||||
packet.ciaddr = ciaddr;
|
packet.ciaddr = ciaddr;
|
||||||
|
|
||||||
add_option_request_list(&packet);
|
add_option_request_list(packet.options, DHCP_OPTIONS_BUFSIZE);
|
||||||
log_line("Sending renew...");
|
log_line("Sending renew...");
|
||||||
if (server)
|
if (server)
|
||||||
return kernel_packet(&packet, ciaddr, DHCP_CLIENT_PORT, server,
|
return kernel_packet(&packet, ciaddr, DHCP_CLIENT_PORT, server,
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* options.c - DHCP options handling
|
/* options.c - DHCP options handling
|
||||||
* Time-stamp: <2011-03-30 15:52:12 nk>
|
* Time-stamp: <2011-03-30 16:01:18 nk>
|
||||||
*
|
*
|
||||||
* (c) 2004-2011 Nicholas J. Kain <njkain at gmail dot com>
|
* (c) 2004-2011 Nicholas J. Kain <njkain at gmail dot com>
|
||||||
*
|
*
|
||||||
@ -23,14 +23,13 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "options.h"
|
#include "options.h"
|
||||||
|
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "malloc.h"
|
#include "malloc.h"
|
||||||
|
|
||||||
struct dhcp_option {
|
struct dhcp_option {
|
||||||
char name[10];
|
char name[10];
|
||||||
enum option_type type;
|
enum option_type type;
|
||||||
unsigned char code;
|
uint8_t code;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* supported options are easily added here */
|
/* supported options are easily added here */
|
||||||
@ -68,7 +67,7 @@ static struct dhcp_option options[] = {
|
|||||||
|
|
||||||
// List of options that will be sent on the parameter request list to the
|
// List of options that will be sent on the parameter request list to the
|
||||||
// remote DHCP server.
|
// remote DHCP server.
|
||||||
static unsigned char req_opts[] = {
|
static uint8_t req_opts[] = {
|
||||||
DHCP_SUBNET,
|
DHCP_SUBNET,
|
||||||
DHCP_ROUTER,
|
DHCP_ROUTER,
|
||||||
DHCP_DNS_SERVER,
|
DHCP_DNS_SERVER,
|
||||||
@ -78,7 +77,7 @@ static unsigned char req_opts[] = {
|
|||||||
0x00
|
0x00
|
||||||
};
|
};
|
||||||
|
|
||||||
static unsigned char list_opts[] = {
|
static uint8_t list_opts[] = {
|
||||||
DHCP_ROUTER,
|
DHCP_ROUTER,
|
||||||
DHCP_TIME_SERVER,
|
DHCP_TIME_SERVER,
|
||||||
DHCP_NAME_SERVER,
|
DHCP_NAME_SERVER,
|
||||||
@ -142,7 +141,7 @@ int option_valid_list(uint8_t code)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t sizeof_option(unsigned char code, size_t datalen)
|
size_t sizeof_option(uint8_t code, size_t datalen)
|
||||||
{
|
{
|
||||||
if (code == DHCP_PADDING || code == DHCP_END)
|
if (code == DHCP_PADDING || code == DHCP_END)
|
||||||
return 1;
|
return 1;
|
||||||
@ -150,8 +149,8 @@ size_t sizeof_option(unsigned char code, size_t datalen)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// optdata can be NULL
|
// optdata can be NULL
|
||||||
size_t set_option(unsigned char *buf, size_t buflen, unsigned char code,
|
size_t set_option(uint8_t *buf, size_t buflen, uint8_t code, uint8_t *optdata,
|
||||||
unsigned char *optdata, size_t datalen)
|
size_t datalen)
|
||||||
{
|
{
|
||||||
if (!optdata)
|
if (!optdata)
|
||||||
datalen = 0;
|
datalen = 0;
|
||||||
@ -170,10 +169,9 @@ size_t set_option(unsigned char *buf, size_t buflen, unsigned char code,
|
|||||||
return 2 + datalen;
|
return 2 + datalen;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char *alloc_option(unsigned char code, unsigned char *optdata,
|
uint8_t *alloc_option(uint8_t code, uint8_t *optdata, size_t datalen)
|
||||||
size_t datalen)
|
|
||||||
{
|
{
|
||||||
unsigned char *ret;
|
uint8_t *ret;
|
||||||
size_t len = sizeof_option(code, datalen);
|
size_t len = sizeof_option(code, datalen);
|
||||||
ret = xmalloc(len);
|
ret = xmalloc(len);
|
||||||
set_option(ret, len, code, optdata, datalen);
|
set_option(ret, len, code, optdata, datalen);
|
||||||
@ -183,10 +181,10 @@ unsigned char *alloc_option(unsigned char code, unsigned char *optdata,
|
|||||||
// This is tricky -- the data must be prefixed by one byte indicating the
|
// This is tricky -- the data must be prefixed by one byte indicating the
|
||||||
// type of ARP MAC address (1 for ethernet) or 0 for a purely symbolic
|
// type of ARP MAC address (1 for ethernet) or 0 for a purely symbolic
|
||||||
// identifier.
|
// identifier.
|
||||||
unsigned char *alloc_dhcp_client_id_option(unsigned char type,
|
uint8_t *alloc_dhcp_client_id_option(uint8_t type, uint8_t *idstr,
|
||||||
unsigned char *idstr, size_t idstrlen)
|
size_t idstrlen)
|
||||||
{
|
{
|
||||||
unsigned char data[idstrlen + 1];
|
uint8_t data[idstrlen + 1];
|
||||||
data[0] = type;
|
data[0] = type;
|
||||||
memcpy(data + 1, idstr, idstrlen);
|
memcpy(data + 1, idstr, idstrlen);
|
||||||
return alloc_option(DHCP_CLIENT_ID, data, sizeof data);
|
return alloc_option(DHCP_CLIENT_ID, data, sizeof data);
|
||||||
@ -339,7 +337,7 @@ size_t add_u32_option(uint8_t *optbuf, size_t buflen, uint8_t code,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Add a paramater request list for stubborn DHCP servers */
|
/* Add a paramater request list for stubborn DHCP servers */
|
||||||
void add_option_request_list(struct dhcpMessage *packet)
|
void add_option_request_list(uint8_t *optbuf, size_t buflen)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
uint8_t reqdata[sizeof req_opts + 1];
|
uint8_t reqdata[sizeof req_opts + 1];
|
||||||
@ -348,5 +346,5 @@ void add_option_request_list(struct dhcpMessage *packet)
|
|||||||
reqdata[1] = sizeof reqdata - 2;
|
reqdata[1] = sizeof reqdata - 2;
|
||||||
for (i = 0; req_opts[i]; i++)
|
for (i = 0; req_opts[i]; i++)
|
||||||
reqdata[i + 2] = req_opts[i];
|
reqdata[i + 2] = req_opts[i];
|
||||||
add_option_string(packet->options, DHCP_OPTIONS_BUFSIZE, reqdata);
|
add_option_string(optbuf, buflen, reqdata);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* options.h - DHCP options handling
|
/* options.h - DHCP options handling
|
||||||
* Time-stamp: <2011-03-30 15:50:30 nk>
|
* Time-stamp: <2011-03-30 16:01:26 nk>
|
||||||
*
|
*
|
||||||
* (c) 2004-2011 Nicholas J. Kain <njkain at gmail dot com>
|
* (c) 2004-2011 Nicholas J. Kain <njkain at gmail dot com>
|
||||||
*
|
*
|
||||||
@ -84,20 +84,19 @@ const char *option_name(uint8_t code);
|
|||||||
enum option_type option_type(uint8_t code);
|
enum option_type option_type(uint8_t code);
|
||||||
uint8_t option_length(uint8_t code);
|
uint8_t option_length(uint8_t code);
|
||||||
int option_valid_list(uint8_t code);
|
int option_valid_list(uint8_t code);
|
||||||
size_t sizeof_option(unsigned char code, size_t datalen);
|
size_t sizeof_option(uint8_t code, size_t datalen);
|
||||||
size_t set_option(unsigned char *buf, size_t buflen, unsigned char code,
|
size_t set_option(uint8_t *buf, size_t buflen, uint8_t code, uint8_t *optdata,
|
||||||
unsigned char *optdata, size_t datalen);
|
size_t datalen);
|
||||||
unsigned char *alloc_option(unsigned char code, unsigned char *optdata,
|
uint8_t *alloc_option(uint8_t code, uint8_t *optdata, size_t datalen);
|
||||||
size_t datalen);
|
|
||||||
|
|
||||||
unsigned char *alloc_dhcp_client_id_option(unsigned char type,
|
uint8_t *alloc_dhcp_client_id_option(uint8_t type, uint8_t *idstr,
|
||||||
unsigned char *idstr, size_t idstrlen);
|
size_t idstrlen);
|
||||||
|
|
||||||
uint8_t *get_option_data(struct dhcpMessage *packet, int code, ssize_t *optlen);
|
uint8_t *get_option_data(struct dhcpMessage *packet, int code, ssize_t *optlen);
|
||||||
ssize_t get_end_option_idx(uint8_t *optbuf, size_t bufsize);
|
ssize_t get_end_option_idx(uint8_t *optbuf, size_t bufsize);
|
||||||
size_t add_option_string(uint8_t *optbuf, size_t buflen, uint8_t *optstr);
|
size_t add_option_string(uint8_t *optbuf, size_t buflen, uint8_t *optstr);
|
||||||
size_t add_u32_option(uint8_t *optbuf, size_t buflen, uint8_t code,
|
size_t add_u32_option(uint8_t *optbuf, size_t buflen, uint8_t code,
|
||||||
uint32_t data);
|
uint32_t data);
|
||||||
void add_option_request_list(struct dhcpMessage *packet);
|
void add_option_request_list(uint8_t *optbuf, size_t buflen);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user