Diff below merge two slightly different versions of our kernel's
inet_ntoa(). I picked 8 rooms for ip4buf to be consistent with
what ip6_sprintf() does.

ok?

Index: netinet/ip_input.c
===================================================================
RCS file: /home/ncvs/src/sys/netinet/ip_input.c,v
retrieving revision 1.208
diff -u -p -r1.208 ip_input.c
--- netinet/ip_input.c  10 Apr 2013 08:50:59 -0000      1.208
+++ netinet/ip_input.c  15 Apr 2013 12:03:46 -0000
@@ -134,16 +134,26 @@ struct ipstat ipstat;
 
 int    in_ouraddr(struct in_addr, struct mbuf *);
 
+
+/* Allow 8 sucessive calls of inet_ntoa() before trashing the value. */
+static int     ip4round = 0;
+static char    ip4buf[8][16];
+
+/*
+ * Return a printable string for the IPv4 address.
+ */
 char *
-inet_ntoa(ina)
-       struct in_addr ina;
+inet_ntoa(struct in_addr ina)
 {
-       static char buf[4*sizeof "123"];
        unsigned char *ucp = (unsigned char *)&ina;
+       char *buf;
+
+       ip4round = (ip4round + 1) & 7;
+       buf = ip4buf[ip4round];
+
+       snprintf(buf, sizeof(ip4buf[0]), "%d.%d.%d.%d",
+           ucp[0] & 0xff, ucp[1] & 0xff, ucp[2] & 0xff, ucp[3] & 0xff);
 
-       snprintf(buf, sizeof buf, "%d.%d.%d.%d",
-           ucp[0] & 0xff, ucp[1] & 0xff,
-           ucp[2] & 0xff, ucp[3] & 0xff);
        return (buf);
 }
 
Index: netinet/ip_ipsp.c
===================================================================
RCS file: /home/ncvs/src/sys/netinet/ip_ipsp.c,v
retrieving revision 1.189
diff -u -p -r1.189 ip_ipsp.c
--- netinet/ip_ipsp.c   11 Apr 2013 12:06:25 -0000      1.189
+++ netinet/ip_ipsp.c   15 Apr 2013 12:03:46 -0000
@@ -981,21 +981,6 @@ tdb_add_inp(struct tdb *tdb, struct inpc
        }
 }
 
-/* Return a printable string for the IPv4 address. */
-char *
-inet_ntoa4(struct in_addr ina)
-{
-       static char buf[4][4 * sizeof "123" + 4];
-       unsigned char *ucp = (unsigned char *) &ina;
-       static int i = 3;
-
-       i = (i + 1) % 4;
-       snprintf(buf[i], sizeof buf[0], "%d.%d.%d.%d",
-           ucp[0] & 0xff, ucp[1] & 0xff,
-           ucp[2] & 0xff, ucp[3] & 0xff);
-       return (buf[i]);
-}
-
 /* Return a printable string for the address. */
 char *
 ipsp_address(union sockaddr_union sa)
@@ -1003,7 +988,7 @@ ipsp_address(union sockaddr_union sa)
        switch (sa.sa.sa_family) {
 #ifdef INET
        case AF_INET:
-               return inet_ntoa4(sa.sin.sin_addr);
+               return inet_ntoa(sa.sin.sin_addr);
 #endif /* INET */
 
 #ifdef INET6
Index: netinet/ip_ipsp.h
===================================================================
RCS file: /home/ncvs/src/sys/netinet/ip_ipsp.h,v
retrieving revision 1.154
diff -u -p -r1.154 ip_ipsp.h
--- netinet/ip_ipsp.h   11 Apr 2013 12:06:25 -0000      1.154
+++ netinet/ip_ipsp.h   15 Apr 2013 12:03:46 -0000
@@ -502,7 +502,6 @@ do {                                                        
                \
 
 /* Misc. */
 uint8_t        get_sa_require(struct inpcb *);
-char   *inet_ntoa4(struct in_addr);
 char   *ipsp_address(union sockaddr_union);
 
 /* TDB management routines */
Index: netinet/ipsec_input.c
===================================================================
RCS file: /home/ncvs/src/sys/netinet/ipsec_input.c,v
retrieving revision 1.113
diff -u -p -r1.113 ipsec_input.c
--- netinet/ipsec_input.c       11 Apr 2013 12:06:25 -0000      1.113
+++ netinet/ipsec_input.c       15 Apr 2013 12:03:46 -0000
@@ -407,7 +407,7 @@ ipsec_common_input_cb(struct mbuf *m, st
                                DPRINTF(("ipsec_common_input_cb(): inner "
                                    "source address %s doesn't correspond to "
                                    "expected proxy source %s, SA %s/%08x\n",
-                                   inet_ntoa4(ipn.ip_src),
+                                   inet_ntoa(ipn.ip_src),
                                    ipsp_address(tdbp->tdb_proxy),
                                    ipsp_address(tdbp->tdb_dst),
                                    ntohl(tdbp->tdb_spi)));
@@ -514,7 +514,7 @@ ipsec_common_input_cb(struct mbuf *m, st
                                DPRINTF(("ipsec_common_input_cb(): inner "
                                    "source address %s doesn't correspond to "
                                    "expected proxy source %s, SA %s/%08x\n",
-                                   inet_ntoa4(ipn.ip_src),
+                                   inet_ntoa(ipn.ip_src),
                                    ipsp_address(tdbp->tdb_proxy),
                                    ipsp_address(tdbp->tdb_dst),
                                    ntohl(tdbp->tdb_spi)));

Reply via email to