Index: kern/subr_prf.c =================================================================== RCS file: /home/ncvs/src/sys/kern/subr_prf.c,v retrieving revision 1.66 diff -u -r1.66 subr_prf.c --- kern/subr_prf.c 2000/11/26 20:35:18 1.66 +++ kern/subr_prf.c 2000/12/10 14:53:56 @@ -404,7 +404,7 @@ /* * Scaled down version of printf(3). * - * Two additional formats: + * Four additional formats: * * The format %b is supported to decode error registers. * Its usage is: @@ -426,6 +426,16 @@ * XXX: %D -- Hexdump, takes pointer and separator string: * ("%6D", ptr, ":") -> XX:XX:XX:XX:XX:XX * ("%*D", len, ptr, " " -> XX XX XX XX ... + * + * The %a format prints IPv4 addresses: + * + * ("%a", &addr) -> 1.2.3.4 + * ("%0a", &addr) -> 001.002.003.004 + * + * The %A format prints IPv6 addresses: + * + * ("%A", &addr) -> 1:2:3:4:5:6:7:8:9:a:b:c:d:e:f:10 + * ("%0A", &addr) -> 01:02:03:04:05:06:07:08:09:0a:0b:0c:0d:0e:0f:10 */ int kvprintf(char const *fmt, void (*func)(int, void*), void *arg, int radix, va_list ap) @@ -465,7 +475,8 @@ } qflag = 0; lflag = 0; ladjust = 0; sharpflag = 0; neg = 0; sign = 0; dot = 0; dwidth = 0; -reswitch: switch (ch = (u_char)*fmt++) { + reswitch: + switch (ch = (u_char)*fmt++) { case '.': dot = 1; goto reswitch; @@ -510,6 +521,29 @@ else width = n; goto reswitch; + case 'A': + p = va_arg(ap, char *); + for (n = 0; n < 16; ++n, ++p) { + if (*p > 15 || padc == '0') + PCHAR(hex2ascii(*p >> 4)); + PCHAR(hex2ascii(*p & 0xf)); + if (n < 15) + PCHAR(':'); + } + break; + case 'a': + p = va_arg(ap, char *); + for (n = 0; n < 4; ++n, ++p) { + tmp = (unsigned char)*p; + if (tmp > 99 || padc == '0') + PCHAR('0' + tmp / 100); + if (tmp > 9 || padc == '0') + PCHAR('0' + (tmp % 100) / 10); + PCHAR('0' + tmp % 10); + if (n < 3) + PCHAR('.'); + } + break; case 'b': ul = va_arg(ap, int); p = va_arg(ap, char *); Index: netinet/if_ether.c =================================================================== RCS file: /home/ncvs/src/sys/netinet/if_ether.c,v retrieving revision 1.73 diff -u -r1.73 if_ether.c --- netinet/if_ether.c 2000/11/25 07:35:33 1.73 +++ netinet/if_ether.c 2000/12/10 14:32:35 @@ -383,9 +383,8 @@ rt = la->la_rt; } if (la == 0 || rt == 0) { - log(LOG_DEBUG, "arpresolve: can't allocate llinfo for %s%s%s\n", - inet_ntoa(SIN(dst)->sin_addr), la ? "la" : "", - rt ? "rt" : ""); + log(LOG_DEBUG, "arpresolve: can't allocate llinfo for %a%s%s\n", + &SIN(dst)->sin_addr, la ? "la" : "", rt ? "rt" : ""); m_freem(m); return (0); } @@ -542,15 +541,15 @@ if (!bcmp((caddr_t)ea->arp_sha, (caddr_t)etherbroadcastaddr, sizeof (ea->arp_sha))) { log(LOG_ERR, - "arp: ether address is broadcast for IP address %s!\n", - inet_ntoa(isaddr)); + "arp: ether address is broadcast for IP address %a!\n", + &isaddr); m_freem(m); return; } if (isaddr.s_addr == myaddr.s_addr) { log(LOG_ERR, - "arp: %6D is using my IP address %s!\n", - ea->arp_sha, ":", inet_ntoa(isaddr)); + "arp: %6D is using my IP address %a!\n", + ea->arp_sha, ":", &isaddr); itaddr = myaddr; goto reply; } @@ -558,8 +557,8 @@ if (la && (rt = la->la_rt) && (sdl = SDL(rt->rt_gateway))) { #ifndef BRIDGE /* the following is not an error when doing bridging */ if (rt->rt_ifp != &ac->ac_if) { - log(LOG_ERR, "arp: %s is on %s%d but got reply from %6D on %s%d\n", - inet_ntoa(isaddr), + log(LOG_ERR, "arp: %a is on %s%d but got reply from %6D on %s%d\n", + &isaddr, rt->rt_ifp->if_name, rt->rt_ifp->if_unit, ea->arp_sha, ":", ac->ac_if.if_name, ac->ac_if.if_unit); @@ -569,14 +568,14 @@ if (sdl->sdl_alen && bcmp((caddr_t)ea->arp_sha, LLADDR(sdl), sdl->sdl_alen)) { if (rt->rt_expire) - log(LOG_INFO, "arp: %s moved from %6D to %6D on %s%d\n", - inet_ntoa(isaddr), (u_char *)LLADDR(sdl), ":", + log(LOG_INFO, "arp: %a moved from %6D to %6D on %s%d\n", + &isaddr, (u_char *)LLADDR(sdl), ":", ea->arp_sha, ":", ac->ac_if.if_name, ac->ac_if.if_unit); else { log(LOG_ERR, - "arp: %6D attempts to modify permanent entry for %s on %s%d\n", - ea->arp_sha, ":", inet_ntoa(isaddr), + "arp: %6D attempts to modify permanent entry for %a on %s%d\n", + ea->arp_sha, ":", &isaddr, ac->ac_if.if_name, ac->ac_if.if_unit); goto reply; } @@ -683,8 +682,8 @@ } if (rt->rt_ifp != &ac->ac_if) { log(LOG_INFO, "arp_proxy: ignoring request" - " from %s via %s%d, expecting %s%d\n", - inet_ntoa(isaddr), ac->ac_if.if_name, + " from %a via %s%d, expecting %s%d\n", + &isaddr, ac->ac_if.if_name, ac->ac_if.if_unit, rt->rt_ifp->if_name, rt->rt_ifp->if_unit); rtfree(rt); @@ -694,8 +693,7 @@ rtfree(rt); #ifdef DEBUG_PROXY - printf("arp: proxying for %s\n", - inet_ntoa(itaddr)); + printf("arp: proxying for %a\n", &itaddr); #endif } else { rt = la->la_rt; @@ -796,8 +794,7 @@ why = "gateway route is not ours"; if (why && create) { - log(LOG_DEBUG, "arplookup %s failed: %s\n", - inet_ntoa(sin.sin_addr), why); + log(LOG_DEBUG, "arplookup %a failed: %s\n", &sin.sin_addr, why); return 0; } else if (why) { return 0; Index: netinet/ip_fw.c =================================================================== RCS file: /home/ncvs/src/sys/netinet/ip_fw.c,v retrieving revision 1.149 diff -u -r1.149 ip_fw.c --- netinet/ip_fw.c 2000/11/07 09:20:32 1.149 +++ netinet/ip_fw.c 2000/12/10 14:24:59 @@ -547,12 +547,12 @@ case IP_FW_F_FWD: if (f->fw_fwd_ip.sin_port) snprintf(SNPARGS(action2, 0), - "Forward to %s:%d", - inet_ntoa(f->fw_fwd_ip.sin_addr), + "Forward to %a:%d", + &f->fw_fwd_ip.sin_addr, f->fw_fwd_ip.sin_port); else - snprintf(SNPARGS(action2, 0), "Forward to %s", - inet_ntoa(f->fw_fwd_ip.sin_addr)); + snprintf(SNPARGS(action2, 0), "Forward to %a", + &f->fw_fwd_ip.sin_addr); break; #endif default: @@ -563,29 +563,25 @@ switch (ip->ip_p) { case IPPROTO_TCP: - len = snprintf(SNPARGS(proto, 0), "TCP %s", - inet_ntoa(ip->ip_src)); + len = snprintf(SNPARGS(proto, 0), "TCP %a", &ip->ip_src); if ((ip->ip_off & IP_OFFMASK) == 0) len += snprintf(SNPARGS(proto, len), ":%d ", ntohs(tcp->th_sport)); else len += snprintf(SNPARGS(proto, len), " "); - len += snprintf(SNPARGS(proto, len), "%s", - inet_ntoa(ip->ip_dst)); + len += snprintf(SNPARGS(proto, len), "%a", &ip->ip_dst); if ((ip->ip_off & IP_OFFMASK) == 0) snprintf(SNPARGS(proto, len), ":%d", ntohs(tcp->th_dport)); break; case IPPROTO_UDP: - len = snprintf(SNPARGS(proto, 0), "UDP %s", - inet_ntoa(ip->ip_src)); + len = snprintf(SNPARGS(proto, 0), "UDP %a", &ip->ip_src); if ((ip->ip_off & IP_OFFMASK) == 0) len += snprintf(SNPARGS(proto, len), ":%d ", ntohs(udp->uh_sport)); else len += snprintf(SNPARGS(proto, len), " "); - len += snprintf(SNPARGS(proto, len), "%s", - inet_ntoa(ip->ip_dst)); + len += snprintf(SNPARGS(proto, len), "%a", &ip->ip_dst); if ((ip->ip_off & IP_OFFMASK) == 0) snprintf(SNPARGS(proto, len), ":%d", ntohs(udp->uh_dport)); @@ -596,14 +592,12 @@ icmp->icmp_type, icmp->icmp_code); else len = snprintf(SNPARGS(proto, 0), "ICMP "); - len += snprintf(SNPARGS(proto, len), "%s", - inet_ntoa(ip->ip_src)); - snprintf(SNPARGS(proto, len), " %s", inet_ntoa(ip->ip_dst)); + len += snprintf(SNPARGS(proto, len), "%a", &ip->ip_src); + snprintf(SNPARGS(proto, len), " %a", &ip->ip_dst); break; default: - len = snprintf(SNPARGS(proto, 0), "P:%d %s", ip->ip_p, - inet_ntoa(ip->ip_src)); - snprintf(SNPARGS(proto, len), " %s", inet_ntoa(ip->ip_dst)); + len = snprintf(SNPARGS(proto, 0), "P:%d %a", ip->ip_p, &ip->ip_src); + snprintf(SNPARGS(proto, len), " %a", &ip->ip_dst); break; } Index: netinet/ip_icmp.c =================================================================== RCS file: /home/ncvs/src/sys/netinet/ip_icmp.c,v retrieving revision 1.46 diff -u -r1.46 ip_icmp.c --- netinet/ip_icmp.c 2000/11/02 09:46:23 1.46 +++ netinet/ip_icmp.c 2000/12/10 14:23:28 @@ -247,10 +247,8 @@ */ #ifdef ICMPPRINTFS if (icmpprintfs) { - char buf[4 * sizeof "123"]; - strcpy(buf, inet_ntoa(ip->ip_src)); - printf("icmp_input from %s to %s, len %d\n", - buf, inet_ntoa(ip->ip_dst), icmplen); + printf("icmp_input from %a to %a, len %d\n", + &ip->ip_src, &ip->ip_dst, icmplen); } #endif if (icmplen < ICMP_MINLEN) { @@ -412,8 +410,8 @@ mtu = ip_next_mtu(rt->rt_rmx.rmx_mtu, 1); #ifdef DEBUG_MTUDISC - printf("MTU for %s reduced to %d\n", - inet_ntoa(icmpsrc.sin_addr), mtu); + printf("MTU for %a reduced to %d\n", + &icmpsrc.sin_addr, mtu); #endif if (mtu < 296) { /* rt->rt_rmx.rmx_mtu = @@ -509,19 +507,10 @@ case ICMP_REDIRECT: if (log_redirect) { - u_long src, dst, gw; - - src = ntohl(ip->ip_src.s_addr); - dst = ntohl(icp->icmp_ip.ip_dst.s_addr); - gw = ntohl(icp->icmp_gwaddr.s_addr); - printf("icmp redirect from %d.%d.%d.%d: " - "%d.%d.%d.%d => %d.%d.%d.%d\n", - (int)(src >> 24), (int)((src >> 16) & 0xff), - (int)((src >> 8) & 0xff), (int)(src & 0xff), - (int)(dst >> 24), (int)((dst >> 16) & 0xff), - (int)((dst >> 8) & 0xff), (int)(dst & 0xff), - (int)(gw >> 24), (int)((gw >> 16) & 0xff), - (int)((gw >> 8) & 0xff), (int)(gw & 0xff)); + printf("icmp redirect from %a: %a => %a\n", + &ip->ip_src.s_addr, + &icp->icmp_ip.ip_dst.s_addr, + &icp->icmp_gwaddr.s_addr); } if (drop_redirect) break; @@ -543,11 +532,8 @@ icmpdst.sin_addr = icp->icmp_gwaddr; #ifdef ICMPPRINTFS if (icmpprintfs) { - char buf[4 * sizeof "123"]; - strcpy(buf, inet_ntoa(icp->icmp_ip.ip_dst)); - - printf("redirect dst %s to %s\n", - buf, inet_ntoa(icp->icmp_gwaddr)); + printf("redirect dst %a to %a\n", + &icp->icmp_ip.ip_dst, &icp->icmp_gwaddr); } #endif icmpsrc.sin_addr = icp->icmp_ip.ip_dst; @@ -735,10 +721,8 @@ m->m_pkthdr.rcvif = (struct ifnet *)0; #ifdef ICMPPRINTFS if (icmpprintfs) { - char buf[4 * sizeof "123"]; - strcpy(buf, inet_ntoa(ip->ip_dst)); - printf("icmp_send dst %s src %s\n", - buf, inet_ntoa(ip->ip_src)); + printf("icmp_send dst %a src %a\n", + &ip->ip_dst, &ip->ip_src); } #endif bzero(&ro, sizeof ro); Index: netinet/ip_input.c =================================================================== RCS file: /home/ncvs/src/sys/netinet/ip_input.c,v retrieving revision 1.149 diff -u -r1.149 ip_input.c --- netinet/ip_input.c 2000/11/25 07:35:33 1.149 +++ netinet/ip_input.c 2000/12/10 14:33:21 @@ -1122,15 +1122,13 @@ if (!ip_dosourceroute) { if (ipforwarding) { - char buf[16]; /* aaa.bbb.ccc.ddd\0 */ /* * Acting as a router, so generate ICMP */ nosourcerouting: - strcpy(buf, inet_ntoa(ip->ip_dst)); log(LOG_WARNING, - "attempted source route from %s to %s\n", - inet_ntoa(ip->ip_src), buf); + "attempted source route from %a to %a\n", + &ip->ip_src, &ip->ip_dst); type = ICMP_UNREACH; code = ICMP_UNREACH_SRCFAIL; goto bad; Index: netinet/udp_usrreq.c =================================================================== RCS file: /home/ncvs/src/sys/netinet/udp_usrreq.c,v retrieving revision 1.78 diff -u -r1.78 udp_usrreq.c --- netinet/udp_usrreq.c 2000/11/01 16:56:33 1.78 +++ netinet/udp_usrreq.c 2000/12/10 14:36:32 @@ -340,12 +340,9 @@ ip->ip_dst, uh->uh_dport, 1, m->m_pkthdr.rcvif); if (inp == NULL) { if (log_in_vain) { - char buf[4*sizeof "123"]; - - strcpy(buf, inet_ntoa(ip->ip_dst)); log(LOG_INFO, - "Connection attempt to UDP %s:%d from %s:%d\n", - buf, ntohs(uh->uh_dport), inet_ntoa(ip->ip_src), + "Connection attempt to UDP %a:%d from %a:%d\n", + &ip->ip_dst, ntohs(uh->uh_dport), &ip->ip_src, ntohs(uh->uh_sport)); } udpstat.udps_noport++;