diff options
author | Kenneth R Westerback <krw@cvs.openbsd.org> | 2015-04-15 12:40:58 +0000 |
---|---|---|
committer | Kenneth R Westerback <krw@cvs.openbsd.org> | 2015-04-15 12:40:58 +0000 |
commit | c2c4aa933629674a6e083b33e8c945484220ca0d (patch) | |
tree | f3fd8d40724b64fe96686072bb37eb9cedd6397b /usr.sbin | |
parent | 0aabb65c2e57f5a7a4cface15c93d7ae286df5c0 (diff) |
Avoid using inet_ntoa() twice in a single printf() parameter list
by caching the results from excess inet_ntoa() calls before doing
the printf(). Should improve usefullness (?) of DHCPRELEASE log
entries by actually printing ciaddr and giaddr correctly when
dhcprelays stand between servers and clients.
Looks good to dlg@.
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/dhcpd/dhcp.c | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/usr.sbin/dhcpd/dhcp.c b/usr.sbin/dhcpd/dhcp.c index 0500c7e4d46..9edcd55dda2 100644 --- a/usr.sbin/dhcpd/dhcp.c +++ b/usr.sbin/dhcpd/dhcp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dhcp.c,v 1.41 2014/11/11 19:59:47 krw Exp $ */ +/* $OpenBSD: dhcp.c,v 1.42 2015/04/15 12:40:57 krw Exp $ */ /* * Copyright (c) 1995, 1996, 1997, 1998, 1999 @@ -366,6 +366,7 @@ dhcprequest(struct packet *packet) void dhcprelease(struct packet *packet) { + char ciaddrbuf[INET_ADDRSTRLEN]; struct lease *lease; struct iaddr cip; int i; @@ -407,8 +408,11 @@ dhcprelease(struct packet *packet) lease = find_lease_by_ip_addr(cip); } + /* Can't do >1 inet_ntoa() in a printf()! */ + strlcpy(ciaddrbuf, inet_ntoa(packet->raw->ciaddr), sizeof(ciaddrbuf)); + note("DHCPRELEASE of %s from %s via %s (%sfound)", - inet_ntoa(packet->raw->ciaddr), + ciaddrbuf, print_hw_addr(packet->raw->htype, packet->raw->hlen, packet->raw->chaddr), packet->raw->giaddr.s_addr ? inet_ntoa(packet->raw->giaddr) : @@ -432,7 +436,7 @@ dhcprelease(struct packet *packet) */ if (!lease->releasing) { note("DHCPRELEASE of %s from %s via %s (found)", - inet_ntoa(packet->raw->ciaddr), + ciaddrbuf, print_hw_addr(packet->raw->htype, packet->raw->hlen, packet->raw->chaddr), packet->raw->giaddr.s_addr ? @@ -446,7 +450,7 @@ dhcprelease(struct packet *packet) } else { note("DHCPRELEASE of %s from %s via %s ignored " "(release already pending)", - inet_ntoa(packet->raw->ciaddr), + ciaddrbuf, print_hw_addr(packet->raw->htype, packet->raw->hlen, packet->raw->chaddr), packet->raw->giaddr.s_addr ? @@ -455,7 +459,7 @@ dhcprelease(struct packet *packet) } } else { note("DHCPRELEASE of %s from %s via %s for nonexistent lease", - inet_ntoa(packet->raw->ciaddr), + ciaddrbuf, print_hw_addr(packet->raw->htype, packet->raw->hlen, packet->raw->chaddr), packet->raw->giaddr.s_addr ? @@ -1213,6 +1217,7 @@ ack_lease(struct packet *packet, struct lease *lease, unsigned int offer, void dhcp_reply(struct lease *lease) { + char ciaddrbuf[INET_ADDRSTRLEN]; int bufs = 0, packet_length, i; struct dhcp_packet raw; struct sockaddr_in to; @@ -1305,10 +1310,13 @@ dhcp_reply(struct lease *lease) raw.hops = state->hops; raw.op = BOOTREPLY; + /* Can't do >1 inet_ntoa() in a printf()! */ + strlcpy(ciaddrbuf, inet_ntoa(state->ciaddr), sizeof(ciaddrbuf)); + /* Say what we're doing... */ if ((state->offer == DHCPACK) && (lease->flags & INFORM_NOLEASE)) note("DHCPACK to %s (%s) via %s", - inet_ntoa(state->ciaddr), + ciaddrbuf, print_hw_addr(lease->hardware_addr.htype, lease->hardware_addr.hlen, lease->hardware_addr.haddr), state->giaddr.s_addr ? inet_ntoa(state->giaddr) : |