From b1aeca30082e1a563c5c2b19b0364fce4d5f119f Mon Sep 17 00:00:00 2001 From: deraadt Date: Tue, 28 Nov 1995 22:42:55 +0000 Subject: [PATCH] add inet_ntoa() to the kernel. use it to log nicer messages. idea from freebsd --- sys/netinet/if_ether.c | 12 +++++++----- sys/netinet/in.h | 1 + sys/netinet/ip_icmp.c | 30 +++++++++++++++++++++--------- sys/netinet/ip_input.c | 30 ++++++++++++++++++++++-------- 4 files changed, 51 insertions(+), 22 deletions(-) diff --git a/sys/netinet/if_ether.c b/sys/netinet/if_ether.c index eb53910486c..bb0a8d480d6 100644 --- a/sys/netinet/if_ether.c +++ b/sys/netinet/if_ether.c @@ -465,14 +465,14 @@ in_arpinput(m) 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 %x!\n", - ntohl(isaddr.s_addr)); + "arp: ether address is broadcast for IP address %s!\n", + inet_ntoa(isaddr)); goto out; } if (isaddr.s_addr == myaddr.s_addr) { log(LOG_ERR, - "duplicate IP address %08x sent from ethernet address %s\n", - ntohl(isaddr.s_addr), ether_sprintf(ea->arp_sha)); + "duplicate IP address %s sent from ethernet address %s\n", + inet_ntoa(isaddr), ether_sprintf(ea->arp_sha)); itaddr = myaddr; goto reply; } @@ -576,7 +576,9 @@ arplookup(addr, create, proxy) if ((rt->rt_flags & RTF_GATEWAY) || (rt->rt_flags & RTF_LLINFO) == 0 || rt->rt_gateway->sa_family != AF_LINK) { if (create) - log(LOG_DEBUG, "arplookup: unable to enter address for %x\n", ntohl(addr)); + log(LOG_DEBUG, + "arplookup: unable to enter address for %s\n", + inet_ntoa(sin.sin_addr)); return (0); } return ((struct llinfo_arp *)rt->rt_llinfo); diff --git a/sys/netinet/in.h b/sys/netinet/in.h index deda496b68e..936954768fb 100644 --- a/sys/netinet/in.h +++ b/sys/netinet/in.h @@ -262,6 +262,7 @@ int in_canforward __P((struct in_addr)); int in_cksum __P((struct mbuf *, int)); int in_localaddr __P((struct in_addr)); void in_socktrim __P((struct sockaddr_in *)); +char *inet_ntoa __P((struct in_addr)); #define satosin(sa) ((struct sockaddr_in *)(sa)) #define sintosa(sin) ((struct sockaddr *)(sin)) diff --git a/sys/netinet/ip_icmp.c b/sys/netinet/ip_icmp.c index e0d9ee6f7c7..ad8dbddd243 100644 --- a/sys/netinet/ip_icmp.c +++ b/sys/netinet/ip_icmp.c @@ -190,10 +190,13 @@ icmp_input(m, hlen) * that not corrupted and of at least minimum length. */ #ifdef ICMPPRINTFS - if (icmpprintfs) - printf("icmp_input from %x to %x, len %d\n", - ntohl(ip->ip_src.s_addr), ntohl(ip->ip_dst.s_addr), - icmplen); + if (icmpprintfs) { + char buf[4*sizeof "123"]; + + strcpy(buf, inet_ntoa(ip->ip_dst)); + printf("icmp_input from %s to %s, len %d\n", + inet_ntoa(ip->ip_src), buf, icmplen); + } #endif if (icmplen < ICMP_MINLEN) { icmpstat.icps_tooshort++; @@ -367,9 +370,13 @@ reflect: icmpgw.sin_addr = ip->ip_src; icmpdst.sin_addr = icp->icmp_gwaddr; #ifdef ICMPPRINTFS - if (icmpprintfs) - printf("redirect dst %x to %x\n", icp->icmp_ip.ip_dst, - icp->icmp_gwaddr); + 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)); + } #endif icmpsrc.sin_addr = icp->icmp_ip.ip_dst; rtredirect(sintosa(&icmpsrc), sintosa(&icmpdst), @@ -545,8 +552,13 @@ icmp_send(m, opts) m->m_data -= hlen; m->m_len += hlen; #ifdef ICMPPRINTFS - if (icmpprintfs) - printf("icmp_send dst %x src %x\n", ip->ip_dst, ip->ip_src); + 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)); + } #endif (void) ip_output(m, opts, NULL, 0, NULL); } diff --git a/sys/netinet/ip_input.c b/sys/netinet/ip_input.c index 991bfe8fe35..100f1865298 100644 --- a/sys/netinet/ip_input.c +++ b/sys/netinet/ip_input.c @@ -83,6 +83,18 @@ int ipqmaxlen = IFQ_MAXLEN; struct in_ifaddrhead in_ifaddr; struct ifqueue ipintrq; +char * +inet_ntoa(ina) + struct in_addr ina; +{ + static char buf[4*sizeof "123"]; + unsigned char *ucp = (unsigned char *)&ina; + + sprintf(buf, "%d.%d.%d.%d", ucp[0] & 0xff, ucp[1] & 0xff, + ucp[2] & 0xff, ucp[3] & 0xff); + return (buf); +} + /* * We need to save the IP options in case a protocol wants to respond * to an incoming packet over the same route if the packet got here @@ -357,10 +369,10 @@ found: ip->ip_len -= hlen; ((struct ipasfrag *)ip)->ipf_mff &= ~1; if (ip->ip_off & IP_MF) { - /* - * Make sure that fragments have a data length + /* + * Make sure that fragments have a data length * that's a non-zero multiple of 8 bytes. - */ + */ if (ip->ip_len == 0 || (ip->ip_len & 0x7) != 0) { ipstat.ips_badfrags++; goto bad; @@ -706,10 +718,12 @@ ip_dooptions(m) } if (!ip_dosourceroute) { + char buf[4*sizeof "123"]; + + strcpy(buf, inet_ntoa(ip->ip_dst)); log(LOG_WARNING, - "attempted source route from %x to %x\n", - ntohl(ip->ip_src.s_addr), - ntohl(ip->ip_dst.s_addr)); + "attempted source route from %s to %s\n", + inet_ntoa(ip->ip_src), buf); type = ICMP_UNREACH; code = ICMP_UNREACH_SRCFAIL; goto bad; @@ -1018,8 +1032,8 @@ ip_forward(m, srcrt) dest = 0; #ifdef DIAGNOSTIC if (ipprintfs) - printf("forward: src %x dst %x ttl %x\n", ip->ip_src, - ip->ip_dst, ip->ip_ttl); + printf("forward: src %lx dst %x ttl %x\n", ip->ip_src.s_addr, + ip->ip_dst.s_addr, ip->ip_ttl); #endif if (m->m_flags & M_BCAST || in_canforward(ip->ip_dst) == 0) { ipstat.ips_cantforward++; -- 2.20.1