static int retries = 3;
static float timeout = 5;
-static int server_port = 0;
+static uint16_t server_port = 0;
static int packet_code = 0;
static fr_ipaddr_t server_ipaddr;
static fr_ipaddr_t client_ipaddr;
-static int client_port = 0;
+static uint16_t client_port = 0;
static int sockfd;
char const *dhcpclient_version = "dhcpclient version " RADIUSD_VERSION_STRING
#ifdef RADIUSD_VERSION_COMMIT
-" (git #" RADIUSD_VERSION_COMMIT ")"
+" (git #" STRINGIFY(RADIUSD_VERSION_COMMIT) ")"
#endif
", built on " __DATE__ " at " __TIME__;
static int request_init(char const *filename)
{
FILE *fp;
+ vp_cursor_t cursor;
VALUE_PAIR *vp;
- int filedone = 0;
+ bool filedone = false;
/*
* Determine where to read the VP's from.
fp = fopen(filename, "r");
if (!fp) {
fprintf(stderr, "dhcpclient: Error opening %s: %s\n",
- filename, strerror(errno));
+ filename, fr_syserror(errno));
return 0;
}
} else {
fp = stdin;
}
- request = rad_alloc(NULL, 0);
+ request = rad_alloc(NULL, false);
/*
* Read the VP's.
*/
- request->vps = readvp2(NULL, fp, &filedone, "dhcpclient:");
- if (!request->vps) {
+ if (readvp2(&request->vps, NULL, fp, &filedone) < 0) {
+ fr_perror("dhcpclient");
rad_free(&request);
if (fp != stdin) fclose(fp);
return 1;
/*
* Fix / set various options
*/
- for (vp = request->vps; vp != NULL; vp = vp->next) {
+ for (vp = fr_cursor_init(&cursor, &request->vps); vp; vp = fr_cursor_next(&cursor)) {
switch (vp->da->attr) {
default:
break;
-
+
/*
* Allow it to set the packet type in
* the attributes read from the file.
case PW_PACKET_TYPE:
request->code = vp->vp_integer;
break;
-
+
case PW_PACKET_DST_PORT:
request->dst_port = (vp->vp_integer & 0xffff);
break;
-
+
case PW_PACKET_DST_IP_ADDRESS:
request->dst_ipaddr.af = AF_INET;
request->dst_ipaddr.ipaddr.ip4addr.s_addr = vp->vp_ipaddr;
break;
-
+
case PW_PACKET_DST_IPV6_ADDRESS:
request->dst_ipaddr.af = AF_INET6;
request->dst_ipaddr.ipaddr.ip6addr = vp->vp_ipv6addr;
break;
-
+
case PW_PACKET_SRC_PORT:
request->src_port = (vp->vp_integer & 0xffff);
break;
-
+
case PW_PACKET_SRC_IP_ADDRESS:
request->src_ipaddr.af = AF_INET;
request->src_ipaddr.ipaddr.ip4addr.s_addr = vp->vp_ipaddr;
break;
-
+
case PW_PACKET_SRC_IPV6_ADDRESS:
request->src_ipaddr.af = AF_INET6;
request->src_ipaddr.ipaddr.ip6addr = vp->vp_ipv6addr;
break;
} /* switch over the attribute */
-
+
} /* loop over the VP's we read in */
if (fp != stdin) fclose(fp);
static void print_hex(RADIUS_PACKET *packet)
{
int i, j;
- const uint8_t *p, *a;
+ uint8_t const *p, *a;
if (!packet->data) return;
printf("%s = 0x", dhcp_header_names[i]);
for (j = 0; j < dhcp_header_sizes[i]; j++) {
printf("%02x", p[j]);
-
+
}
printf("\n");
p += dhcp_header_sizes[i];
printf("%02x %02x ", p[0], p[1]);
a = p + 2;
-
+
for (i = 0; i < p[1]; i++) {
if ((i > 0) && ((i & 0x0f) == 0x00))
printf("\t\t");
printf("%02x ", a[i]);
if ((i & 0x0f) == 0x0f) printf("\n");
}
-
+
if ((p[1] & 0x0f) != 0x00) printf("\n");
-
+
p += p[1] + 2;
}
printf("\n----------------------------------------------------------------------\n");
portname = NULL;
}
- if (ip_hton(hostname, AF_INET, &server_ipaddr) < 0) {
- fprintf(stderr, "dhcpclient: Failed to find IP address for host %s: %s\n", hostname, strerror(errno));
+ if (ip_hton(&server_ipaddr, AF_INET, hostname, false) < 0) {
+ fprintf(stderr, "dhcpclient: Failed to find IP address for host %s: %s\n", hostname, fr_syserror(errno));
exit(1);
}
exit(1);
}
if (fr_debug_flag) print_hex(request);
-
+
if (fr_dhcp_send(request) < 0) {
fprintf(stderr, "dhcpclient: failed sending: %s\n",
- strerror(errno));
+ fr_syserror(errno));
exit(1);
}
reply = fr_dhcp_recv(sockfd);
if (!reply) {
- fprintf(stderr, "dhcpclient: no reply\n");
+ fprintf(stderr, "dhcpclient: Error receiving reply %s\n", fr_strerror());
exit(1);
}
if (fr_debug_flag) print_hex(reply);