Changeset 3621 in MondoRescue for branches/3.3/mindi-busybox/networking/arping.c
- Timestamp:
- Dec 20, 2016, 4:07:32 PM (7 years ago)
- Location:
- branches/3.3
- Files:
-
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/3.3/mindi-busybox/networking/arping.c
r3232 r3621 14 14 //usage: "\n -q Quiet" 15 15 //usage: "\n -b Keep broadcasting, don't go unicast" 16 //usage: "\n -D Duplicated address detection mode"16 //usage: "\n -D Exit with 1 if DST_IP replies" 17 17 //usage: "\n -U Unsolicited ARP mode, update your neighbors" 18 18 //usage: "\n -A ARP answer mode, update your neighbors" 19 19 //usage: "\n -c N Stop after sending N ARP requests" 20 //usage: "\n -w TIMEOUT Time to wait for ARP reply, seconds"20 //usage: "\n -w TIMEOUT Seconds to wait for ARP reply" 21 21 //usage: "\n -I IFACE Interface to use (default eth0)" 22 22 //usage: "\n -s SRC_IP Sender IP address" … … 29 29 30 30 #include "libbb.h" 31 #include "common_bufsiz.h" 31 32 32 33 /* We don't expect to see 1000+ seconds delay, unsigned is enough */ … … 61 62 unsigned req_recv; 62 63 } FIX_ALIASING; 63 #define G (*(struct globals*) &bb_common_bufsiz1)64 #define G (*(struct globals*)bb_common_bufsiz1) 64 65 #define src (G.src ) 65 66 #define dst (G.dst ) … … 77 78 #define req_recv (G.req_recv ) 78 79 #define INIT_G() do { \ 80 setup_common_bufsiz(); \ 79 81 count = -1; \ 80 82 } while (0) … … 163 165 } 164 166 165 static boolrecv_pack(unsigned char *buf, int len, struct sockaddr_ll *FROM)167 static void recv_pack(unsigned char *buf, int len, struct sockaddr_ll *FROM) 166 168 { 167 169 struct arphdr *ah = (struct arphdr *) buf; … … 182 184 && FROM->sll_pkttype != PACKET_BROADCAST 183 185 && FROM->sll_pkttype != PACKET_MULTICAST) 184 return false;186 return; 185 187 186 188 /* Only these types are recognized */ 187 189 if (ah->ar_op != htons(ARPOP_REQUEST) && ah->ar_op != htons(ARPOP_REPLY)) 188 return false;190 return; 189 191 190 192 /* ARPHRD check and this darned FDDI hack here :-( */ 191 193 if (ah->ar_hrd != htons(FROM->sll_hatype) 192 194 && (FROM->sll_hatype != ARPHRD_FDDI || ah->ar_hrd != htons(ARPHRD_ETHER))) 193 return false;195 return; 194 196 195 197 /* Protocol must be IP. */ … … 198 200 || (ah->ar_hln != me.sll_halen) 199 201 || (len < (int)(sizeof(*ah) + 2 * (4 + ah->ar_hln)))) 200 return false;202 return; 201 203 202 204 move_from_unaligned32(src_ip.s_addr, p + ah->ar_hln); … … 204 206 205 207 if (dst.s_addr != src_ip.s_addr) 206 return false;208 return; 207 209 if (!(option_mask32 & DAD)) { 208 210 if ((src.s_addr != dst_ip.s_addr) 209 210 return false;211 || (memcmp(p + ah->ar_hln + 4, &me.sll_addr, ah->ar_hln))) 212 return; 211 213 } else { 212 214 /* DAD packet was: … … 225 227 if ((memcmp(p, &me.sll_addr, me.sll_halen) == 0) 226 228 || (src.s_addr && src.s_addr != dst_ip.s_addr)) 227 return false;229 return; 228 230 } 229 231 if (!(option_mask32 & QUIET)) { 230 232 int s_printed = 0; 231 233 232 printf("%scast re%s from %s [% s]",234 printf("%scast re%s from %s [%02x:%02x:%02x:%02x:%02x:%02x]", 233 235 FROM->sll_pkttype == PACKET_HOST ? "Uni" : "Broad", 234 236 ah->ar_op == htons(ARPOP_REPLY) ? "ply" : "quest", 235 237 inet_ntoa(src_ip), 236 ether_ntoa((struct ether_addr *) p)); 238 p[0], p[1], p[2], p[3], p[4], p[5] 239 ); 237 240 if (dst_ip.s_addr != src.s_addr) { 238 241 printf("for %s ", inet_ntoa(dst_ip)); … … 240 243 } 241 244 if (memcmp(p + ah->ar_hln + 4, me.sll_addr, ah->ar_hln)) { 245 unsigned char *pp = p + ah->ar_hln + 4; 242 246 if (!s_printed) 243 247 printf("for "); 244 printf("[%s]", 245 ether_ntoa((struct ether_addr *) p + ah->ar_hln + 4)); 248 printf("[%02x:%02x:%02x:%02x:%02x:%02x]", 249 pp[0], pp[1], pp[2], pp[3], pp[4], pp[5] 250 ); 246 251 } 247 252 … … 250 255 printf(" %u.%03ums\n", diff / 1000, diff % 1000); 251 256 } else { 252 p rintf(" UNSOLICITED?\n");257 puts(" UNSOLICITED?"); 253 258 } 254 259 fflush_all(); … … 265 270 option_mask32 |= UNICASTING; 266 271 } 267 return true;268 272 } 269 273 … … 285 289 //xsetuid(getuid()); 286 290 287 err_str = xasprintf("interface %s %%s", device);288 291 { 289 292 unsigned opt; … … 303 306 304 307 target = argv[optind]; 305 308 err_str = xasprintf("interface %s %%s", device); 306 309 xfunc_error_retval = 2; 307 310 … … 360 363 saddr.sin_addr = dst; 361 364 362 if (setsockopt (probe_fd, SOL_SOCKET, SO_DONTROUTE, &const_int_1, sizeof(const_int_1)) == -1)363 bb_perror_msg("setsockopt( SO_DONTROUTE)");365 if (setsockopt_SOL_SOCKET_1(probe_fd, SO_DONTROUTE) != 0) 366 bb_perror_msg("setsockopt(%s)", "SO_DONTROUTE"); 364 367 xconnect(probe_fd, (struct sockaddr *) &saddr, sizeof(saddr)); 365 368 getsockname(probe_fd, (struct sockaddr *) &saddr, &alen);
Note:
See TracChangeset
for help on using the changeset viewer.