From 0c927cdd8e6e05387fc5a9ffcb5dbe128d4ad749 Mon Sep 17 00:00:00 2001 From: Xin LI Date: Mon, 11 Jun 2007 07:21:21 +0000 Subject: [PATCH] Add inet_ntoa_r, a reentrant version of inet_ntoa. This is available on a lot of platforms, as well as libkern for years. Submitted by: "MQ" --- include/arpa/inet.h | 2 ++ lib/libc/inet/Symbol.map | 2 ++ lib/libc/inet/inet_ntoa.c | 8 ++++++++ lib/libc/net/Makefile.inc | 2 +- lib/libc/net/inet.3 | 13 ++++++++++++- 5 files changed, 25 insertions(+), 2 deletions(-) diff --git a/include/arpa/inet.h b/include/arpa/inet.h index fc5ef7d42937..fdc770862c31 100644 --- a/include/arpa/inet.h +++ b/include/arpa/inet.h @@ -130,6 +130,7 @@ struct in_addr { #define inet_cidr_ntop __inet_cidr_ntop #define inet_cidr_pton __inet_cidr_pton #define inet_ntoa __inet_ntoa +#define inet_ntoa_r __inet_ntoa_r #define inet_pton __inet_pton #define inet_ntop __inet_ntop #define inet_nsap_addr __inet_nsap_addr @@ -147,6 +148,7 @@ uint16_t ntohs(uint16_t); in_addr_t inet_addr(const char *); /*const*/ char *inet_ntoa(struct in_addr); +char *inet_ntoa_r(struct in_addr, char *buf); const char *inet_ntop(int, const void * __restrict, char * __restrict, socklen_t); int inet_pton(int, const char * __restrict, void * __restrict); diff --git a/lib/libc/inet/Symbol.map b/lib/libc/inet/Symbol.map index 13d1f477a26f..f188b137de94 100644 --- a/lib/libc/inet/Symbol.map +++ b/lib/libc/inet/Symbol.map @@ -25,6 +25,8 @@ FBSD_1.0 { inet_network; __inet_ntoa; inet_ntoa; + __inet_ntoa_r; + inet_ntoa_r; __inet_ntop; inet_ntop; __inet_pton; diff --git a/lib/libc/inet/inet_ntoa.c b/lib/libc/inet/inet_ntoa.c index 7e291456bcee..b75a983a523a 100644 --- a/lib/libc/inet/inet_ntoa.c +++ b/lib/libc/inet/inet_ntoa.c @@ -59,11 +59,19 @@ inet_ntoa(struct in_addr in) { return (ret); } +char * +inet_ntoa_r(struct in_addr in, char *buf) +{ + (void) inet_ntop(AF_INET, &in, buf, sizeof("255.255.255.255")); + return (buf); +} + /* * Weak aliases for applications that use certain private entry points, * and fail to include . */ #undef inet_ntoa __weak_reference(__inet_ntoa, inet_ntoa); +__weak_reference(__inet_ntoa_r, inet_ntoa_r); /*! \file */ diff --git a/lib/libc/net/Makefile.inc b/lib/libc/net/Makefile.inc index b9abe0fbe375..3592f50160ed 100644 --- a/lib/libc/net/Makefile.inc +++ b/lib/libc/net/Makefile.inc @@ -80,7 +80,7 @@ MLINKS+=if_indextoname.3 if_nametoindex.3 if_indextoname.3 if_nameindex.3 \ if_indextoname.3 if_freenameindex.3 MLINKS+=inet.3 addr.3 inet.3 inet_addr.3 inet.3 inet_aton.3 \ inet.3 inet_lnaof.3 inet.3 inet_makeaddr.3 inet.3 inet_netof.3 \ - inet.3 inet_network.3 inet.3 inet_ntoa.3 \ + inet.3 inet_network.3 inet.3 inet_ntoa.3 inet.3 inet_ntoa_r.3\ inet.3 inet_ntop.3 inet.3 inet_pton.3 \ inet.3 network.3 inet.3 ntoa.3 MLINKS+= sctp_send.3 sctp_sendx.3 diff --git a/lib/libc/net/inet.3 b/lib/libc/net/inet.3 index d721d9efeb95..d6428c90142c 100644 --- a/lib/libc/net/inet.3 +++ b/lib/libc/net/inet.3 @@ -28,7 +28,7 @@ .\" From: @(#)inet.3 8.1 (Berkeley) 6/4/93 .\" $FreeBSD$ .\" -.Dd March 21, 2007 +.Dd June 11, 2007 .Dt INET 3 .Os .Sh NAME @@ -36,6 +36,7 @@ .Nm inet_addr , .Nm inet_network , .Nm inet_ntoa , +.Nm inet_ntoa_r , .Nm inet_ntop , .Nm inet_pton , .Nm inet_makeaddr , @@ -57,6 +58,11 @@ .Fn inet_network "const char *cp" .Ft char * .Fn inet_ntoa "struct in_addr in" +.Ft char * +.Fo inet_ntoa_r +.Fa "struct in_addr in" +.Fa "char *buf" +.Fc .Ft const char * .Fo inet_ntop .Fa "int af" @@ -147,6 +153,11 @@ string representing the address in .Ql .\& notation. The routine +.Fn inet_ntoa_r +is the reentrant version of +.Fn inet_ntoa . +It requires a buffer large enough to contain an IPv4 address. +The routine .Fn inet_makeaddr takes an Internet network number and a local network address and constructs an Internet address