Index: /branches/eam_branches/ipp-20110906/Ohana/src/opihi/include/shell.h
===================================================================
--- /branches/eam_branches/ipp-20110906/Ohana/src/opihi/include/shell.h	(revision 32582)
+++ /branches/eam_branches/ipp-20110906/Ohana/src/opihi/include/shell.h	(revision 32583)
@@ -184,5 +184,5 @@
 
 /* socket functions */
-int InitServerSocket (SockAddress *Address);
+int InitServerSocket (SockAddress *Address, char *hostname, char *portinfo);
 int WaitServerSocket (int InitSocket, SockAddress *Address);
 int GetClientSocket (char *hostname, char *portinfo);
Index: /branches/eam_branches/ipp-20110906/Ohana/src/opihi/lib.shell/SocketOps.c
===================================================================
--- /branches/eam_branches/ipp-20110906/Ohana/src/opihi/lib.shell/SocketOps.c	(revision 32582)
+++ /branches/eam_branches/ipp-20110906/Ohana/src/opihi/lib.shell/SocketOps.c	(revision 32583)
@@ -1,3 +1,5 @@
 # include "shell.h"
+# include <unistd.h>
+# define HOST_NAME_MAX 256
 
 # define MY_PORT 2000
@@ -11,34 +13,25 @@
 static int *VALID;
 
-int InitServerSocket (SockAddress *Address) {
-
+int GetPortRange (int *start, int *stop, char *portinfo);
+
+int InitServerSocket (SockAddress *Address, char *hostname, char *portinfo) {
+
+  int start, stop;
   int status, InitSocket, length;
-
-# if (0)
-  struct hostent  *host;
-  char tmpline[80], hostip[80];
-
-  host = gethostbyname (hostname);
-  bzero (hostip, 80);
-  for (i = 0; i < host[0].h_length; i++) {
-    sprintf (tmpline, "%u", (0xff & host[0].h_addr[i]));
-    strcat (hostip, tmpline);
-    if (i < host[0].h_length - 1) strcat (hostip, ".");
-  }
-# endif
-  
+  char myHostname[HOST_NAME_MAX];
+
+  status = gethostname (myHostname, HOST_NAME_MAX);
+
+  fprintf (stderr, "target host: %s, real host: %s\n", hostname, myHostname);
+
+  GetPortRange (&start, &stop, portinfo);
+
+  fprintf (stderr, "using port range %d - %d\n", start, stop);
+
   Address[0].sin_family = AF_INET;
-  Address[0].sin_port   = MY_PORT;
+  Address[0].sin_port   = start;
   Address[0].sin_addr.s_addr = INADDR_ANY; // use this line to bind any address / port?
 
 retry_server:
-
-# if (0)  
-  status = inet_aton (hostip, &Address[0].sin_addr);
-  if (!status) {
-    gprint (GP_ERR, "invalid address\n");
-    exit (4);
-  }
-# endif
 
   length = sizeof(Address[0]);
@@ -74,5 +67,5 @@
     if (errno == EADDRINUSE) {
 	Address[0].sin_port ++;
-	if (Address[0].sin_port > MY_PORT + 10) {
+	if (Address[0].sin_port > stop) {
 	  fprintf (stderr, "failed to find a usable port\n");
 	  exit (6);
@@ -154,7 +147,49 @@
 }
 
+int GetPortRange (int *start, int *stop, char *portinfo) {
+
+  // portinfo is a port or port range of the form NN or NN:MM
+  *start = MY_PORT;
+  *stop = *start + 10;
+  if (!portinfo) return TRUE;
+  if (*portinfo == 0) return TRUE;
+
+  char *endptr;
+  *start = strtol (portinfo, &endptr, 0);
+  *stop = *start + 10; // default range of 10
+  if (!endptr) {
+    gprint (GP_ERR, "error in port range parsing : %s\n", portinfo);
+    exit (20);
+  }
+  if (endptr == portinfo) {
+    gprint (GP_ERR, "error in port range (%s), must be in form NN:MM or NN\n", portinfo);
+    exit (20);
+  }
+  if (*endptr == 0) return TRUE;
+
+  if (*endptr != ':') {
+    gprint (GP_ERR, "error in port range %s (wrong range separator, must be in form NN:MM)\n", portinfo);
+    exit (20);
+  }
+  char *ptr = endptr + 1;
+  *stop = strtol (ptr, &endptr, 0);
+  if (endptr == ptr)  {
+    gprint (GP_ERR, "error in port range (%s), must be in form NN:MM or NN\n", portinfo);
+    exit (20);
+  }
+  if (*stop - *start > 20) {
+    gprint (GP_ERR, "error in port range (%s), range must be 20 or less\n", portinfo);
+    exit (20);
+  }
+  if (*stop < *start) {
+    gprint (GP_ERR, "error in port range (%s), stop must >= start\n", portinfo);
+    exit (20);
+  }
+  return TRUE;
+}
+
 int GetClientSocket (char *hostname, char *portinfo) {
 
-  int i, status, InitSocket, length;
+  int i, status, InitSocket, length, start, stop;
   SockAddress Address;
   struct hostent  *host;
@@ -169,32 +204,5 @@
   }
 
-  // portinfo is a port or port range of the form NN or NN:MM
-  int start = MY_PORT;
-  int stop = start + 10;
-  if (portinfo[0]) {
-      char *endptr;
-      start = strtol (portinfo, &endptr, 0);
-      stop = start + 10; // default range of 10
-      if (!endptr) {
-	  gprint (GP_ERR, "error in port range parsing\n");
-	  exit (20);
-      }
-      if (endptr == portinfo) {
-	  gprint (GP_ERR, "error in port range, must be in form NN:MM or NN\n");
-	  exit (20);
-      }
-      if (*endptr) {
-	  if (*endptr != ":") {
-	      gprint (GP_ERR, "error in port range (wrong range separator, must be in form NN:MM)\n");
-	      exit (20);
-	  }
-	  char *ptr = endptr + 1;
-	  stop = strtol (ptr, &endptr, 0);
-	  if (endptr == ptr)  {
-	      gprint (GP_ERR, "error in port range, must be in form NN:MM or NN\n");
-	      exit (20);
-	  }
-      }
-  }      
+  GetPortRange (&start, &stop, portinfo);
 
   if (DEBUG) {
Index: /branches/eam_branches/ipp-20110906/Ohana/src/opihi/pantasks/pantasks_server.c.in
===================================================================
--- /branches/eam_branches/ipp-20110906/Ohana/src/opihi/pantasks/pantasks_server.c.in	(revision 32582)
+++ /branches/eam_branches/ipp-20110906/Ohana/src/opihi/pantasks/pantasks_server.c.in	(revision 32583)
@@ -18,4 +18,5 @@
 int main (int argc, char **argv) {
   
+  char hostname[256], portinfo[256];
   char log_stdout[1024], log_stderr[1024];
   pthread_t JobsAndTasksThread;
@@ -100,6 +101,16 @@
      pass them to the ListenClient thread */
 
+  /* find the defined server hostname */
+  if (VarConfig ("PANTASKS_SERVER", "%s", hostname) == NULL) {
+    gprint (GP_ERR, "pantasks server host undefined\n");
+    exit (31);
+  }
+
+  /* is a port range defined? otherwise use the default */
+  memset (portinfo, 0, 256);
+  VarConfig ("PANTASKS_SERVER_PORT", "%s", portinfo);
+
   /* create the listening socket */
-  InitSocket = InitServerSocket (&Address);
+  InitSocket = InitServerSocket (&Address, hostname, portinfo);
   
   InitPassword ();
