aboutsummaryrefslogtreecommitdiff
path: root/networking/arping.c
diff options
context:
space:
mode:
Diffstat (limited to 'networking/arping.c')
-rw-r--r--networking/arping.c23
1 files changed, 16 insertions, 7 deletions
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)
153 struct arphdr *ah = (struct arphdr *) buf; 153 struct arphdr *ah = (struct arphdr *) buf;
154 unsigned char *p = (unsigned char *) (ah + 1); 154 unsigned char *p = (unsigned char *) (ah + 1);
155 struct in_addr src_ip, dst_ip; 155 struct in_addr src_ip, dst_ip;
156 /* moves below assume in_addr is 4 bytes big, ensure that */
157 struct BUG_in_addr_must_be_4 {
158 char BUG_in_addr_must_be_4[
159 sizeof(struct in_addr) == 4 ? 1 : -1
160 ];
161 char BUG_s_addr_must_be_4[
162 sizeof(src_ip.s_addr) == 4 ? 1 : -1
163 ];
164 };
156 165
157 /* Filter out wild packets */ 166 /* Filter out wild packets */
158 if (FROM->sll_pkttype != PACKET_HOST 167 if (FROM->sll_pkttype != PACKET_HOST
@@ -171,13 +180,13 @@ static bool recv_pack(unsigned char *buf, int len, struct sockaddr_ll *FROM)
171 180
172 /* Protocol must be IP. */ 181 /* Protocol must be IP. */
173 if (ah->ar_pro != htons(ETH_P_IP) 182 if (ah->ar_pro != htons(ETH_P_IP)
174 || (ah->ar_pln != 4) 183 || (ah->ar_pln != 4)
175 || (ah->ar_hln != me.sll_halen) 184 || (ah->ar_hln != me.sll_halen)
176 || (len < (int)(sizeof(*ah) + 2 * (4 + ah->ar_hln)))) 185 || (len < (int)(sizeof(*ah) + 2 * (4 + ah->ar_hln))))
177 return false; 186 return false;
178 187
179 memcpy(&src_ip, p + ah->ar_hln, 4); 188 move_from_unaligned32(src_ip.s_addr, p + ah->ar_hln);
180 memcpy(&dst_ip, p + ah->ar_hln + 4 + ah->ar_hln, 4); 189 move_from_unaligned32(dst_ip.s_addr, p + ah->ar_hln + 4 + ah->ar_hln);
181 190
182 if (dst.s_addr != src_ip.s_addr) 191 if (dst.s_addr != src_ip.s_addr)
183 return false; 192 return false;
@@ -200,7 +209,7 @@ static bool recv_pack(unsigned char *buf, int len, struct sockaddr_ll *FROM)
200 dst_ip/dst_hw do not matter. 209 dst_ip/dst_hw do not matter.
201 */ 210 */
202 if ((memcmp(p, &me.sll_addr, me.sll_halen) == 0) 211 if ((memcmp(p, &me.sll_addr, me.sll_halen) == 0)
203 || (src.s_addr && src.s_addr != dst_ip.s_addr)) 212 || (src.s_addr && src.s_addr != dst_ip.s_addr))
204 return false; 213 return false;
205 } 214 }
206 if (!(option_mask32 & QUIET)) { 215 if (!(option_mask32 & QUIET)) {
@@ -306,7 +315,7 @@ int arping_main(int argc UNUSED_PARAM, char **argv)
306 /* if (!inet_aton(target, &dst)) - not needed */ { 315 /* if (!inet_aton(target, &dst)) - not needed */ {
307 len_and_sockaddr *lsa; 316 len_and_sockaddr *lsa;
308 lsa = xhost_and_af2sockaddr(target, 0, AF_INET); 317 lsa = xhost_and_af2sockaddr(target, 0, AF_INET);
309 memcpy(&dst, &lsa->u.sin.sin_addr.s_addr, 4); 318 dst = lsa->u.sin.sin_addr;
310 if (ENABLE_FEATURE_CLEAN_UP) 319 if (ENABLE_FEATURE_CLEAN_UP)
311 free(lsa); 320 free(lsa);
312 } 321 }