Changeset 32583
- Timestamp:
- Oct 27, 2011, 9:06:45 PM (15 years ago)
- Location:
- branches/eam_branches/ipp-20110906/Ohana/src/opihi
- Files:
-
- 3 edited
-
include/shell.h (modified) (1 diff)
-
lib.shell/SocketOps.c (modified) (5 diffs)
-
pantasks/pantasks_server.c.in (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20110906/Ohana/src/opihi/include/shell.h
r32569 r32583 184 184 185 185 /* socket functions */ 186 int InitServerSocket (SockAddress *Address );186 int InitServerSocket (SockAddress *Address, char *hostname, char *portinfo); 187 187 int WaitServerSocket (int InitSocket, SockAddress *Address); 188 188 int GetClientSocket (char *hostname, char *portinfo); -
branches/eam_branches/ipp-20110906/Ohana/src/opihi/lib.shell/SocketOps.c
r32569 r32583 1 1 # include "shell.h" 2 # include <unistd.h> 3 # define HOST_NAME_MAX 256 2 4 3 5 # define MY_PORT 2000 … … 11 13 static int *VALID; 12 14 13 int InitServerSocket (SockAddress *Address) { 14 15 int GetPortRange (int *start, int *stop, char *portinfo); 16 17 int InitServerSocket (SockAddress *Address, char *hostname, char *portinfo) { 18 19 int start, stop; 15 20 int status, InitSocket, length; 16 17 # if (0) 18 struct hostent *host; 19 char tmpline[80], hostip[80]; 20 21 host = gethostbyname (hostname); 22 bzero (hostip, 80); 23 for (i = 0; i < host[0].h_length; i++) { 24 sprintf (tmpline, "%u", (0xff & host[0].h_addr[i])); 25 strcat (hostip, tmpline); 26 if (i < host[0].h_length - 1) strcat (hostip, "."); 27 } 28 # endif 29 21 char myHostname[HOST_NAME_MAX]; 22 23 status = gethostname (myHostname, HOST_NAME_MAX); 24 25 fprintf (stderr, "target host: %s, real host: %s\n", hostname, myHostname); 26 27 GetPortRange (&start, &stop, portinfo); 28 29 fprintf (stderr, "using port range %d - %d\n", start, stop); 30 30 31 Address[0].sin_family = AF_INET; 31 Address[0].sin_port = MY_PORT;32 Address[0].sin_port = start; 32 33 Address[0].sin_addr.s_addr = INADDR_ANY; // use this line to bind any address / port? 33 34 34 35 retry_server: 35 36 # if (0)37 status = inet_aton (hostip, &Address[0].sin_addr);38 if (!status) {39 gprint (GP_ERR, "invalid address\n");40 exit (4);41 }42 # endif43 36 44 37 length = sizeof(Address[0]); … … 74 67 if (errno == EADDRINUSE) { 75 68 Address[0].sin_port ++; 76 if (Address[0].sin_port > MY_PORT + 10) {69 if (Address[0].sin_port > stop) { 77 70 fprintf (stderr, "failed to find a usable port\n"); 78 71 exit (6); … … 154 147 } 155 148 149 int GetPortRange (int *start, int *stop, char *portinfo) { 150 151 // portinfo is a port or port range of the form NN or NN:MM 152 *start = MY_PORT; 153 *stop = *start + 10; 154 if (!portinfo) return TRUE; 155 if (*portinfo == 0) return TRUE; 156 157 char *endptr; 158 *start = strtol (portinfo, &endptr, 0); 159 *stop = *start + 10; // default range of 10 160 if (!endptr) { 161 gprint (GP_ERR, "error in port range parsing : %s\n", portinfo); 162 exit (20); 163 } 164 if (endptr == portinfo) { 165 gprint (GP_ERR, "error in port range (%s), must be in form NN:MM or NN\n", portinfo); 166 exit (20); 167 } 168 if (*endptr == 0) return TRUE; 169 170 if (*endptr != ':') { 171 gprint (GP_ERR, "error in port range %s (wrong range separator, must be in form NN:MM)\n", portinfo); 172 exit (20); 173 } 174 char *ptr = endptr + 1; 175 *stop = strtol (ptr, &endptr, 0); 176 if (endptr == ptr) { 177 gprint (GP_ERR, "error in port range (%s), must be in form NN:MM or NN\n", portinfo); 178 exit (20); 179 } 180 if (*stop - *start > 20) { 181 gprint (GP_ERR, "error in port range (%s), range must be 20 or less\n", portinfo); 182 exit (20); 183 } 184 if (*stop < *start) { 185 gprint (GP_ERR, "error in port range (%s), stop must >= start\n", portinfo); 186 exit (20); 187 } 188 return TRUE; 189 } 190 156 191 int GetClientSocket (char *hostname, char *portinfo) { 157 192 158 int i, status, InitSocket, length ;193 int i, status, InitSocket, length, start, stop; 159 194 SockAddress Address; 160 195 struct hostent *host; … … 169 204 } 170 205 171 // portinfo is a port or port range of the form NN or NN:MM 172 int start = MY_PORT; 173 int stop = start + 10; 174 if (portinfo[0]) { 175 char *endptr; 176 start = strtol (portinfo, &endptr, 0); 177 stop = start + 10; // default range of 10 178 if (!endptr) { 179 gprint (GP_ERR, "error in port range parsing\n"); 180 exit (20); 181 } 182 if (endptr == portinfo) { 183 gprint (GP_ERR, "error in port range, must be in form NN:MM or NN\n"); 184 exit (20); 185 } 186 if (*endptr) { 187 if (*endptr != ":") { 188 gprint (GP_ERR, "error in port range (wrong range separator, must be in form NN:MM)\n"); 189 exit (20); 190 } 191 char *ptr = endptr + 1; 192 stop = strtol (ptr, &endptr, 0); 193 if (endptr == ptr) { 194 gprint (GP_ERR, "error in port range, must be in form NN:MM or NN\n"); 195 exit (20); 196 } 197 } 198 } 206 GetPortRange (&start, &stop, portinfo); 199 207 200 208 if (DEBUG) { -
branches/eam_branches/ipp-20110906/Ohana/src/opihi/pantasks/pantasks_server.c.in
r27999 r32583 18 18 int main (int argc, char **argv) { 19 19 20 char hostname[256], portinfo[256]; 20 21 char log_stdout[1024], log_stderr[1024]; 21 22 pthread_t JobsAndTasksThread; … … 100 101 pass them to the ListenClient thread */ 101 102 103 /* find the defined server hostname */ 104 if (VarConfig ("PANTASKS_SERVER", "%s", hostname) == NULL) { 105 gprint (GP_ERR, "pantasks server host undefined\n"); 106 exit (31); 107 } 108 109 /* is a port range defined? otherwise use the default */ 110 memset (portinfo, 0, 256); 111 VarConfig ("PANTASKS_SERVER_PORT", "%s", portinfo); 112 102 113 /* create the listening socket */ 103 InitSocket = InitServerSocket (&Address );114 InitSocket = InitServerSocket (&Address, hostname, portinfo); 104 115 105 116 InitPassword ();
Note:
See TracChangeset
for help on using the changeset viewer.
