From owner-freebsd-bugs Fri Mar 9 1:46:22 2001 Delivered-To: freebsd-bugs@freebsd.org Received: from whale.sunbay.crimea.ua (whale.sunbay.crimea.ua [212.110.138.65]) by hub.freebsd.org (Postfix) with ESMTP id 115F437B719 for ; Fri, 9 Mar 2001 01:46:12 -0800 (PST) (envelope-from ru@whale.sunbay.crimea.ua) Received: (from ru@localhost) by whale.sunbay.crimea.ua (8.11.2/8.11.2) id f299jb320610; Fri, 9 Mar 2001 11:45:37 +0200 (EET) (envelope-from ru) Date: Fri, 9 Mar 2001 11:45:37 +0200 From: Ruslan Ermilov To: Bill Fumerola Cc: Garrett Wollman , freebsd-bugs@FreeBSD.ORG Subject: Re: bin/25584: arp.c - better printed ether address Message-ID: <20010309114537.A19746@sunbay.com> Mail-Followup-To: Bill Fumerola , Garrett Wollman , freebsd-bugs@FreeBSD.ORG References: <200103072200.f27M02o56673@freefall.freebsd.org> <20010307195349.H31752@elvis.mu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="IJpNTDwzlM2Ie8A6" Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <20010307195349.H31752@elvis.mu.org>; from billf@mu.org on Wed, Mar 07, 2001 at 07:53:49PM -0600 Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org --IJpNTDwzlM2Ie8A6 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Wed, Mar 07, 2001 at 07:53:49PM -0600, Bill Fumerola wrote: > On Wed, Mar 07, 2001 at 02:00:02PM -0800, Garrett Wollman wrote: > > > > - printf("%x:%x:%x:%x:%x:%x", cp[0], cp[1], cp[2], cp[3], cp[4], cp[5]); > > > + printf("%02x:%02x:%02x:%02x:%02x:%02x", cp[0], cp[1], cp[2], cp[3], cp[4], cp[5]); > > > > FWIW, I like this change. > > So do I, so I committed it... > Objecting. This is not compatible with ether_ntoa(3) and link_ntoa(3). The correct fix would be to fix these functions, and use them in arp(8). I am attaching the patch to arp(8) I would like to commit. See, for comparison, how route(8) and netstat(1) output Ethernet addresses. (I know that kernel prints Ethernet addresses differently.) Cheers, -- Ruslan Ermilov Oracle Developer/DBA, ru@sunbay.com Sunbay Software AG, ru@FreeBSD.org FreeBSD committer, +380.652.512.251 Simferopol, Ukraine http://www.FreeBSD.org The Power To Serve http://www.oracle.com Enabling The Information Age --IJpNTDwzlM2Ie8A6 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=p Index: arp.c =================================================================== RCS file: /home/ncvs/src/usr.sbin/arp/arp.c,v retrieving revision 1.28 diff -u -p -r1.28 arp.c --- arp.c 2001/03/08 01:52:49 1.28 +++ arp.c 2001/03/09 09:34:12 @@ -61,6 +61,7 @@ static const char rcsid[] = #include #include +#include #include #include #include @@ -88,15 +89,14 @@ void print_entry(struct sockaddr_dl *sdl void nuke_entry(struct sockaddr_dl *sdl, struct sockaddr_inarp *sin, struct rt_msghdr *rtm); int delete(char *host, char *info); -void ether_print(u_char *cp); +void sdl_print(const struct sockaddr_dl *); void usage(void); int set(int argc, char **argv); int get(char *host); int file(char *name); void getsocket(void); -int my_ether_aton(char *a, u_char *n); int rtmsg(int cmd); -int get_ether_addr(u_int32_t ipaddr, u_char *hwaddr); +int get_sdl_addr(u_int32_t ipaddr, struct sockaddr_dl *sdl); static int pid; static int nflag; /* no reverse dns lookups */ @@ -255,7 +255,7 @@ set(int argc, char **argv) register struct sockaddr_inarp *sin = &sin_m; register struct sockaddr_dl *sdl; register struct rt_msghdr *rtm = &(m_rtmsg.m_rtm); - u_char *ea; + struct ether_addr *ea; char *host = argv[0], *eaddr = argv[1]; getsocket(); @@ -288,17 +288,19 @@ set(int argc, char **argv) } argv++; } - ea = (u_char *)LLADDR(&sdl_m); if (doing_proxy && !strcmp(eaddr, "auto")) { - if (!get_ether_addr(sin->sin_addr.s_addr, ea)) { + if (!get_sdl_addr(sin->sin_addr.s_addr, &sdl_m)) { printf("no interface found for %s\n", inet_ntoa(sin->sin_addr)); return (1); } - sdl_m.sdl_alen = 6; } else { - if (my_ether_aton(eaddr, ea) == 0) + if ((ea = ether_aton(eaddr)) == NULL) + warnx("invalid Ethernet address '%s'", eaddr); + else { sdl_m.sdl_alen = 6; + memcpy(LLADDR(&sdl_m), ea, sdl_m.sdl_alen); + } } tryagain: if (rtmsg(RTM_GET) < 0) { @@ -487,7 +489,7 @@ print_entry(struct sockaddr_dl *sdl, } printf("%s (%s) at ", host, inet_ntoa(sin->sin_addr)); if (sdl->sdl_alen) - ether_print(LLADDR(sdl)); + sdl_print(sdl); else printf("(incomplete)"); if (rtm->rtm_rmx.rmx_expire == 0) @@ -535,26 +537,13 @@ nuke_entry(struct sockaddr_dl *sdl, } void -ether_print(u_char *cp) -{ - printf("%02x:%02x:%02x:%02x:%02x:%02x", cp[0], cp[1], cp[2], cp[3], - cp[4], cp[5]); -} - -int -my_ether_aton(char *a, u_char *n) +sdl_print(const struct sockaddr_dl *sdl) { - int i, o[6]; - i = sscanf(a, "%x:%x:%x:%x:%x:%x", &o[0], &o[1], &o[2], - &o[3], &o[4], &o[5]); - if (i != 6) { - warnx("invalid Ethernet address '%s'", a); - return (1); - } - for (i=0; i<6; i++) - n[i] = o[i]; - return (0); + if (sdl->sdl_type == IFT_ETHER && sdl->sdl_alen == ETHER_ADDR_LEN) + (void)printf("%s", ether_ntoa((struct ether_addr *)LLADDR(sdl))); + else + (void)printf("%s", link_ntoa(sdl)); } void @@ -636,13 +625,13 @@ doit: } /* - * get_ether_addr - get the hardware address of an interface on the + * get_sdl_addr - get the hardware address of an interface on the * the same subnet as ipaddr. */ #define MAX_IFS 32 int -get_ether_addr(u_int32_t ipaddr, u_char *hwaddr) +get_sdl_addr(u_int32_t ipaddr, struct sockaddr_dl *sdl) { struct ifreq *ifr, *ifend, *ifp; u_int32_t ina, mask; @@ -720,13 +709,14 @@ nextif: * Found the link-level address - copy it out */ dla = (struct sockaddr_dl *) &ifr->ifr_addr; - memcpy(hwaddr, LLADDR(dla), dla->sdl_alen); + memcpy(LLADDR(sdl), LLADDR(dla), dla->sdl_alen); + sdl->sdl_alen = dla->sdl_alen; close (s); printf("using interface %s for proxy with address ", ifp->ifr_name); - ether_print(hwaddr); + sdl_print(dla); printf("\n"); - return dla->sdl_alen; + return 1; } ifr = (struct ifreq *) ((char *)&ifr->ifr_addr + MAX(ifr->ifr_addr.sa_len, sizeof(ifr->ifr_addr))); --IJpNTDwzlM2Ie8A6-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message