8
8
* NET-3 Networking Distribution for the LINUX operating
11
* Version: $Id: arp.c,v 1.25 2005/12/04 02:57:15 ecki Exp $
11
* Version: $Id: arp.c,v 1.20 2001/04/08 17:05:05 pb Exp $
13
13
* Maintainer: Bernd 'eckes' Eckenfels, <net-tools@lina.inka.de>
115
114
safe_strncpy(host, *args, (sizeof host));
116
sa = (struct sockaddr *)&ss;
117
if (ap->input(0, host, sa) < 0) {
115
if (ap->input(0, host, &sa) < 0) {
118
116
ap->herror(host);
121
119
/* If a host has more than one address, use the correct one! */
122
memcpy((char *) &req.arp_pa, (char *) sa, sizeof(struct sockaddr));
120
memcpy((char *) &req.arp_pa, (char *) &sa, sizeof(struct sockaddr));
125
123
req.arp_ha.sa_family = hw->type;
180
178
if (strcmp(*args, "255.255.255.255") != 0) {
181
179
strcpy(host, *args);
182
if (ap->input(0, host, sa) < 0) {
180
if (ap->input(0, host, &sa) < 0) {
183
181
ap->herror(host);
186
memcpy((char *) &req.arp_netmask, (char *) sa,
184
memcpy((char *) &req.arp_netmask, (char *) &sa,
187
185
sizeof(struct sockaddr));
188
186
req.arp_flags |= ATF_NETMASK;
196
// if neighter priv nor pub is given, work on both
200
196
strcpy(req.arp_dev, device);
202
/* unfortuatelly the kernel interface does not allow us to
203
delete private entries anlone, so we need this hack
204
to avoid "not found" errors if we try both. */
207
200
/* Call the kernel. */
210
fprintf(stderr, "arp: SIOCDARP(dontpub)\n");
211
if (ioctl(sockfd, SIOCDARP, &req) < 0) {
212
if ((errno == ENXIO) || (errno == ENOENT)) {
203
fprintf(stderr, "arp: SIOCDARP(nopub)\n");
204
if ((err = ioctl(sockfd, SIOCDARP, &req) < 0)) {
205
if (errno == ENXIO) {
215
208
printf(_("No ARP entry for %s\n"), host);
218
perror("SIOCDARP(dontpub)");
211
perror("SIOCDARP(priv)");
223
if (!deleted && (flags & 1)) {
215
if ((flags & 1) && (err)) {
225
217
req.arp_flags |= ATF_PUBL;
227
219
fprintf(stderr, "arp: SIOCDARP(pub)\n");
228
220
if (ioctl(sockfd, SIOCDARP, &req) < 0) {
229
if ((errno == ENXIO) || (errno == ENOENT)) {
221
if (errno == ENXIO) {
230
222
printf(_("No ARP entry for %s\n"), host);
282
273
safe_strncpy(host, *args++, (sizeof host));
283
sa = (struct sockaddr *)&ss;
284
if (ap->input(0, host, sa) < 0) {
274
if (ap->input(0, host, &sa) < 0) {
285
275
ap->herror(host);
288
278
/* If a host has more than one address, use the correct one! */
289
memcpy((char *) &req.arp_pa, (char *) sa, sizeof(struct sockaddr));
279
memcpy((char *) &req.arp_pa, (char *) &sa, sizeof(struct sockaddr));
291
281
/* Fetch the hardware address. */
292
282
if (*args == NULL) {
357
347
if (strcmp(*args, "255.255.255.255") != 0) {
358
348
strcpy(host, *args);
359
if (ap->input(0, host, sa) < 0) {
349
if (ap->input(0, host, &sa) < 0) {
360
350
ap->herror(host);
363
memcpy((char *) &req.arp_netmask, (char *) sa,
353
memcpy((char *) &req.arp_netmask, (char *) &sa,
364
354
sizeof(struct sockaddr));
365
355
flags |= ATF_NETMASK;
474
464
if (!(arp_flags & ATF_COM)) {
475
465
if (arp_flags & ATF_PUBL)
476
printf("%-8.8s%-20.20s", "*", _("<from_interface>"));
466
printf("%-8.8s%-20.20s", "*", "*");
478
468
printf("%-8.8s%-20.20s", "", _("(incomplete)"));
546
sa = (struct sockaddr *)&ss;
547
535
if (name != NULL) {
548
536
/* Resolve the host name. */
549
537
safe_strncpy(host, name, (sizeof host));
550
if (ap->input(0, host, sa) < 0) {
538
if (ap->input(0, host, &sa) < 0) {
551
539
ap->herror(host);
554
safe_strncpy(host, ap->sprint(sa, 1), sizeof(host));
542
safe_strncpy(host, ap->sprint(&sa, 1), sizeof(host));
556
544
/* Open the PROCps kernel table. */
557
545
if ((fp = fopen(_PATH_PROCNET_ARP, "r")) == NULL) {
590
if (ap->input(0, ip, sa) < 0)
578
if (ap->input(0, ip, &sa) < 0)
593
hostname = ap->sprint(sa, opt_n | 0x8000);
581
hostname = ap->sprint(&sa, opt_n | 0x8000);
594
582
if (strcmp(hostname, ip) == 0)
624
612
static void usage(void)
626
614
fprintf(stderr, _("Usage:\n arp [-vn] [<HW>] [-i <if>] [-a] [<hostname>] <-Display ARP cache\n"));
627
fprintf(stderr, _(" arp [-v] [-i <if>] -d <host> [pub] <-Delete ARP entry\n"));
628
fprintf(stderr, _(" arp [-vnD] [<HW>] [-i <if>] -f [<filename>] <-Add entry from file\n"));
629
fprintf(stderr, _(" arp [-v] [<HW>] [-i <if>] -s <host> <hwaddr> [temp] <-Add entry\n"));
630
fprintf(stderr, _(" arp [-v] [<HW>] [-i <if>] -Ds <host> <if> [netmask <nm>] pub <-''-\n\n"));
615
fprintf(stderr, _(" arp [-v] [-i <if>] -d <hostname> [pub][nopub] <-Delete ARP entry\n"));
616
fprintf(stderr, _(" arp [-vnD] [<HW>] [-i <if>] -f [<filename>] <-Add entry from file\n"));
617
fprintf(stderr, _(" arp [-v] [<HW>] [-i <if>] -s <hostname> <hwaddr> [temp][nopub] <-Add entry\n"));
618
fprintf(stderr, _(" arp [-v] [<HW>] [-i <if>] -s <hostname> <hwaddr> [netmask <nm>] pub <-''-\n"));
619
fprintf(stderr, _(" arp [-v] [<HW>] [-i <if>] -Ds <hostname> <if> [netmask <nm>] pub <-''-\n\n"));
632
621
fprintf(stderr, _(" -a display (all) hosts in alternative (BSD) style\n"));
633
622
fprintf(stderr, _(" -s, --set set a new ARP entry\n"));