test-dhcp-option.c revision 9116b40692cf973eca74731860bfaa58daeb9543
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
#include <stdio.h>
#include <stdbool.h>
#include <errno.h>
#include <string.h>
#include "util.h"
#include "macro.h"
#include "dhcp-protocol.h"
#include "dhcp-internal.h"
struct option_desc {
int snamelen;
int filelen;
int len;
bool success;
int filepos;
int snamepos;
int pos;
};
static bool verbose = false;
static struct option_desc option_tests[] = {
{ {}, 0, {}, 0, { 42, 5, 65, 66, 67, 68, 69 }, 7, false, },
{ {}, 0, {}, 0, { 42, 5, 65, 66, 67, 68, 69, 0, 0,
{ {}, 0, {}, 0, { 8, 255, 70, 71, 72 }, 5, false, },
{ {}, 0, {}, 0, { 0x35, 0x01, 0x05, 0x36, 0x04, 0x01, 0x00, 0xa8,
0xc0, 0x33, 0x04, 0x00, 0x01, 0x51, 0x80, 0x01,
0x04, 0xff, 0xff, 0xff, 0x00, 0x03, 0x04, 0xc0,
0xa8, 0x00, 0x01, 0x06, 0x04, 0xc0, 0xa8, 0x00,
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, },
40, true, },
42, 3, 0, 0, 0 }, 8, true, },
{ {}, 0, {}, 0, { 42, 2, 1, 2, 44 }, 5, false, },
{ {}, 0,
{ 222, 3, 1, 2, 3 }, 5,
{ DHCP_OPTION_OVERLOAD, 1,
};
switch(type) {
case DHCP_DISCOVER:
return "DHCPDISCOVER";
case DHCP_OFFER:
return "DHCPOFFER";
case DHCP_REQUEST:
return "DHCPREQUEST";
case DHCP_DECLINE:
return "DHCPDECLINE";
case DHCP_ACK:
return "DHCPACK";
case DHCP_NAK:
return "DHCPNAK";
case DHCP_RELEASE:
return "DHCPRELEASE";
default:
return "unknown";
}
}
static void test_invalid_buffer_length(void) {
== -EINVAL);
}
static void test_message_init(void) {
}
return message;
}
switch(descoption[*descpos]) {
case DHCP_OPTION_PAD:
*descpos += 1;
break;
case DHCP_OPTION_MESSAGE_TYPE:
case DHCP_OPTION_OVERLOAD:
*descpos += 3;
break;
default:
return;
}
}
}
uint8_t i;
if (!desc)
return -EINVAL;
}
if (*desclen)
break;
*descpos = -1;
}
if (verbose)
for (i = 0; i < len; i++) {
if (verbose)
}
if (verbose)
printf("\n");
return 0;
}
int optlen = 0;
int filelen = 0;
int snamelen = 0;
int buflen = 0;
int res;
if (desc) {
if (!filelen)
if (!snamelen)
}
if (!desc) {
desc)) >= 0);
} else
desc)) < 0);
if (verbose)
}
'A', 'B', 'C', 'D',
160, 2, 0x11, 0x12,
0,
31, 8, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38,
0,
55, 3, 0x51, 0x52, 0x53,
17, 7, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
255
};
static void test_option_set(void) {
unsigned i;
offset = 4;
0, NULL) >= 0);
len = 11;
pos++;
else
}
for (i = 0; i < 9; i++) {
if (verbose)
options[i]);
}
if (verbose)
if (verbose)
for (i = 0; i < pos - 8; i++) {
if (verbose)
options[i + 9]);
}
if (verbose)
printf ("\n");
}
unsigned i;
for (i = 0; i < ELEMENTSOF(option_tests); i++)
test_options(&option_tests[i]);
return 0;
}