This is the mail archive of the
ecos-patches@sources.redhat.com
mailing list for the eCos project.
Re: thread safe inet_ntoa
- From: Gary Thomas <gary at chez-thomas dot org>
- To: Matt Jerdonek <maj1224 at yahoo dot com>
- Cc: Patches eCos <ecos-patches at sources dot redhat dot com>
- Date: 10 Dec 2003 05:09:36 -0700
- Subject: Re: thread safe inet_ntoa
- Organization:
- References: <20031209191432.36941.qmail@web14207.mail.yahoo.com>
On Tue, 2003-12-09 at 12:14, Matt Jerdonek wrote:
> Copied from FreeBSD ...
Thanks for bringing this up. However, rather than duplicating code,
I think the attached patch is a better approach.
--
Gary Thomas <gary@chez-thomas.org>
Index: net/bsd_tcpip/current/ChangeLog
===================================================================
RCS file: /misc/cvsfiles/ecos-opt/net/net/bsd_tcpip/current/ChangeLog,v
retrieving revision 1.37
diff -u -5 -p -r1.37 ChangeLog
--- net/bsd_tcpip/current/ChangeLog 22 Nov 2003 12:59:20 -0000 1.37
+++ net/bsd_tcpip/current/ChangeLog 10 Dec 2003 12:05:56 -0000
@@ -1,5 +1,9 @@
+2003-12-10 Gary Thomas <gary@mlbassoc.com>
+
+ * include/netinet/in.h: Prototype for inet_ntoa_r()
+
2003-11-22 Andrew Lunn <andrew.lunn@ascom.ch>
* include/net/if_gif.h include/net/if_sec.h include/net/zlib.h
include/netinet/ip_ecn.h include/netinet6/ah.h
include/netinet6/esp.h include/netinet6/esp_rijndael.h
Index: net/bsd_tcpip/current/include/netinet/in.h
===================================================================
RCS file: /misc/cvsfiles/ecos-opt/net/net/bsd_tcpip/current/include/netinet/in.h,v
retrieving revision 1.4
diff -u -5 -p -r1.4 in.h
--- net/bsd_tcpip/current/include/netinet/in.h 24 Jul 2003 18:04:24 -0000 1.4
+++ net/bsd_tcpip/current/include/netinet/in.h 10 Dec 2003 12:00:07 -0000
@@ -515,9 +515,10 @@ u_int in_cksum_hdr __P((const struct ip
u_short in_cksum_skip __P((struct mbuf *, int, int));
u_short in_pseudo __P((u_int32_t, u_int32_t, u_int32_t));
u_short in_addword __P((u_short, u_short));
int in_localaddr __P((struct in_addr));
char *inet_ntoa __P((struct in_addr));
+char *inet_ntoa_r __P((struct in_addr, char *));
#endif
#endif
Index: net/common/current/ChangeLog
===================================================================
RCS file: /misc/cvsfiles/ecos-opt/net/net/common/current/ChangeLog,v
retrieving revision 1.53
diff -u -5 -p -r1.53 ChangeLog
--- net/common/current/ChangeLog 27 Nov 2003 15:24:13 -0000 1.53
+++ net/common/current/ChangeLog 10 Dec 2003 12:08:01 -0000
@@ -1,5 +1,13 @@
+2003-12-10 Gary Thomas <gary@mlbassoc.com>
+
+ * src/inet_ntoa.c: Add thread safe inet_ntoa_r() and change
+ inet_ntoa() to use it. Inspired by Matt Jerdonek.
+
+ * include/net/netdb.h:
+ * include/arpa/inet.h: Prototype for inet_ntoa_r()
+
2003-11-25 Manu Sharma <manu.sharma@ascom.com>
* tests/bridge.c: Changes to enable Spanning Tree Protocol if the
corresponding CDL component is enabled.
Index: net/common/current/include/arpa/inet.h
===================================================================
RCS file: /misc/cvsfiles/ecos-opt/net/net/common/current/include/arpa/inet.h,v
retrieving revision 1.1
diff -u -5 -p -r1.1 inet.h
--- net/common/current/include/arpa/inet.h 20 May 2002 22:25:03 -0000 1.1
+++ net/common/current/include/arpa/inet.h 10 Dec 2003 12:01:14 -0000
@@ -65,8 +65,9 @@ extern int inet_aton __P((
extern unsigned long inet_lnaof __P((struct in_addr));
extern struct in_addr inet_makeaddr __P((u_long , u_long));
extern unsigned long inet_netof __P((struct in_addr));
extern unsigned long inet_network __P((const char *));
extern char *inet_ntoa __P((struct in_addr));
+extern char *inet_ntoa_r __P((struct in_addr, char *));
__END_DECLS
#endif /* !_ARPA_INET_H_ */
Index: net/common/current/include/net/netdb.h
===================================================================
RCS file: /misc/cvsfiles/ecos-opt/net/net/common/current/include/net/netdb.h,v
retrieving revision 1.4
diff -u -5 -p -r1.4 netdb.h
--- net/common/current/include/net/netdb.h 15 Jul 2003 08:45:16 -0000 1.4
+++ net/common/current/include/net/netdb.h 10 Dec 2003 12:00:05 -0000
@@ -133,10 +133,11 @@ int getnameinfo (const struct sockaddr *
unsigned int flags);
// Miscellaneous address manipulation functions
#include <netinet/in.h>
char *inet_ntoa(struct in_addr);
+char *inet_ntoa_r(struct in_addr, char *);
char *inet_ntop(int af, const char *src, char *dst, size_t len);
int inet_pton(int af, const char *src, char *dst);
char *_inet_ntop(struct sockaddr *sa, char *dst, size_t len);
u_int16_t _inet_port(struct sockaddr *sa);
Index: net/common/current/src/inet_ntoa.c
===================================================================
RCS file: /misc/cvsfiles/ecos-opt/net/net/common/current/src/inet_ntoa.c,v
retrieving revision 1.1
diff -u -5 -p -r1.1 inet_ntoa.c
--- net/common/current/src/inet_ntoa.c 20 May 2002 22:25:05 -0000 1.1
+++ net/common/current/src/inet_ntoa.c 10 Dec 2003 11:51:24 -0000
@@ -53,18 +53,23 @@
#include <sys/param.h>
#include <netinet/in.h>
char *
-inet_ntoa(struct in_addr ina)
+inet_ntoa_r(struct in_addr ina, char *buf)
{
- static char buf[4*sizeof "123"];
- unsigned char *ucp = (unsigned char *)&ina;
+ unsigned char *ucp = (unsigned char *)&ina;
+ diag_sprintf(buf, "%d.%d.%d.%d",
+ ucp[0] & 0xff,
+ ucp[1] & 0xff,
+ ucp[2] & 0xff,
+ ucp[3] & 0xff);
+ return buf;
+}
- diag_sprintf(buf, "%d.%d.%d.%d",
- ucp[0] & 0xff,
- ucp[1] & 0xff,
- ucp[2] & 0xff,
- ucp[3] & 0xff);
- return buf;
+char *
+inet_ntoa(struct in_addr ina)
+{
+ static char buf[sizeof "123.456.789.012"];
+ return inet_ntoa_r(ina, buf);
}
Index: net/tcpip/current/ChangeLog
===================================================================
RCS file: /misc/cvsfiles/ecos-opt/net/net/tcpip/current/ChangeLog,v
retrieving revision 1.45
diff -u -5 -p -r1.45 ChangeLog
--- net/tcpip/current/ChangeLog 27 Nov 2003 15:25:16 -0000 1.45
+++ net/tcpip/current/ChangeLog 10 Dec 2003 12:08:25 -0000
@@ -1,5 +1,9 @@
+2003-12-10 Gary Thomas <gary@mlbassoc.com>
+
+ * include/netinet/in.h: Prototype for inet_ntoa_r()
+
2003-11-25 Manu Sharma <manu.sharma@ascom.com>
* src/sys/net/bridgestp.c: Code for Spanning Tree Protocol (STP).
* cdl/openbsd_net.cdl: Changes make provisions for STP code.
* doc/openbsd.sgml: Same.
Index: net/tcpip/current/include/netinet/in.h
===================================================================
RCS file: /misc/cvsfiles/ecos-opt/net/net/tcpip/current/include/netinet/in.h,v
retrieving revision 1.2
diff -u -5 -p -r1.2 in.h
--- net/tcpip/current/include/netinet/in.h 20 May 2002 22:25:16 -0000 1.2
+++ net/tcpip/current/include/netinet/in.h 10 Dec 2003 12:00:06 -0000
@@ -672,10 +672,11 @@ int in_broadcast __P((struct in_addr,
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));
+char *inet_ntoa_r __P((struct in_addr, char *));
#define satosin(sa) ((struct sockaddr_in *)(sa))
#define sintosa(sin) ((struct sockaddr *)(sin))
#define ifatoia(ifa) ((struct in_ifaddr *)(ifa))
#endif