summaryrefslogtreecommitdiff
path: root/parallel/glunix/patches/patch-ab
blob: 3221bc3518672202771b11ef37894deaccc0b185 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
$NetBSD: patch-ab,v 1.2 2003/03/31 03:46:30 jmc Exp $

--- glunix/src/comm/ccomm_net.cc.orig	Wed Oct 15 19:24:52 1997
+++ glunix/src/comm/ccomm_net.cc	Sun Mar 30 21:48:41 2003
@@ -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 @@
 
     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 @@
     }
 
     // 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 @@
 Comm_SocketGetPort(int sock, int *port)
 {
     struct sockaddr_in  s;
-    int len;
+    socklen_t len;
 
     ASSERT(port != NULL);
 
@@ -376,7 +378,11 @@
 	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 @@
 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 @@
 Comm_SocketGetPeerIpAddr(int sock, uint *ipAddrPtr)
 {
     struct sockaddr_in  s;
-    int                 len;
+    socklen_t           len;
 
     ASSERT(ipAddrPtr != NULL);
     *ipAddrPtr = 0;
@@ -435,8 +441,11 @@
 	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 @@
 
     // 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 @@
 
     // 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 @@
 {
     struct sockaddr_in  s;
     int                 fd;
-    int                 addrLen;
+    socklen_t           addrLen;
 
     ASSERT(newFd != NULL);
     *newFd = -1;
@@ -754,7 +772,7 @@
     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 @@
 		vecLen--;
 	    } else {
 		vecPtr[0].iov_len -= val;
-		vecPtr[0].iov_base += val;
+		(char *)vecPtr[0].iov_base += val;
 		break;
 	    }
 	}
@@ -915,7 +933,7 @@
     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 @@
 		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;
 	    }
 	}