Deleted Added
full compact
arp.c (177362) arp.c (186119)
1/*
2 * Copyright (c) 1984, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Sun Microsystems, Inc.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 28 unchanged lines hidden (view full) ---

37 The Regents of the University of California. All rights reserved.\n";
38#endif /* not lint */
39
40#ifndef lint
41static char const sccsid[] = "@(#)from: arp.c 8.2 (Berkeley) 1/2/94";
42#endif /* not lint */
43#endif
44#include <sys/cdefs.h>
1/*
2 * Copyright (c) 1984, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Sun Microsystems, Inc.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 28 unchanged lines hidden (view full) ---

37 The Regents of the University of California. All rights reserved.\n";
38#endif /* not lint */
39
40#ifndef lint
41static char const sccsid[] = "@(#)from: arp.c 8.2 (Berkeley) 1/2/94";
42#endif /* not lint */
43#endif
44#include <sys/cdefs.h>
45__FBSDID("$FreeBSD: head/usr.sbin/arp/arp.c 177362 2008-03-18 21:45:27Z sam $");
45__FBSDID("$FreeBSD: head/usr.sbin/arp/arp.c 186119 2008-12-15 06:10:57Z qingli $");
46
47/*
48 * arp - display, set, and delete arp table entries
49 */
50
51
52#include <sys/param.h>
53#include <sys/file.h>

--- 311 unchanged lines hidden (view full) ---

365 warn("%s", host);
366 return (1);
367 }
368 addr = (struct sockaddr_inarp *)(rtm + 1);
369 sdl = (struct sockaddr_dl *)(SA_SIZE(addr) + (char *)addr);
370 if (addr->sin_addr.s_addr != dst->sin_addr.s_addr)
371 break;
372 if (sdl->sdl_family == AF_LINK &&
46
47/*
48 * arp - display, set, and delete arp table entries
49 */
50
51
52#include <sys/param.h>
53#include <sys/file.h>

--- 311 unchanged lines hidden (view full) ---

365 warn("%s", host);
366 return (1);
367 }
368 addr = (struct sockaddr_inarp *)(rtm + 1);
369 sdl = (struct sockaddr_dl *)(SA_SIZE(addr) + (char *)addr);
370 if (addr->sin_addr.s_addr != dst->sin_addr.s_addr)
371 break;
372 if (sdl->sdl_family == AF_LINK &&
373 (rtm->rtm_flags & RTF_LLINFO) &&
374 !(rtm->rtm_flags & RTF_GATEWAY) &&
375 valid_type(sdl->sdl_type) )
376 break;
377 if (doing_proxy == 0) {
378 printf("set: can only proxy for %s\n", host);
379 return (1);
380 }
381 if (dst->sin_other & SIN_PROXY) {

--- 39 unchanged lines hidden (view full) ---

421 * Delete an arp entry
422 */
423static int
424delete(char *host, int do_proxy)
425{
426 struct sockaddr_inarp *addr, *dst;
427 struct rt_msghdr *rtm;
428 struct sockaddr_dl *sdl;
373 !(rtm->rtm_flags & RTF_GATEWAY) &&
374 valid_type(sdl->sdl_type) )
375 break;
376 if (doing_proxy == 0) {
377 printf("set: can only proxy for %s\n", host);
378 return (1);
379 }
380 if (dst->sin_other & SIN_PROXY) {

--- 39 unchanged lines hidden (view full) ---

420 * Delete an arp entry
421 */
422static int
423delete(char *host, int do_proxy)
424{
425 struct sockaddr_inarp *addr, *dst;
426 struct rt_msghdr *rtm;
427 struct sockaddr_dl *sdl;
428 struct sockaddr_dl sdl_m;
429
430 dst = getaddr(host);
431 if (dst == NULL)
432 return (1);
433 dst->sin_other = do_proxy;
429
430 dst = getaddr(host);
431 if (dst == NULL)
432 return (1);
433 dst->sin_other = do_proxy;
434
435 /*
436 * setup the data structure to notify the kernel
437 * it is the ARP entry the RTM_GET is interested
438 * in
439 */
440 bzero(&sdl_m, sizeof(sdl_m));
441 sdl_m.sdl_len = sizeof(sdl_m);
442 sdl_m.sdl_family = AF_LINK;
443
434 for (;;) { /* try twice */
444 for (;;) { /* try twice */
435 rtm = rtmsg(RTM_GET, dst, NULL);
445 rtm = rtmsg(RTM_GET, dst, &sdl_m);
436 if (rtm == NULL) {
437 warn("%s", host);
438 return (1);
439 }
440 addr = (struct sockaddr_inarp *)(rtm + 1);
441 sdl = (struct sockaddr_dl *)(SA_SIZE(addr) + (char *)addr);
446 if (rtm == NULL) {
447 warn("%s", host);
448 return (1);
449 }
450 addr = (struct sockaddr_inarp *)(rtm + 1);
451 sdl = (struct sockaddr_dl *)(SA_SIZE(addr) + (char *)addr);
442 if (addr->sin_addr.s_addr == dst->sin_addr.s_addr &&
443 sdl->sdl_family == AF_LINK &&
444 (rtm->rtm_flags & RTF_LLINFO) &&
452
453 /*
454 * With the new L2/L3 restructure, the route
455 * returned is a prefix route. The important
456 * piece of information from the previous
457 * RTM_GET is the interface index. In the
458 * case of ECMP, the kernel will traverse
459 * the route group for the given entry.
460 */
461 if (sdl->sdl_family == AF_LINK &&
445 !(rtm->rtm_flags & RTF_GATEWAY) &&
462 !(rtm->rtm_flags & RTF_GATEWAY) &&
446 valid_type(sdl->sdl_type) )
447 break; /* found it */
463 valid_type(sdl->sdl_type) ) {
464 addr->sin_addr.s_addr = dst->sin_addr.s_addr;
465 break;
466 }
467
448 if (dst->sin_other & SIN_PROXY) {
449 fprintf(stderr, "delete: cannot locate %s\n",host);
450 return (1);
451 }
452 dst->sin_other = SIN_PROXY;
453 }
454 if (rtmsg(RTM_DELETE, dst, NULL) != NULL) {
455 printf("%s (%s) deleted\n", host, inet_ntoa(addr->sin_addr));

--- 17 unchanged lines hidden (view full) ---

473 char ifname[IF_NAMESIZE];
474 int st, found_entry = 0;
475
476 mib[0] = CTL_NET;
477 mib[1] = PF_ROUTE;
478 mib[2] = 0;
479 mib[3] = AF_INET;
480 mib[4] = NET_RT_FLAGS;
468 if (dst->sin_other & SIN_PROXY) {
469 fprintf(stderr, "delete: cannot locate %s\n",host);
470 return (1);
471 }
472 dst->sin_other = SIN_PROXY;
473 }
474 if (rtmsg(RTM_DELETE, dst, NULL) != NULL) {
475 printf("%s (%s) deleted\n", host, inet_ntoa(addr->sin_addr));

--- 17 unchanged lines hidden (view full) ---

493 char ifname[IF_NAMESIZE];
494 int st, found_entry = 0;
495
496 mib[0] = CTL_NET;
497 mib[1] = PF_ROUTE;
498 mib[2] = 0;
499 mib[3] = AF_INET;
500 mib[4] = NET_RT_FLAGS;
501#ifdef RTF_LLINFO
481 mib[5] = RTF_LLINFO;
502 mib[5] = RTF_LLINFO;
503#else
504 mib[5] = 0;
505#endif
482 if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0)
483 err(1, "route-sysctl-estimate");
484 if (needed == 0) /* empty table */
485 return 0;
486 buf = NULL;
487 for (;;) {
488 newbuf = realloc(buf, needed);
489 if (newbuf == NULL) {

--- 68 unchanged lines hidden (view full) ---

558 } else
559 printf("(incomplete)");
560 if (if_indextoname(sdl->sdl_index, ifname) != NULL)
561 printf(" on %s", ifname);
562 if (rtm->rtm_rmx.rmx_expire == 0)
563 printf(" permanent");
564 if (addr->sin_other & SIN_PROXY)
565 printf(" published (proxy only)");
506 if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0)
507 err(1, "route-sysctl-estimate");
508 if (needed == 0) /* empty table */
509 return 0;
510 buf = NULL;
511 for (;;) {
512 newbuf = realloc(buf, needed);
513 if (newbuf == NULL) {

--- 68 unchanged lines hidden (view full) ---

582 } else
583 printf("(incomplete)");
584 if (if_indextoname(sdl->sdl_index, ifname) != NULL)
585 printf(" on %s", ifname);
586 if (rtm->rtm_rmx.rmx_expire == 0)
587 printf(" permanent");
588 if (addr->sin_other & SIN_PROXY)
589 printf(" published (proxy only)");
566 if (rtm->rtm_addrs & RTA_NETMASK) {
567 addr = (struct sockaddr_inarp *)
568 (SA_SIZE(sdl) + (char *)sdl);
569 if (addr->sin_addr.s_addr == 0xffffffff)
570 printf(" published");
571 if (addr->sin_len != 8)
572 printf("(weird)");
573 }
574 switch(sdl->sdl_type) {
590 if (rtm->rtm_flags & RTF_ANNOUNCE)
591 printf(" published");
592 switch(sdl->sdl_type) {
575 case IFT_ETHER:
576 printf(" [ethernet]");
577 break;
578 case IFT_ISO88025:
579 printf(" [token-ring]");
580 trld = SDL_ISO88025(sdl);
581 if (trld->trld_rcf != 0) {
582 printf(" rt=%x", ntohs(trld->trld_rcf));

--- 239 unchanged lines hidden ---
593 case IFT_ETHER:
594 printf(" [ethernet]");
595 break;
596 case IFT_ISO88025:
597 printf(" [token-ring]");
598 trld = SDL_ISO88025(sdl);
599 if (trld->trld_rcf != 0) {
600 printf(" rt=%x", ntohs(trld->trld_rcf));

--- 239 unchanged lines hidden ---