[enet-cvs] CVS: enet Makefile,1.1,1.2 unix.c,1.3,1.4
Lee Salzman
enet-discuss@lists.puremagic.com
Mon, 28 Oct 2002 12:06:02 -0700
Update of /home/enet/cvsroot/enet
In directory sferik:/tmp/cvs-serv22136
Modified Files:
Makefile unix.c
Log Message:
Added fixes to make enet_address_set_host and enet_address_get_host reentrant.
Index: Makefile
===================================================================
RCS file: /home/enet/cvsroot/enet/Makefile,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Makefile 2002/10/13 01:59:54 1.1
+++ Makefile 2002/10/28 19:05:59 1.2
@@ -1,6 +1,6 @@
CC=gcc
-COPTFLAGS=-ansi -Wall -pedantic -O3 -fomit-frame-pointer
-CFLAGS=$(COPTFLAGS) -Iinclude -DHAS_POLL -DHAS_FCNTL -DHAS_MSGHDR_FLAGS
+COPTFLAGS=-Wall -pedantic -O3 -fomit-frame-pointer
+CFLAGS=$(COPTFLAGS) -Iinclude -DHAS_GETHOSTBYNAME_R -DHAS_GETHOSTBYADDR_R -DHAS_POLL -DHAS_FCNTL -DHAS_MSGHDR_FLAGS
OBJS= \
host.o \
list.o \
Index: unix.c
===================================================================
RCS file: /home/enet/cvsroot/enet/unix.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- unix.c 2002/07/28 21:26:06 1.3
+++ unix.c 2002/10/28 19:05:59 1.4
@@ -59,9 +59,21 @@
int
enet_address_set_host (ENetAddress * address, const char * name)
{
- struct hostent * hostEntry;
+ struct hostent * hostEntry = NULL;
+#ifdef HAS_GETHOSTBYNAME_R
+ struct hostent hostData;
+ char buffer [2048];
+ int errnum;
+#ifdef linux
+ gethostbyname_r (name, & hostData, buffer, sizeof (buffer), & hostEntry, & errnum);
+#else
+ hostEntry = gethostbyname_r (name, & hostData, buffer, sizeof (buffer), & errnum);
+#endif
+#else
hostEntry = gethostbyname (name);
+#endif
+
if (hostEntry == NULL ||
hostEntry -> h_addrtype != AF_INET)
return -1;
@@ -76,10 +88,24 @@
{
struct in_addr in;
struct hostent * hostEntry;
-
+#ifdef HAS_GETHOSTBYADDR_R
+ struct hostent hostData;
+ char buffer [2048];
+ int errnum;
+
in.s_addr = address -> host;
-
+
+#ifdef linux
+ gethostbyaddr_r ((char *) & in, sizeof (struct in_addr), AF_INET, & hostData, buffer, sizeof (buffer), & hostEntry, & errnum);
+#else
+ hostEntry = gethostbyaddr_r ((char *) & in, sizeof (struct in_addr), AF_INET, & hostData, buffer, sizeof (buffer), & errnum);
+#endif
+#else
+ in.s_addr = address -> host;
+
hostEntry = gethostbyaddr ((char *) & in, sizeof (struct in_addr), AF_INET);
+#endif
+
if (hostEntry == NULL)
return -1;