Date: Sun, 27 Jul 1997 21:35:53 PDT From: Craig Leres <leres@ee.lbl.gov> To: FreeBSD-gnats-submit@FreeBSD.ORG Subject: bin/4182: netstat should always print the interface name Message-ID: <199707280435.VAA00894@hot.ee.lbl.gov> Resent-Message-ID: <199707280440.VAA09406@hub.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 4182 >Category: bin >Synopsis: netstat should always print the interface name >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Class: change-request >Submitter-Id: current-users >Arrival-Date: Sun Jul 27 21:40:00 PDT 1997 >Last-Modified: >Originator: Craig Leres >Organization: Lawrence Berkeley National Laboratory >Release: FreeBSD 2.2.2-RELEASE i386 >Environment: Hosts with multiple network interfaces. >Description: The current version of netstat does not print the interface name for AF_LINK routing entries. This makes debugging network problems more difficult. (BTW, I sent this in a day or two ago but send-pr apparently ate it. Requiring a particular format for bug reports is ok but forcing us to use a badly designed, broken and unsafe interface is going a bit far...) >How-To-Repeat: % netstat -rn | grep link 131.243.1/24 link#1 UC 0 0 131.243.1.100/30 link#2 UC 0 0 224/4 link#1 UCS 0 0 >Fix: The appended context diff causes netstat to always print the network interface name: % netstat -rn | grep link 131.243.1/24 link#1 UC 0 0 ed0 131.243.1.100/30 link#2 UC 0 0 wl0 224/4 link#1 UCS 0 0 ed0 It also cleans up some formatting and whitespace foobars. RCS file: RCS/route.c,v retrieving revision 1.1 diff -c -r1.1 route.c *** /tmp/,RCSt1025609 Sun Jul 27 21:31:33 1997 --- route.c Sat Jul 26 21:04:33 1997 *************** *** 114,125 **** static struct sockaddr *kgetsa __P((struct sockaddr *)); static void p_tree __P((struct radix_node *)); ! static void p_rtnode __P(()); ! static void ntreestuff __P(()); static void np_rtentry __P((struct rt_msghdr *)); static void p_sockaddr __P((struct sockaddr *, struct sockaddr *, int, int)); static void p_flags __P((int, char *)); static void p_rtentry __P((struct rtentry *)); /* * Print routing tables. --- 114,127 ---- static struct sockaddr *kgetsa __P((struct sockaddr *)); static void p_tree __P((struct radix_node *)); ! static void p_rtnode __P((void)); ! static void ntreestuff __P((void)); static void np_rtentry __P((struct rt_msghdr *)); static void p_sockaddr __P((struct sockaddr *, struct sockaddr *, int, int)); static void p_flags __P((int, char *)); static void p_rtentry __P((struct rtentry *)); + static u_long forgemask __P((u_long)); + static void domask __P((char *, u_long, u_long)); /* * Print routing tables. *************** *** 314,333 **** char *buf, *next, *lim; register struct rt_msghdr *rtm; ! mib[0] = CTL_NET; ! mib[1] = PF_ROUTE; ! mib[2] = 0; ! mib[3] = 0; ! mib[4] = NET_RT_DUMP; ! mib[5] = 0; ! if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0) { err(1, "sysctl: net.route.0.0.dump estimate"); } if ((buf = malloc(needed)) == 0) { err(2, "malloc(%lu)", (unsigned long)needed); } ! if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0) { err(1, "sysctl: net.route.0.0.dump"); } lim = buf + needed; --- 316,335 ---- char *buf, *next, *lim; register struct rt_msghdr *rtm; ! mib[0] = CTL_NET; ! mib[1] = PF_ROUTE; ! mib[2] = 0; ! mib[3] = 0; ! mib[4] = NET_RT_DUMP; ! mib[5] = 0; ! if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0) { err(1, "sysctl: net.route.0.0.dump estimate"); } if ((buf = malloc(needed)) == 0) { err(2, "malloc(%lu)", (unsigned long)needed); } ! if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0) { err(1, "sysctl: net.route.0.0.dump"); } lim = buf + needed; *************** *** 435,459 **** if (sdl->sdl_nlen == 0 && sdl->sdl_alen == 0 && sdl->sdl_slen == 0) (void) sprintf(workbuf, "link#%d", sdl->sdl_index); ! else switch (sdl->sdl_type) { ! case IFT_ETHER: ! { ! register int i; ! register u_char *lla = (u_char *)sdl->sdl_data + ! sdl->sdl_nlen; ! ! cplim = ""; ! for (i = 0; i < sdl->sdl_alen; i++, lla++) { ! cp += sprintf(cp, "%s%x", cplim, *lla); ! cplim = ":"; } - cp = workbuf; - break; - } - default: - cp = link_ntoa(sdl); - break; - } break; } --- 437,464 ---- if (sdl->sdl_nlen == 0 && sdl->sdl_alen == 0 && sdl->sdl_slen == 0) (void) sprintf(workbuf, "link#%d", sdl->sdl_index); ! else ! switch (sdl->sdl_type) { ! ! case IFT_ETHER: ! { ! register int i; ! register u_char *lla = (u_char *)sdl->sdl_data + ! sdl->sdl_nlen; ! ! cplim = ""; ! for (i = 0; i < sdl->sdl_alen; i++, lla++) { ! cp += sprintf(cp, "%s%x", cplim, *lla); ! cplim = ":"; ! } ! cp = workbuf; ! break; ! } ! ! default: ! cp = link_ntoa(sdl); ! break; } break; } *************** *** 510,516 **** /* * Don't print protocol-cloned routes unless -a. */ ! if(rt->rt_parent && !aflag) return; if (!(sa = kgetsa(rt_key(rt)))) --- 515,521 ---- /* * Don't print protocol-cloned routes unless -a. */ ! if (rt->rt_parent && !aflag) return; if (!(sa = kgetsa(rt_key(rt)))) *************** *** 533,549 **** snprintf(prettyname, sizeof prettyname, "%.6s%d", name, ifnet.if_unit); } ! if(rt->rt_rmx.rmx_expire) { time_t expire_time; ! if ((expire_time ! =rt->rt_rmx.rmx_expire - time((time_t *)0)) > 0) ! printf(" %8.8s %6d%s", prettyname, ! (int)expire_time, ! rt->rt_nodes[0].rn_dupedkey ? " =>" : ""); ! } else { ! printf(" %8.8s%s", prettyname, ! rt->rt_nodes[0].rn_dupedkey ? " =>" : ""); } } --- 538,553 ---- snprintf(prettyname, sizeof prettyname, "%.6s%d", name, ifnet.if_unit); } ! printf("%8.8s", prettyname); ! if (rt->rt_rmx.rmx_expire) { time_t expire_time; ! if ((expire_time = ! rt->rt_rmx.rmx_expire - time((time_t *)0)) > 0) ! printf(" %6d%s", (int)expire_time, ! rt->rt_nodes[0].rn_dupedkey ? " =>" : ""); ! } else if (rt->rt_nodes[0].rn_dupedkey) { ! printf(" =>"); } } *************** *** 723,744 **** u_short port; struct netent *np = 0; struct hostent *hp = 0; ! struct servent *sp = 0; char *net = "", *host = ""; ! register char *p; register u_char *q; struct ipx_addr work = ((struct sockaddr_ipx *)sa)->sipx_addr; ! static char mybuf[50]; char cport[10], chost[15], cnet[15]; ! if(!nflag) sp = getservbyport(work.x_port, "ipx"); port = ntohs(work.x_port); if (ipx_nullnet(work) && ipx_nullhost(work)) { if (port) { ! if (sp) sprintf(mybuf, "*.%s", sp->s_name); ! else sprintf(mybuf, "*.%x", port); } else sprintf(mybuf, "*.*"); --- 727,751 ---- u_short port; struct netent *np = 0; struct hostent *hp = 0; ! struct servent *sp = 0; char *net = "", *host = ""; ! register char *p; ! register u_char *q; struct ipx_addr work = ((struct sockaddr_ipx *)sa)->sipx_addr; ! static char mybuf[50]; char cport[10], chost[15], cnet[15]; ! if (!nflag) sp = getservbyport(work.x_port, "ipx"); port = ntohs(work.x_port); if (ipx_nullnet(work) && ipx_nullhost(work)) { if (port) { ! if (sp) ! sprintf(mybuf, "*.%s", sp->s_name); ! else ! sprintf(mybuf, "*.%x", port); } else sprintf(mybuf, "*.*"); *************** *** 776,784 **** } if (port) { ! if (strcmp(host, "*") == 0) host = ""; ! if (sp) sprintf(cport, "%s%s", *host ? "." : "", sp->s_name); ! else sprintf(cport, "%s%x", *host ? "." : "", port); } else *cport = 0; --- 783,794 ---- } if (port) { ! if (strcmp(host, "*") == 0) ! host = ""; ! if (sp) ! sprintf(cport, "%s%s", *host ? "." : "", sp->s_name); ! else ! sprintf(cport, "%s%x", *host ? "." : "", port); } else *cport = 0; *************** *** 792,798 **** { register struct sockaddr_ipx *sipx = (struct sockaddr_ipx *)sa; struct sockaddr_ipx work; ! static union ipx_net ipx_zeronet; char *p; struct ipx_addr in; struct hostent *hp; --- 802,808 ---- { register struct sockaddr_ipx *sipx = (struct sockaddr_ipx *)sa; struct sockaddr_ipx work; ! static union ipx_net ipx_zeronet; char *p; struct ipx_addr in; struct hostent *hp; *************** *** 801,812 **** in = work.sipx_addr; hp = gethostbyaddr((char *)&in, sizeof(struct ipx_addr), AF_IPX); ! if (hp) return (hp->h_name); work.sipx_addr.x_port = 0; work.sipx_addr.x_net = ipx_zeronet; p = ipx_print((struct sockaddr *)&work); ! if (strncmp("*.", p, 2) == 0) p += 2; return(p); } --- 811,824 ---- in = work.sipx_addr; hp = gethostbyaddr((char *)&in, sizeof(struct ipx_addr), AF_IPX); ! if (hp) ! return (hp->h_name); work.sipx_addr.x_port = 0; work.sipx_addr.x_net = ipx_zeronet; p = ipx_print((struct sockaddr *)&work); ! if (strncmp("*.", p, 2) == 0) ! p += 2; return(p); } *************** *** 876,882 **** work.sns_addr.x_net = ns_zeronet; p = ns_print((struct sockaddr *)&work); ! if (strncmp("0H.", p, 3) == 0) p += 3; return(p); } #endif --- 888,895 ---- work.sns_addr.x_net = ns_zeronet; p = ns_print((struct sockaddr *)&work); ! if (strncmp("0H.", p, 3) == 0) ! p += 3; return(p); } #endif *************** *** 886,894 **** char *p0; { register char *p = p0; - for (; *p; p++) switch (*p) { ! case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': ! *p += ('A' - 'a'); ! } } --- 899,915 ---- char *p0; { register char *p = p0; ! for (; *p; p++) ! switch (*p) { ! ! case 'a': ! case 'b': ! case 'c': ! case 'd': ! case 'e': ! case 'f': ! *p += ('A' - 'a'); ! break; ! } } >Audit-Trail: >Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199707280435.VAA00894>