blob: 278f2dc9a3b04d7fda86beeedd244ab1000d05f5 [file] [log] [blame]
Denis Vlasenko88e2b1c2007-01-07 19:35:11 +00001/* vi: set sw=4 ts=4: */
2/*
3 * arp.c - Manipulate the system ARP cache
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version
8 * 2 of the License, or (at your option) any later version.
9 *
10 * Author: Fred N. van Kempen, <waltje at uwalt.nl.mugnet.org>
11 * Busybox port: Paul van Gool <pvangool at mimotech.com>
12 *
13 * modified for getopt32 by Arne Bernin <arne [at] alamut.de>
14 */
15
Denis Vlasenkob6adbf12007-05-26 19:00:18 +000016#include "libbb.h"
Denis Vlasenko88e2b1c2007-01-07 19:35:11 +000017#include "inet_common.h"
18
19#include <arpa/inet.h>
20#include <net/if.h>
21#include <net/if_arp.h>
22#include <netinet/ether.h>
23#include <netpacket/packet.h>
24
25#define DEBUG 0
26
27#define DFLT_AF "inet"
28#define DFLT_HW "ether"
29
Denis Vlasenko4d476922008-11-13 00:05:17 +000030enum {
31 ARP_OPT_A = (1 << 0),
32 ARP_OPT_p = (1 << 1),
33 ARP_OPT_H = (1 << 2),
34 ARP_OPT_t = (1 << 3),
35 ARP_OPT_i = (1 << 4),
36 ARP_OPT_a = (1 << 5),
37 ARP_OPT_d = (1 << 6),
38 ARP_OPT_n = (1 << 7), /* do not resolve addresses */
39 ARP_OPT_D = (1 << 8), /* HW-address is devicename */
40 ARP_OPT_s = (1 << 9),
41 ARP_OPT_v = (1 << 10) * DEBUG, /* debugging output flag */
42};
Denis Vlasenko88e2b1c2007-01-07 19:35:11 +000043
Denis Vlasenko4d476922008-11-13 00:05:17 +000044enum {
45 sockfd = 3, /* active socket descriptor */
46};
Denis Vlasenko88e2b1c2007-01-07 19:35:11 +000047
Denis Vlasenko4d476922008-11-13 00:05:17 +000048struct globals {
49 const struct aftype *ap; /* current address family */
50 const struct hwtype *hw; /* current hardware type */
51 const char *device; /* current device */
52 smallint hw_set; /* flag if hw-type was set (-H) */
53
54};
55#define G (*(struct globals*)&bb_common_bufsiz1)
56#define ap (G.ap )
57#define hw (G.hw )
58#define device (G.device )
59#define hw_set (G.hw_set )
60#define INIT_G() do { \
61 device = ""; \
62} while (0)
63
Denis Vlasenko88e2b1c2007-01-07 19:35:11 +000064
Denis Vlasenko6ca409e2007-08-12 20:58:27 +000065static const char options[] ALIGN1 =
Denis Vlasenko990d0f62007-07-24 15:54:42 +000066 "pub\0"
67 "priv\0"
68 "temp\0"
69 "trail\0"
70 "dontpub\0"
71 "auto\0"
72 "dev\0"
73 "netmask\0";
Denis Vlasenko88e2b1c2007-01-07 19:35:11 +000074
75/* Delete an entry from the ARP cache. */
76/* Called only from main, once */
77static int arp_del(char **args)
78{
Denis Vlasenko7f2527e2007-03-14 22:11:20 +000079 char *host;
Denis Vlasenko88e2b1c2007-01-07 19:35:11 +000080 struct arpreq req;
81 struct sockaddr sa;
82 int flags = 0;
83 int err;
84
85 memset(&req, 0, sizeof(req));
86
87 /* Resolve the host name. */
Denis Vlasenko7f2527e2007-03-14 22:11:20 +000088 host = *args;
89 if (ap->input(host, &sa) < 0) {
Denis Vlasenko88e2b1c2007-01-07 19:35:11 +000090 bb_herror_msg_and_die("%s", host);
91 }
92
93 /* If a host has more than one address, use the correct one! */
94 memcpy(&req.arp_pa, &sa, sizeof(struct sockaddr));
95
96 if (hw_set)
97 req.arp_ha.sa_family = hw->type;
98
99 req.arp_flags = ATF_PERM;
100 args++;
101 while (*args != NULL) {
Denis Vlasenko990d0f62007-07-24 15:54:42 +0000102 switch (index_in_strings(options, *args)) {
Bernhard Reutner-Fischer42646c52007-01-07 22:12:35 +0000103 case 0: /* "pub" */
Denis Vlasenko88e2b1c2007-01-07 19:35:11 +0000104 flags |= 1;
105 args++;
106 break;
Bernhard Reutner-Fischer42646c52007-01-07 22:12:35 +0000107 case 1: /* "priv" */
Denis Vlasenko88e2b1c2007-01-07 19:35:11 +0000108 flags |= 2;
109 args++;
110 break;
Bernhard Reutner-Fischer42646c52007-01-07 22:12:35 +0000111 case 2: /* "temp" */
Denis Vlasenko88e2b1c2007-01-07 19:35:11 +0000112 req.arp_flags &= ~ATF_PERM;
113 args++;
114 break;
Bernhard Reutner-Fischer42646c52007-01-07 22:12:35 +0000115 case 3: /* "trail" */
Denis Vlasenko88e2b1c2007-01-07 19:35:11 +0000116 req.arp_flags |= ATF_USETRAILERS;
117 args++;
118 break;
Bernhard Reutner-Fischer42646c52007-01-07 22:12:35 +0000119 case 4: /* "dontpub" */
Denis Vlasenko88e2b1c2007-01-07 19:35:11 +0000120#ifdef HAVE_ATF_DONTPUB
121 req.arp_flags |= ATF_DONTPUB;
122#else
123 bb_error_msg("feature ATF_DONTPUB is not supported");
124#endif
125 args++;
126 break;
Bernhard Reutner-Fischer42646c52007-01-07 22:12:35 +0000127 case 5: /* "auto" */
Denis Vlasenko88e2b1c2007-01-07 19:35:11 +0000128#ifdef HAVE_ATF_MAGIC
129 req.arp_flags |= ATF_MAGIC;
130#else
131 bb_error_msg("feature ATF_MAGIC is not supported");
132#endif
133 args++;
134 break;
Bernhard Reutner-Fischer42646c52007-01-07 22:12:35 +0000135 case 6: /* "dev" */
Denis Vlasenko88e2b1c2007-01-07 19:35:11 +0000136 if (*++args == NULL)
137 bb_show_usage();
138 device = *args;
139 args++;
140 break;
Bernhard Reutner-Fischer42646c52007-01-07 22:12:35 +0000141 case 7: /* "netmask" */
Denis Vlasenko88e2b1c2007-01-07 19:35:11 +0000142 if (*++args == NULL)
143 bb_show_usage();
144 if (strcmp(*args, "255.255.255.255") != 0) {
Denis Vlasenko7f2527e2007-03-14 22:11:20 +0000145 host = *args;
146 if (ap->input(host, &sa) < 0) {
Bernhard Reutner-Fischer42646c52007-01-07 22:12:35 +0000147 bb_herror_msg_and_die("%s", host);
Denis Vlasenko88e2b1c2007-01-07 19:35:11 +0000148 }
149 memcpy(&req.arp_netmask, &sa, sizeof(struct sockaddr));
150 req.arp_flags |= ATF_NETMASK;
151 }
152 args++;
153 break;
154 default:
155 bb_show_usage();
156 break;
157 }
158 }
159 if (flags == 0)
160 flags = 3;
161
162 strncpy(req.arp_dev, device, sizeof(req.arp_dev));
163
164 err = -1;
165
166 /* Call the kernel. */
167 if (flags & 2) {
168 if (option_mask32 & ARP_OPT_v)
169 bb_error_msg("SIOCDARP(nopub)");
170 err = ioctl(sockfd, SIOCDARP, &req);
171 if (err < 0) {
172 if (errno == ENXIO) {
173 if (flags & 1)
174 goto nopub;
175 printf("No ARP entry for %s\n", host);
176 return -1;
177 }
178 bb_perror_msg_and_die("SIOCDARP(priv)");
179 }
180 }
181 if ((flags & 1) && err) {
182 nopub:
183 req.arp_flags |= ATF_PUBL;
184 if (option_mask32 & ARP_OPT_v)
185 bb_error_msg("SIOCDARP(pub)");
186 if (ioctl(sockfd, SIOCDARP, &req) < 0) {
187 if (errno == ENXIO) {
188 printf("No ARP entry for %s\n", host);
189 return -1;
190 }
191 bb_perror_msg_and_die("SIOCDARP(pub)");
192 }
193 }
194 return 0;
195}
196
197/* Get the hardware address to a specified interface name */
Bernhard Reutner-Fischer42646c52007-01-07 22:12:35 +0000198static void arp_getdevhw(char *ifname, struct sockaddr *sa,
199 const struct hwtype *hwt)
Denis Vlasenko88e2b1c2007-01-07 19:35:11 +0000200{
201 struct ifreq ifr;
202 const struct hwtype *xhw;
203
204 strcpy(ifr.ifr_name, ifname);
Denis Vlasenkofb79a2e2007-07-14 22:07:14 +0000205 ioctl_or_perror_and_die(sockfd, SIOCGIFHWADDR, &ifr,
206 "cant get HW-Address for '%s'", ifname);
Denis Vlasenko88e2b1c2007-01-07 19:35:11 +0000207 if (hwt && (ifr.ifr_hwaddr.sa_family != hw->type)) {
208 bb_error_msg_and_die("protocol type mismatch");
209 }
210 memcpy(sa, &(ifr.ifr_hwaddr), sizeof(struct sockaddr));
211
212 if (option_mask32 & ARP_OPT_v) {
213 xhw = get_hwntype(ifr.ifr_hwaddr.sa_family);
214 if (!xhw || !xhw->print) {
215 xhw = get_hwntype(-1);
216 }
217 bb_error_msg("device '%s' has HW address %s '%s'",
218 ifname, xhw->name,
Denis Vlasenko023dc672008-05-09 18:07:15 +0000219 xhw->print((unsigned char *) &ifr.ifr_hwaddr.sa_data));
Denis Vlasenko88e2b1c2007-01-07 19:35:11 +0000220 }
221}
222
223/* Set an entry in the ARP cache. */
224/* Called only from main, once */
225static int arp_set(char **args)
226{
Denis Vlasenko7f2527e2007-03-14 22:11:20 +0000227 char *host;
Denis Vlasenko88e2b1c2007-01-07 19:35:11 +0000228 struct arpreq req;
229 struct sockaddr sa;
230 int flags;
Bernhard Reutner-Fischer42646c52007-01-07 22:12:35 +0000231
Denis Vlasenko88e2b1c2007-01-07 19:35:11 +0000232 memset(&req, 0, sizeof(req));
233
Denis Vlasenko7f2527e2007-03-14 22:11:20 +0000234 host = *args++;
235 if (ap->input(host, &sa) < 0) {
Denis Vlasenko88e2b1c2007-01-07 19:35:11 +0000236 bb_herror_msg_and_die("%s", host);
237 }
238 /* If a host has more than one address, use the correct one! */
239 memcpy(&req.arp_pa, &sa, sizeof(struct sockaddr));
240
241 /* Fetch the hardware address. */
242 if (*args == NULL) {
243 bb_error_msg_and_die("need hardware address");
244 }
245 if (option_mask32 & ARP_OPT_D) {
246 arp_getdevhw(*args++, &req.arp_ha, hw_set ? hw : NULL);
247 } else {
248 if (hw->input(*args++, &req.arp_ha) < 0) {
249 bb_error_msg_and_die("invalid hardware address");
250 }
251 }
252
253 /* Check out any modifiers. */
254 flags = ATF_PERM | ATF_COM;
255 while (*args != NULL) {
Denis Vlasenko990d0f62007-07-24 15:54:42 +0000256 switch (index_in_strings(options, *args)) {
Bernhard Reutner-Fischer42646c52007-01-07 22:12:35 +0000257 case 0: /* "pub" */
Denis Vlasenko88e2b1c2007-01-07 19:35:11 +0000258 flags |= ATF_PUBL;
259 args++;
260 break;
Bernhard Reutner-Fischer42646c52007-01-07 22:12:35 +0000261 case 1: /* "priv" */
Denis Vlasenko88e2b1c2007-01-07 19:35:11 +0000262 flags &= ~ATF_PUBL;
263 args++;
264 break;
Bernhard Reutner-Fischer42646c52007-01-07 22:12:35 +0000265 case 2: /* "temp" */
Denis Vlasenko88e2b1c2007-01-07 19:35:11 +0000266 flags &= ~ATF_PERM;
267 args++;
268 break;
Bernhard Reutner-Fischer42646c52007-01-07 22:12:35 +0000269 case 3: /* "trail" */
Denis Vlasenko88e2b1c2007-01-07 19:35:11 +0000270 flags |= ATF_USETRAILERS;
271 args++;
272 break;
Bernhard Reutner-Fischer42646c52007-01-07 22:12:35 +0000273 case 4: /* "dontpub" */
Denis Vlasenko88e2b1c2007-01-07 19:35:11 +0000274#ifdef HAVE_ATF_DONTPUB
275 flags |= ATF_DONTPUB;
276#else
277 bb_error_msg("feature ATF_DONTPUB is not supported");
278#endif
279 args++;
280 break;
Bernhard Reutner-Fischer42646c52007-01-07 22:12:35 +0000281 case 5: /* "auto" */
Denis Vlasenko88e2b1c2007-01-07 19:35:11 +0000282#ifdef HAVE_ATF_MAGIC
283 flags |= ATF_MAGIC;
284#else
285 bb_error_msg("feature ATF_MAGIC is not supported");
286#endif
287 args++;
288 break;
Bernhard Reutner-Fischer42646c52007-01-07 22:12:35 +0000289 case 6: /* "dev" */
Denis Vlasenko88e2b1c2007-01-07 19:35:11 +0000290 if (*++args == NULL)
291 bb_show_usage();
292 device = *args;
293 args++;
294 break;
Bernhard Reutner-Fischer42646c52007-01-07 22:12:35 +0000295 case 7: /* "netmask" */
Denis Vlasenko88e2b1c2007-01-07 19:35:11 +0000296 if (*++args == NULL)
297 bb_show_usage();
298 if (strcmp(*args, "255.255.255.255") != 0) {
Denis Vlasenko7f2527e2007-03-14 22:11:20 +0000299 host = *args;
300 if (ap->input(host, &sa) < 0) {
Denis Vlasenko88e2b1c2007-01-07 19:35:11 +0000301 bb_herror_msg_and_die("%s", host);
302 }
303 memcpy(&req.arp_netmask, &sa, sizeof(struct sockaddr));
304 flags |= ATF_NETMASK;
305 }
306 args++;
307 break;
308 default:
309 bb_show_usage();
310 break;
311 }
312 }
313
314 /* Fill in the remainder of the request. */
315 req.arp_flags = flags;
316
317 strncpy(req.arp_dev, device, sizeof(req.arp_dev));
318
319 /* Call the kernel. */
320 if (option_mask32 & ARP_OPT_v)
321 bb_error_msg("SIOCSARP()");
Denis Vlasenkofb79a2e2007-07-14 22:07:14 +0000322 xioctl(sockfd, SIOCSARP, &req);
Denis Vlasenko88e2b1c2007-01-07 19:35:11 +0000323 return 0;
324}
325
326
327/* Print the contents of an ARP request block. */
328static void
Denis Vlasenkoab2aea42007-01-29 22:51:58 +0000329arp_disp(const char *name, char *ip, int type, int arp_flags,
Denis Vlasenko88e2b1c2007-01-07 19:35:11 +0000330 char *hwa, char *mask, char *dev)
331{
Denis Vlasenko53354ac2008-06-07 15:10:29 +0000332 static const int arp_masks[] = {
Denis Vlasenkof45c4f42008-06-16 04:09:25 +0000333 ATF_PERM, ATF_PUBL,
Denis Vlasenko53354ac2008-06-07 15:10:29 +0000334#ifdef HAVE_ATF_MAGIC
335 ATF_MAGIC,
336#endif
337#ifdef HAVE_ATF_DONTPUB
338 ATF_DONTPUB,
339#endif
340 ATF_USETRAILERS,
341 };
342 static const char arp_labels[] ALIGN1 = "PERM\0""PUP\0"
343#ifdef HAVE_ATF_MAGIC
344 "AUTO\0"
345#endif
346#ifdef HAVE_ATF_DONTPUB
347 "DONTPUB\0"
348#endif
349 "TRAIL\0"
350 ;
351
Denis Vlasenko88e2b1c2007-01-07 19:35:11 +0000352 const struct hwtype *xhw;
353
354 xhw = get_hwntype(type);
355 if (xhw == NULL)
356 xhw = get_hwtype(DFLT_HW);
357
358 printf("%s (%s) at ", name, ip);
359
360 if (!(arp_flags & ATF_COM)) {
361 if (arp_flags & ATF_PUBL)
362 printf("* ");
363 else
364 printf("<incomplete> ");
365 } else {
366 printf("%s [%s] ", hwa, xhw->name);
367 }
368
369 if (arp_flags & ATF_NETMASK)
370 printf("netmask %s ", mask);
371
Denis Vlasenko53354ac2008-06-07 15:10:29 +0000372 print_flags_separated(arp_masks, arp_labels, arp_flags, " ");
373 printf(" on %s\n", dev);
Denis Vlasenko88e2b1c2007-01-07 19:35:11 +0000374}
375
376/* Display the contents of the ARP cache in the kernel. */
377/* Called only from main, once */
378static int arp_show(char *name)
379{
Denis Vlasenko7f2527e2007-03-14 22:11:20 +0000380 const char *host;
Denis Vlasenkoab2aea42007-01-29 22:51:58 +0000381 const char *hostname;
Denis Vlasenko7f2527e2007-03-14 22:11:20 +0000382 FILE *fp;
383 struct sockaddr sa;
384 int type, flags;
Bernhard Reutner-Fischer42646c52007-01-07 22:12:35 +0000385 int num;
386 unsigned entries = 0, shown = 0;
Denis Vlasenko7f2527e2007-03-14 22:11:20 +0000387 char ip[128];
388 char hwa[128];
389 char mask[128];
390 char line[128];
391 char dev[128];
Denis Vlasenko88e2b1c2007-01-07 19:35:11 +0000392
Denis Vlasenko7f2527e2007-03-14 22:11:20 +0000393 host = NULL;
Denis Vlasenko88e2b1c2007-01-07 19:35:11 +0000394 if (name != NULL) {
395 /* Resolve the host name. */
Denis Vlasenko7f2527e2007-03-14 22:11:20 +0000396 if (ap->input(name, &sa) < 0) {
397 bb_herror_msg_and_die("%s", name);
Denis Vlasenko88e2b1c2007-01-07 19:35:11 +0000398 }
Denis Vlasenko7f2527e2007-03-14 22:11:20 +0000399 host = xstrdup(ap->sprint(&sa, 1));
Denis Vlasenko88e2b1c2007-01-07 19:35:11 +0000400 }
Denis Vlasenko5415c852008-07-21 23:05:26 +0000401 fp = xfopen_for_read("/proc/net/arp");
Denis Vlasenko7f2527e2007-03-14 22:11:20 +0000402 /* Bypass header -- read one line */
403 fgets(line, sizeof(line), fp);
404
405 /* Read the ARP cache entries. */
406 while (fgets(line, sizeof(line), fp)) {
407
Denis Vlasenko88e2b1c2007-01-07 19:35:11 +0000408 mask[0] = '-'; mask[1] = '\0';
409 dev[0] = '-'; dev[1] = '\0';
Denis Vlasenko7f2527e2007-03-14 22:11:20 +0000410 /* All these strings can't overflow
411 * because fgets above reads limited amount of data */
412 num = sscanf(line, "%s 0x%x 0x%x %s %s %s\n",
413 ip, &type, &flags, hwa, mask, dev);
414 if (num < 4)
415 break;
Denis Vlasenko88e2b1c2007-01-07 19:35:11 +0000416
Denis Vlasenko7f2527e2007-03-14 22:11:20 +0000417 entries++;
418 /* if the user specified hw-type differs, skip it */
419 if (hw_set && (type != hw->type))
420 continue;
Denis Vlasenko88e2b1c2007-01-07 19:35:11 +0000421
Denis Vlasenko7f2527e2007-03-14 22:11:20 +0000422 /* if the user specified address differs, skip it */
423 if (host && strcmp(ip, host) != 0)
424 continue;
Denis Vlasenko88e2b1c2007-01-07 19:35:11 +0000425
Denis Vlasenko7f2527e2007-03-14 22:11:20 +0000426 /* if the user specified device differs, skip it */
427 if (device[0] && strcmp(dev, device) != 0)
428 continue;
Denis Vlasenko88e2b1c2007-01-07 19:35:11 +0000429
Denis Vlasenko7f2527e2007-03-14 22:11:20 +0000430 shown++;
431 /* This IS ugly but it works -be */
432 hostname = "?";
433 if (!(option_mask32 & ARP_OPT_n)) {
434 if (ap->input(ip, &sa) < 0)
435 hostname = ip;
436 else
437 hostname = ap->sprint(&sa, (option_mask32 & ARP_OPT_n) | 0x8000);
438 if (strcmp(hostname, ip) == 0)
Denis Vlasenko88e2b1c2007-01-07 19:35:11 +0000439 hostname = "?";
Denis Vlasenko88e2b1c2007-01-07 19:35:11 +0000440 }
Denis Vlasenko7f2527e2007-03-14 22:11:20 +0000441
442 arp_disp(hostname, ip, type, flags, hwa, mask, dev);
Denis Vlasenko88e2b1c2007-01-07 19:35:11 +0000443 }
444 if (option_mask32 & ARP_OPT_v)
445 printf("Entries: %d\tSkipped: %d\tFound: %d\n",
446 entries, entries - shown, shown);
447
448 if (!shown) {
Denis Vlasenko7f2527e2007-03-14 22:11:20 +0000449 if (hw_set || host || device[0])
Denis Vlasenko88e2b1c2007-01-07 19:35:11 +0000450 printf("No match found in %d entries\n", entries);
451 }
Denis Vlasenko7f2527e2007-03-14 22:11:20 +0000452 if (ENABLE_FEATURE_CLEAN_UP) {
453 free((char*)host);
454 fclose(fp);
455 }
Denis Vlasenko88e2b1c2007-01-07 19:35:11 +0000456 return 0;
457}
458
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +0000459int arp_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Denis Vlasenkoa60f84e2008-07-05 09:18:54 +0000460int arp_main(int argc UNUSED_PARAM, char **argv)
Denis Vlasenko88e2b1c2007-01-07 19:35:11 +0000461{
Denis Vlasenkoec7e7ae2008-08-15 20:14:23 +0000462 const char *hw_type = "ether";
463 const char *protocol;
Denis Vlasenko4d476922008-11-13 00:05:17 +0000464 unsigned opts;
Denis Vlasenko88e2b1c2007-01-07 19:35:11 +0000465
Denis Vlasenko4d476922008-11-13 00:05:17 +0000466 INIT_G();
467
468 xmove_fd(xsocket(AF_INET, SOCK_DGRAM, 0), sockfd);
Denis Vlasenko88e2b1c2007-01-07 19:35:11 +0000469 ap = get_aftype(DFLT_AF);
470 if (!ap)
471 bb_error_msg_and_die("%s: %s not supported", DFLT_AF, "address family");
472
Denis Vlasenko4d476922008-11-13 00:05:17 +0000473 opts = getopt32(argv, "A:p:H:t:i:adnDsv", &protocol, &protocol,
Denis Vlasenko88e2b1c2007-01-07 19:35:11 +0000474 &hw_type, &hw_type, &device);
475 argv += optind;
Denis Vlasenko4d476922008-11-13 00:05:17 +0000476 if (opts & (ARP_OPT_A | ARP_OPT_p)) {
Denis Vlasenko88e2b1c2007-01-07 19:35:11 +0000477 ap = get_aftype(protocol);
478 if (ap == NULL)
479 bb_error_msg_and_die("%s: unknown %s", protocol, "address family");
480 }
Denis Vlasenko4d476922008-11-13 00:05:17 +0000481 if (opts & (ARP_OPT_A | ARP_OPT_p)) {
Denis Vlasenko88e2b1c2007-01-07 19:35:11 +0000482 hw = get_hwtype(hw_type);
483 if (hw == NULL)
484 bb_error_msg_and_die("%s: unknown %s", hw_type, "hardware type");
485 hw_set = 1;
486 }
Denis Vlasenko4d476922008-11-13 00:05:17 +0000487 //if (opts & ARP_OPT_i)... -i
Denis Vlasenko88e2b1c2007-01-07 19:35:11 +0000488
489 if (ap->af != AF_INET) {
490 bb_error_msg_and_die("%s: kernel only supports 'inet'", ap->name);
491 }
492
493 /* If no hw type specified get default */
494 if (!hw) {
495 hw = get_hwtype(DFLT_HW);
496 if (!hw)
497 bb_error_msg_and_die("%s: %s not supported", DFLT_HW, "hardware type");
498 }
499
500 if (hw->alen <= 0) {
501 bb_error_msg_and_die("%s: %s without ARP support",
502 hw->name, "hardware type");
503 }
Denis Vlasenko88e2b1c2007-01-07 19:35:11 +0000504
505 /* Now see what we have to do here... */
Denis Vlasenko4d476922008-11-13 00:05:17 +0000506 if (opts & (ARP_OPT_d | ARP_OPT_s)) {
Denis Vlasenko88e2b1c2007-01-07 19:35:11 +0000507 if (argv[0] == NULL)
508 bb_error_msg_and_die("need host name");
Denis Vlasenko4d476922008-11-13 00:05:17 +0000509 if (opts & ARP_OPT_s)
Denis Vlasenko88e2b1c2007-01-07 19:35:11 +0000510 return arp_set(argv);
511 return arp_del(argv);
512 }
Denis Vlasenko4d476922008-11-13 00:05:17 +0000513 //if (opts & ARP_OPT_a) - default
Denis Vlasenko88e2b1c2007-01-07 19:35:11 +0000514 return arp_show(argv[0]);
515}