diff options
author | Kenneth R Westerback <krw@cvs.openbsd.org> | 2013-12-05 21:33:00 +0000 |
---|---|---|
committer | Kenneth R Westerback <krw@cvs.openbsd.org> | 2013-12-05 21:33:00 +0000 |
commit | 11269fdc5369d1c0fcad17d16f7eaeeb955a8c83 (patch) | |
tree | 478707877c3fe4c1be96a3c2928b13928aefa485 /sbin/dhclient | |
parent | f9acee5cd09c67c4bf3945cd89ac9b613b9178a5 (diff) |
Use destination size as size of memcpy(). Use <in_addr> rather than
<in_addr>.s_addr to shorten code.
ok deraadt@ matthew@ as part of larger diff
Diffstat (limited to 'sbin/dhclient')
-rw-r--r-- | sbin/dhclient/dhclient.c | 36 | ||||
-rw-r--r-- | sbin/dhclient/dispatch.c | 8 | ||||
-rw-r--r-- | sbin/dhclient/kroute.c | 9 | ||||
-rw-r--r-- | sbin/dhclient/packet.c | 4 |
4 files changed, 28 insertions, 29 deletions
diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c index b503756ee74..a32c173087c 100644 --- a/sbin/dhclient/dhclient.c +++ b/sbin/dhclient/dhclient.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dhclient.c,v 1.272 2013/12/04 22:14:33 matthew Exp $ */ +/* $OpenBSD: dhclient.c,v 1.273 2013/12/05 21:32:59 krw Exp $ */ /* * Copyright 2004 Henning Brauer <henning@openbsd.org> @@ -862,9 +862,8 @@ bind_lease(void) flush_routes(ifi->name, ifi->rdomain); memset(&mask, 0, sizeof(mask)); - if (options[DHO_SUBNET_MASK].len == sizeof(mask.s_addr)) { - memcpy(&mask.s_addr, options[DHO_SUBNET_MASK].data, - sizeof(mask.s_addr)); + if (options[DHO_SUBNET_MASK].len == sizeof(mask)) { + memcpy(&mask, options[DHO_SUBNET_MASK].data, sizeof(mask)); } /* @@ -876,11 +875,11 @@ bind_lease(void) add_classless_static_routes(ifi->rdomain, &options[DHO_CLASSLESS_STATIC_ROUTES]); } else { - if (options[DHO_ROUTERS].len >= sizeof(gateway.s_addr)) { + if (options[DHO_ROUTERS].len >= sizeof(gateway)) { memset(&gateway, 0, sizeof(gateway)); /* XXX Only use FIRST router address for now. */ - memcpy(&gateway.s_addr, options[DHO_ROUTERS].data, - sizeof(gateway.s_addr)); + memcpy(&gateway, options[DHO_ROUTERS].data, + sizeof(gateway)); /* * If we were given a /32 IP assignment, then make sure @@ -942,10 +941,11 @@ state_bound(void) client->xid = arc4random(); make_request(client->active); - if (client->active->options[DHO_DHCP_SERVER_IDENTIFIER].len == 4) { - memcpy(&client->destination.s_addr, + if (client->active->options[DHO_DHCP_SERVER_IDENTIFIER].len == + sizeof(client->destination)) { + memcpy(&client->destination, client->active->options[DHO_DHCP_SERVER_IDENTIFIER].data, - sizeof(client->destination.s_addr)); + sizeof(client->destination)); } else client->destination.s_addr = INADDR_BROADCAST; @@ -1082,12 +1082,11 @@ packet_to_lease(struct in_addr client_addr, struct option_data *options) } } - memcpy(&lease->address.s_addr, &client->packet.yiaddr, - sizeof(in_addr_t)); + memcpy(&lease->address, &client->packet.yiaddr, sizeof(lease->address)); /* Save the siaddr (a.k.a. next-server) info. */ - memcpy(&lease->next_server.s_addr, &client->packet.siaddr, - sizeof(in_addr_t)); + memcpy(&lease->next_server, &client->packet.siaddr, + sizeof(lease->next_server)); /* If the server name was filled out, copy it. */ if ((!lease->options[DHO_DHCP_OPTION_OVERLOAD].len || @@ -2442,10 +2441,10 @@ add_static_routes(int rdomain, struct option_data *static_routes) memset(&dest, 0, sizeof(dest)); memset(&gateway, 0, sizeof(gateway)); - memcpy(&dest.s_addr, addr, 4); + memcpy(&dest, addr, sizeof(dest)); if (dest.s_addr == INADDR_ANY) continue; /* RFC 2132 says 0.0.0.0 is not allowed. */ - memcpy(&gateway.s_addr, addr+4, 4); + memcpy(&gateway, addr+sizeof(dest), sizeof(gateway)); /* XXX Order implies priority but we're ignoring that. */ add_route(rdomain, dest, netmask, gateway, @@ -2478,8 +2477,9 @@ void add_classless_static_routes(int rdomain, i += bytes; memset(&gateway, 0, sizeof(gateway)); - memcpy(&gateway, &classless_static_routes->data[i], 4); - i += 4; + memcpy(&gateway, &classless_static_routes->data[i], + sizeof(gateway)); + i += sizeof(gateway); if (gateway.s_addr == INADDR_ANY) continue; /* OBSD TCP/IP doesn't support this. */ diff --git a/sbin/dhclient/dispatch.c b/sbin/dhclient/dispatch.c index 2516301d0bb..30db8aa984f 100644 --- a/sbin/dhclient/dispatch.c +++ b/sbin/dhclient/dispatch.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dispatch.c,v 1.84 2013/12/04 19:39:50 krw Exp $ */ +/* $OpenBSD: dispatch.c,v 1.85 2013/12/05 21:32:59 krw Exp $ */ /* * Copyright 2004 Henning Brauer <henning@openbsd.org> @@ -403,9 +403,9 @@ subnet_exists(struct client_lease *l) int myrdomain, hisrdomain; memset(&mymask, 0, sizeof(mymask)); - if (l->options[DHO_SUBNET_MASK].len == sizeof(mymask.s_addr)) { - memcpy(&mymask.s_addr, l->options[DHO_SUBNET_MASK].data, - sizeof(mymask.s_addr)); + if (l->options[DHO_SUBNET_MASK].len == sizeof(mymask)) { + memcpy(&mymask, l->options[DHO_SUBNET_MASK].data, + sizeof(mymask)); } myaddr.s_addr = l->address.s_addr; mynet.s_addr = mymask.s_addr & myaddr.s_addr; diff --git a/sbin/dhclient/kroute.c b/sbin/dhclient/kroute.c index 1451ce57cb6..c4ade92fb50 100644 --- a/sbin/dhclient/kroute.c +++ b/sbin/dhclient/kroute.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kroute.c,v 1.57 2013/12/04 19:39:50 krw Exp $ */ +/* $OpenBSD: kroute.c,v 1.58 2013/12/05 21:32:59 krw Exp $ */ /* * Copyright 2012 Kenneth R Westerback <krw@openbsd.org> @@ -301,9 +301,8 @@ delete_addresses(char *ifname, int rdomain) continue; memset(&addr, 0, sizeof(addr)); - memcpy(&addr, - &((struct sockaddr_in *)ifa->ifa_addr)->sin_addr, - sizeof(in_addr_t)); + memcpy(&addr, &((struct sockaddr_in *)ifa->ifa_addr)->sin_addr, + sizeof(addr)); delete_address(ifi->name, ifi->rdomain, addr); } @@ -441,7 +440,7 @@ priv_add_address(struct imsg_add_address *imsg) in = (struct sockaddr_in *)&ifaliasreq.ifra_mask; in->sin_family = AF_INET; in->sin_len = sizeof(ifaliasreq.ifra_mask); - memcpy(&in->sin_addr.s_addr, &imsg->mask, sizeof(in->sin_addr.s_addr)); + memcpy(&in->sin_addr, &imsg->mask, sizeof(in->sin_addr)); /* No need to set broadcast address. Kernel can figure it out. */ diff --git a/sbin/dhclient/packet.c b/sbin/dhclient/packet.c index b793ea9cc91..f6e94bca489 100644 --- a/sbin/dhclient/packet.c +++ b/sbin/dhclient/packet.c @@ -1,4 +1,4 @@ -/* $OpenBSD: packet.c,v 1.20 2013/12/05 21:03:40 krw Exp $ */ +/* $OpenBSD: packet.c,v 1.21 2013/12/05 21:32:59 krw Exp $ */ /* Packet assembly code, originally contributed by Archie Cobbs. */ @@ -241,7 +241,7 @@ decode_udp_ip_header(unsigned char *buf, int bufix, struct sockaddr_in *from, return (-1); } - memcpy(&from->sin_port, &udp->uh_sport, sizeof(from->sin_port)); + memcpy(&from->sin_port, &udp->uh_sport, sizeof(udp->uh_sport)); return (ip_len + sizeof(*udp)); } |