Deleted Added
full compact
route.c (59540) route.c (62584)
1/*
2 * Copyright (c) 1983, 1988, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

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

31 * SUCH DAMAGE.
32 */
33
34#ifndef lint
35#if 0
36static char sccsid[] = "From: @(#)route.c 8.6 (Berkeley) 4/28/95";
37#endif
38static const char rcsid[] =
1/*
2 * Copyright (c) 1983, 1988, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

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

31 * SUCH DAMAGE.
32 */
33
34#ifndef lint
35#if 0
36static char sccsid[] = "From: @(#)route.c 8.6 (Berkeley) 4/28/95";
37#endif
38static const char rcsid[] =
39 "$FreeBSD: head/usr.bin/netstat/route.c 59540 2000-04-23 14:18:18Z markm $";
39 "$FreeBSD: head/usr.bin/netstat/route.c 62584 2000-07-04 16:26:46Z itojun $";
40#endif /* not lint */
41
42#include <sys/param.h>
43#include <sys/protosw.h>
44#include <sys/socket.h>
45#include <sys/time.h>
46
47#include <net/if.h>

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

68#include <string.h>
69#include <unistd.h>
70#include <err.h>
71#include <time.h>
72#include "netstat.h"
73
74#define kget(p, d) (kread((u_long)(p), (char *)&(d), sizeof (d)))
75
40#endif /* not lint */
41
42#include <sys/param.h>
43#include <sys/protosw.h>
44#include <sys/socket.h>
45#include <sys/time.h>
46
47#include <net/if.h>

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

68#include <string.h>
69#include <unistd.h>
70#include <err.h>
71#include <time.h>
72#include "netstat.h"
73
74#define kget(p, d) (kread((u_long)(p), (char *)&(d), sizeof (d)))
75
76
77/* alignment constraint for routing socket */
78#define ROUNDUP(a) \
79 ((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long))
80#define ADVANCE(x, n) (x += ROUNDUP((n)->sa_len))
81
76/*
77 * Definitions for showing gateway flags.
78 */
79struct bits {
80 u_long b_mask;
81 char b_val;
82} bits[] = {
83 { RTF_UP, 'U' },

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

217 }
218 if (afname)
219 printf("\n%s:\n", afname);
220 else
221 printf("\nProtocol Family %d:\n", af);
222}
223
224/* column widths; each followed by one space */
82/*
83 * Definitions for showing gateway flags.
84 */
85struct bits {
86 u_long b_mask;
87 char b_val;
88} bits[] = {
89 { RTF_UP, 'U' },

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

223 }
224 if (afname)
225 printf("\n%s:\n", afname);
226 else
227 printf("\nProtocol Family %d:\n", af);
228}
229
230/* column widths; each followed by one space */
225#define WID_DST 18 /* width of destination column */
226#define WID_GW 18 /* width of gateway column */
227#ifdef INET6
228#define WID_DST6 (lflag ? 39 : (nflag ? 33: 18)) /* width of dest column */
229#define WID_GW6 (lflag ? 31 : (nflag ? 29 : 18)) /* width of gateway column */
231#ifndef INET6
232#define WID_DST(af) 18 /* width of destination column */
233#define WID_GW(af) 18 /* width of gateway column */
234#else
235#define WID_DST(af) \
236 ((af) == AF_INET6 ? (lflag ? 39 : (nflag ? 33: 18)) : 18)
237#define WID_GW(af) \
238 ((af) == AF_INET6 ? (lflag ? 31 : (nflag ? 29 : 18)) : 18)
230#endif /*INET6*/
231
232/*
233 * Print header for routing table columns.
234 */
235void
239#endif /*INET6*/
240
241/*
242 * Print header for routing table columns.
243 */
244void
236pr_rthdr(wid_af)
237 int wid_af;
245pr_rthdr(af)
246 int af;
238{
247{
239 int wid_dst, wid_gw;
240
248
241 wid_dst =
242#ifdef INET6
243 wid_af == AF_INET6 ? WID_DST6 :
244#endif
245 WID_DST;
246 wid_gw =
247#ifdef INET6
248 wid_af == AF_INET6 ? WID_GW6 :
249#endif
250 WID_GW;
251
252 if (Aflag)
253 printf("%-8.8s ","Address");
249 if (Aflag)
250 printf("%-8.8s ","Address");
254 if (wid_af == AF_INET || lflag)
251 if (lflag)
255 printf("%-*.*s %-*.*s %-6.6s %6.6s%8.8s %8.8s %6s\n",
252 printf("%-*.*s %-*.*s %-6.6s %6.6s%8.8s %8.8s %6s\n",
256 wid_dst, wid_dst, "Destination",
257 wid_gw, wid_gw, "Gateway",
253 WID_DST(af), WID_DST(af), "Destination",
254 WID_GW(af), WID_GW(af), "Gateway",
258 "Flags", "Refs", "Use", "Netif", "Expire");
259 else
260 printf("%-*.*s %-*.*s %-6.6s %8.8s %6s\n",
255 "Flags", "Refs", "Use", "Netif", "Expire");
256 else
257 printf("%-*.*s %-*.*s %-6.6s %8.8s %6s\n",
261 wid_dst, wid_dst, "Destination",
262 wid_gw, wid_gw, "Gateway",
258 WID_DST(af), WID_DST(af), "Destination",
259 WID_GW(af), WID_GW(af), "Gateway",
263 "Flags", "Netif", "Expire");
264}
265
266static struct sockaddr *
267kgetsa(dst)
268 register struct sockaddr *dst;
269{
270

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

409 if (af != old_af) {
410 pr_family(af);
411 old_af = af;
412 }
413 if (rtm->rtm_addrs == RTA_DST)
414 p_sockaddr(sa, NULL, 0, 36);
415 else {
416 p_sockaddr(sa, NULL, rtm->rtm_flags, 16);
260 "Flags", "Netif", "Expire");
261}
262
263static struct sockaddr *
264kgetsa(dst)
265 register struct sockaddr *dst;
266{
267

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

406 if (af != old_af) {
407 pr_family(af);
408 old_af = af;
409 }
410 if (rtm->rtm_addrs == RTA_DST)
411 p_sockaddr(sa, NULL, 0, 36);
412 else {
413 p_sockaddr(sa, NULL, rtm->rtm_flags, 16);
417 sa = (struct sockaddr *)(sa->sa_len + (char *)sa);
414 sa = (struct sockaddr *)(ROUNDUP(sa->sa_len) + (char *)sa);
418 p_sockaddr(sa, NULL, 0, 18);
419 }
420 p_flags(rtm->rtm_flags & interesting, "%-6.6s ");
421 putchar('\n');
422}
423
424static void
425p_sockaddr(sa, mask, flags, width)

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

597
598 bzero(&addr, sizeof(addr));
599 if ((sa = kgetsa(rt_key(rt))))
600 bcopy(sa, &addr, sa->sa_len);
601 bzero(&mask, sizeof(mask));
602 if (rt_mask(rt) && (sa = kgetsa(rt_mask(rt))))
603 bcopy(sa, &mask, sa->sa_len);
604 p_sockaddr(&addr.u_sa, &mask.u_sa, rt->rt_flags,
415 p_sockaddr(sa, NULL, 0, 18);
416 }
417 p_flags(rtm->rtm_flags & interesting, "%-6.6s ");
418 putchar('\n');
419}
420
421static void
422p_sockaddr(sa, mask, flags, width)

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

594
595 bzero(&addr, sizeof(addr));
596 if ((sa = kgetsa(rt_key(rt))))
597 bcopy(sa, &addr, sa->sa_len);
598 bzero(&mask, sizeof(mask));
599 if (rt_mask(rt) && (sa = kgetsa(rt_mask(rt))))
600 bcopy(sa, &mask, sa->sa_len);
601 p_sockaddr(&addr.u_sa, &mask.u_sa, rt->rt_flags,
605#ifdef INET6
606 addr.u_sa.sa_family == AF_INET6 ? WID_DST6 :
607#endif
608 WID_DST);
602 WID_DST(addr.u_sa.sa_family));
609 p_sockaddr(kgetsa(rt->rt_gateway), NULL, RTF_HOST,
603 p_sockaddr(kgetsa(rt->rt_gateway), NULL, RTF_HOST,
610#ifdef INET6
611 addr.u_sa.sa_family == AF_INET6 ? WID_GW6 :
612#endif
613 WID_GW);
604 WID_GW(addr.u_sa.sa_family));
614 p_flags(rt->rt_flags, "%-6.6s ");
615 if (addr.u_sa.sa_family == AF_INET || lflag)
616 printf("%6ld %8ld ", rt->rt_refcnt, rt->rt_use);
617 if (rt->rt_ifp) {
618 if (rt->rt_ifp != lastif) {
619 kget(rt->rt_ifp, ifnet);
620 kread((u_long)ifnet.if_name, name, 16);
621 lastif = rt->rt_ifp;

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

760char *
761netname6(sa6, mask)
762 struct sockaddr_in6 *sa6;
763 struct in6_addr *mask;
764{
765 static char line[MAXHOSTNAMELEN + 1];
766 u_char *p = (u_char *)mask;
767 u_char *lim;
605 p_flags(rt->rt_flags, "%-6.6s ");
606 if (addr.u_sa.sa_family == AF_INET || lflag)
607 printf("%6ld %8ld ", rt->rt_refcnt, rt->rt_use);
608 if (rt->rt_ifp) {
609 if (rt->rt_ifp != lastif) {
610 kget(rt->rt_ifp, ifnet);
611 kread((u_long)ifnet.if_name, name, 16);
612 lastif = rt->rt_ifp;

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

751char *
752netname6(sa6, mask)
753 struct sockaddr_in6 *sa6;
754 struct in6_addr *mask;
755{
756 static char line[MAXHOSTNAMELEN + 1];
757 u_char *p = (u_char *)mask;
758 u_char *lim;
768 int masklen, illegal = 0;
769 int flag = NI_WITHSCOPEID;
759 int masklen, illegal = 0, flag = NI_WITHSCOPEID;
770
771 if (mask) {
772 for (masklen = 0, lim = p + 16; p < lim; p++) {
760
761 if (mask) {
762 for (masklen = 0, lim = p + 16; p < lim; p++) {
773 if (*p == 0xff)
774 masklen += 8;
775 else
776 break;
777 }
778 if (p < lim) {
779 switch (*p) {
763 switch (*p) {
764 case 0xff:
765 masklen += 8;
766 break;
780 case 0xfe:
781 masklen += 7;
782 break;
783 case 0xfc:
784 masklen += 6;
785 break;
786 case 0xf8:
787 masklen += 5;

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

826}
827
828char *
829routename6(sa6)
830 struct sockaddr_in6 *sa6;
831{
832 static char line[MAXHOSTNAMELEN + 1];
833 int flag = NI_WITHSCOPEID;
767 case 0xfe:
768 masklen += 7;
769 break;
770 case 0xfc:
771 masklen += 6;
772 break;
773 case 0xf8:
774 masklen += 5;

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

813}
814
815char *
816routename6(sa6)
817 struct sockaddr_in6 *sa6;
818{
819 static char line[MAXHOSTNAMELEN + 1];
820 int flag = NI_WITHSCOPEID;
821 /* use local variable for safety */
822 struct sockaddr_in6 sa6_local = {AF_INET6, sizeof(sa6_local),};
834
823
824 sa6_local.sin6_addr = sa6->sin6_addr;
825 sa6_local.sin6_scope_id = sa6->sin6_scope_id;
826
835 if (nflag)
836 flag |= NI_NUMERICHOST;
837
827 if (nflag)
828 flag |= NI_NUMERICHOST;
829
838 getnameinfo((struct sockaddr *)sa6, sa6->sin6_len, line, sizeof(line),
839 NULL, 0, flag);
830 getnameinfo((struct sockaddr *)&sa6_local, sa6_local.sin6_len,
831 line, sizeof(line), NULL, 0, flag);
840
841 return line;
842}
843#endif /*INET6*/
844
845/*
846 * Print routing statistics
847 */

--- 205 unchanged lines hidden ---
832
833 return line;
834}
835#endif /*INET6*/
836
837/*
838 * Print routing statistics
839 */

--- 205 unchanged lines hidden ---