summaryrefslogtreecommitdiff
path: root/sbin/dhclient/options.c
diff options
context:
space:
mode:
authorKenneth R Westerback <krw@cvs.openbsd.org>2013-01-16 06:11:22 +0000
committerKenneth R Westerback <krw@cvs.openbsd.org>2013-01-16 06:11:22 +0000
commitda18f078821e2fdd3eacb02db868ceef525067b7 (patch)
tree84df5be3f2073d195880edc5e3f14dfdf1ac6586 /sbin/dhclient/options.c
parent9b76b1376b56f95d1418109213f81c0649acee53 (diff)
Use the magic of asprintf() to produce more informative error
and log messages.
Diffstat (limited to 'sbin/dhclient/options.c')
-rw-r--r--sbin/dhclient/options.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/sbin/dhclient/options.c b/sbin/dhclient/options.c
index 205312b0ae5..ca0fa0542d4 100644
--- a/sbin/dhclient/options.c
+++ b/sbin/dhclient/options.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: options.c,v 1.47 2013/01/13 22:50:33 krw Exp $ */
+/* $OpenBSD: options.c,v 1.48 2013/01/16 06:11:21 krw Exp $ */
/* DHCP options parsing and reassembly. */
@@ -463,9 +463,9 @@ do_packet(int len, unsigned int from_port, struct in_addr from,
struct dhcp_packet *packet = &client->packet;
struct option_data options[256];
struct reject_elem *ap;
- void (*handler)(struct in_addr, struct option_data *);
- char *type;
- int i, options_valid = 1;
+ void (*handler)(struct in_addr, struct option_data *, char *);
+ char *type, *info;
+ int i, rslt, options_valid = 1;
if (packet->hlen > sizeof(packet->chaddr)) {
note("Discarding packet with invalid hlen.");
@@ -531,21 +531,27 @@ do_packet(int len, unsigned int from_port, struct in_addr from,
if (handler && client->xid == client->packet.xid) {
if (hfrom->hlen == 6)
- note("%s from %s (%s)", type, inet_ntoa(from),
+ rslt = asprintf(&info, "%s from %s (%s)", type,
+ inet_ntoa(from),
ether_ntoa((struct ether_addr *)hfrom->haddr));
else
- note("%s from %s", type, inet_ntoa(from));
+ rslt = asprintf(&info, "%s from %s", type,
+ inet_ntoa(from));
+ if (rslt == -1)
+ error("no memory for info string");
} else
handler = NULL;
for (ap = config->reject_list; ap && handler; ap = ap->next)
if (from.s_addr == ap->addr.s_addr) {
- note("%s from %s rejected.", type, inet_ntoa(from));
+ note("Rejected %s.", info);
handler = NULL;
}
if (handler)
- (*handler)(from, options);
+ (*handler)(from, options, info);
+
+ free(info);
for (i = 0; i < 256; i++)
if (options[i].len && options[i].data)