$NetBSD: patch-ab,v 1.3 2005/05/29 14:38:33 wiz Exp $

--- glunix/src/comm/ccomm_net.cc.orig	1997-10-15 21:24:52.000000000 +0200
+++ glunix/src/comm/ccomm_net.cc
@@ -73,7 +73,8 @@
 #include <netinet/tcp.h>
 #include <sys/socket.h>
 #include <unistd.h>
-#include <sys/systeminfo.h>
+/*#include <sys/systeminfo.h>*/
+#include <sys/uio.h>
 
 #include "glib/types.h"
 #include "cdebug.h"
@@ -258,7 +259,7 @@ Comm_GetIpByHostName(char *hostName)
 
     h = gethostbyname(hostName);
     if (!h) {
-	DE("Cannot resolve host name: %s\n", strerror(errno));
+	DE("Cannot resolve host name: %s %s\n",hostName, strerror(errno));
 	// BUGBUG set error code
 	return 0;
     }
@@ -328,14 +329,15 @@ Comm_GetMyIpAddr(uint *ipPtr)
     }
 
     // Get my IP address
-    if (sysinfo(SI_HOSTNAME, hostName, sizeof(hostName)-1) < 0) {
-	DE("sysinfo(SI_HOSTNAME): %s\n", strerror(errno));
-	*ipPtr = 0;
-	return False;
-    }
+//    if (sysinfo(SI_HOSTNAME, hostName, sizeof(hostName)-1) < 0) {
+//	DE("sysinfo(SI_HOSTNAME): %s\n", strerror(errno));
+//	*ipPtr = 0;
+//	return False;
+//    }
+    gethostname(hostName,sizeof(hostName));
     h = gethostbyname(hostName);
     if (!h) {
-	DE("Cannot resolve host name: %s\n", strerror(errno));
+	DE("Cannot resolve host name: %s %s\n",hostName, strerror(errno));
 	// BUGBUG error code
 	*ipPtr = 0;
 	return False;
@@ -365,7 +367,7 @@ Bool
 Comm_SocketGetPort(int sock, int *port)
 {
     struct sockaddr_in  s;
-    int len;
+    socklen_t len;
 
     ASSERT(port != NULL);
 
@@ -376,7 +378,11 @@ Comm_SocketGetPort(int sock, int *port)
 	return False;
     }
     // use ntohs to convert it back to host order for pc's
+#ifdef L_ENDIAN
+    *port = s.sin_port;
+#else
     *port = ntohs(s.sin_port);
+#endif
     return True;
 }
 
@@ -397,7 +403,7 @@ int
 Comm_SocketGetPeerPort(int sock)
 {
     struct sockaddr_in  s;
-    int                 len;
+    socklen_t           len;
 
     len = sizeof(struct sockaddr_in);
     if (getpeername(sock, (struct sockaddr *)&s, &len)
@@ -425,7 +431,7 @@ Bool
 Comm_SocketGetPeerIpAddr(int sock, uint *ipAddrPtr)
 {
     struct sockaddr_in  s;
-    int                 len;
+    socklen_t           len;
 
     ASSERT(ipAddrPtr != NULL);
     *ipAddrPtr = 0;
@@ -435,8 +441,11 @@ Comm_SocketGetPeerIpAddr(int sock, uint 
 	DE("getpeername: %s\n", strerror(errno));
 	return False;
     }
-
+#ifdef L_ENDIAN
+    *ipAddrPtr = s.sin_addr.s_addr;
+#else
     *ipAddrPtr = ntohl(s.sin_addr.s_addr);
+#endif
     return True;
 }
 
@@ -528,8 +537,13 @@ Comm_CreateListenSock(int port, int *soc
 
     // Bind the socket to a well-known port
     s.sin_family = AF_INET;
+#ifdef L_ENDIAN
+    s.sin_port = port;
+    s.sin_addr.s_addr = INADDR_ANY;
+#else
     s.sin_port = htons(port);
     s.sin_addr.s_addr = htonl(INADDR_ANY);
+#endif
 
     val = bind(sock, (struct sockaddr *) &s, sizeof(s));
     if (val < 0) {
@@ -637,9 +651,13 @@ Comm_Connect(int *sockPtr, uint ipAddr, 
 
     // Now connect to the requested host
     s.sin_family = AF_INET ;
+#ifdef L_ENDIAN
+    s.sin_port = port;
+    s.sin_addr.s_addr = ipAddr;
+#else
     s.sin_port = htons(port);
     s.sin_addr.s_addr = htonl(ipAddr);
-
+#endif
     if (connect(sock, (struct sockaddr *) &s, sizeof(s)) < 0) {
 	if (errno == EINTR) {
 	    while(1) {
@@ -700,7 +718,7 @@ Comm_Accept(int listenFd, int *newFd)
 {
     struct sockaddr_in  s;
     int                 fd;
-    int                 addrLen;
+    socklen_t           addrLen;
 
     ASSERT(newFd != NULL);
     *newFd = -1;
@@ -754,7 +772,7 @@ Comm_SureWrite(int sock, void *bufPtr, i
     ASSERT(bufLen > 0);
 
     errno = 0; // BUGBUG, we should do this for ALL related funcs
-    for (; bufLen; bufLen -= val, bufPtr += val) {
+    for (; bufLen; bufLen -= val, (char *)bufPtr += val) {
 	val = write(sock, (const char *)bufPtr, bufLen);
 
 	writeErrno = errno;
@@ -880,7 +898,7 @@ Comm_SureWriteV(int sock, struct iovec *
 		vecLen--;
 	    } else {
 		vecPtr[0].iov_len -= val;
-		vecPtr[0].iov_base += val;
+		(char *)vecPtr[0].iov_base += val;
 		break;
 	    }
 	}
@@ -915,7 +933,7 @@ Comm_SureRead(int sock, void *bufPtr, in
     ASSERT(bufLen > 0);
 
     errno = 0; // BUGBUG, we should do this for ALL related funcs
-    for (; bufLen; bufLen -= val, bufPtr += val) {
+    for (; bufLen; bufLen -= val, (char *)bufPtr += val) {
 	val = read(sock, (char *)bufPtr, bufLen);
 	readErrno = errno;
 	D9("Read from sock %d, bufPtr %08x, bufLen %d, bytes %d\n",
@@ -1045,7 +1063,7 @@ Comm_SureReadV(int sock, struct iovec *v
 		D3("Read fewer bytes than asked for:%d < %d\n",
 		   totRead, vecPtr[currVec].iov_len);
 		vecPtr[currVec].iov_len -= val;
-		vecPtr[currVec].iov_base += val;
+		(char *)vecPtr[currVec].iov_base += val;
 		break;
 	    }
 	}
