From efb545b9bdd3934dcdbf9bc0890a42081b330049 Mon Sep 17 00:00:00 2001 From: Denis Vlasenko Date: Mon, 8 Dec 2008 22:56:18 +0000 Subject: optimize 16- and 32-bit moves function old new delta udhcpd_main 1239 1257 +18 udhcp_add_simple_option 93 92 -1 buffer_read_le_u32 19 18 -1 unpack_gz_stream_with_info 526 520 -6 dnsd_main 1470 1463 -7 udhcp_run_script 1208 1186 -22 send_ACK 255 229 -26 arping_main 1661 1623 -38 send_offer 470 428 -42 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/8 up/down: 18/-143) Total: -125 bytes --- networking/arping.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'networking/arping.c') diff --git a/networking/arping.c b/networking/arping.c index e4429973b..e7b842f5b 100644 --- a/networking/arping.c +++ b/networking/arping.c @@ -153,6 +153,15 @@ static bool recv_pack(unsigned char *buf, int len, struct sockaddr_ll *FROM) struct arphdr *ah = (struct arphdr *) buf; unsigned char *p = (unsigned char *) (ah + 1); struct in_addr src_ip, dst_ip; + /* moves below assume in_addr is 4 bytes big, ensure that */ + struct BUG_in_addr_must_be_4 { + char BUG_in_addr_must_be_4[ + sizeof(struct in_addr) == 4 ? 1 : -1 + ]; + char BUG_s_addr_must_be_4[ + sizeof(src_ip.s_addr) == 4 ? 1 : -1 + ]; + }; /* Filter out wild packets */ if (FROM->sll_pkttype != PACKET_HOST @@ -171,13 +180,13 @@ static bool recv_pack(unsigned char *buf, int len, struct sockaddr_ll *FROM) /* Protocol must be IP. */ if (ah->ar_pro != htons(ETH_P_IP) - || (ah->ar_pln != 4) - || (ah->ar_hln != me.sll_halen) - || (len < (int)(sizeof(*ah) + 2 * (4 + ah->ar_hln)))) + || (ah->ar_pln != 4) + || (ah->ar_hln != me.sll_halen) + || (len < (int)(sizeof(*ah) + 2 * (4 + ah->ar_hln)))) return false; - memcpy(&src_ip, p + ah->ar_hln, 4); - memcpy(&dst_ip, p + ah->ar_hln + 4 + ah->ar_hln, 4); + move_from_unaligned32(src_ip.s_addr, p + ah->ar_hln); + move_from_unaligned32(dst_ip.s_addr, p + ah->ar_hln + 4 + ah->ar_hln); if (dst.s_addr != src_ip.s_addr) return false; @@ -200,7 +209,7 @@ static bool recv_pack(unsigned char *buf, int len, struct sockaddr_ll *FROM) dst_ip/dst_hw do not matter. */ if ((memcmp(p, &me.sll_addr, me.sll_halen) == 0) - || (src.s_addr && src.s_addr != dst_ip.s_addr)) + || (src.s_addr && src.s_addr != dst_ip.s_addr)) return false; } if (!(option_mask32 & QUIET)) { @@ -306,7 +315,7 @@ int arping_main(int argc UNUSED_PARAM, char **argv) /* if (!inet_aton(target, &dst)) - not needed */ { len_and_sockaddr *lsa; lsa = xhost_and_af2sockaddr(target, 0, AF_INET); - memcpy(&dst, &lsa->u.sin.sin_addr.s_addr, 4); + dst = lsa->u.sin.sin_addr; if (ENABLE_FEATURE_CLEAN_UP) free(lsa); } -- cgit v1.2.3