diff options
author | goodale <goodale@bfcf8e34-485d-4d46-a995-1fd6fa6fb178> | 2000-10-31 22:58:15 +0000 |
---|---|---|
committer | goodale <goodale@bfcf8e34-485d-4d46-a995-1fd6fa6fb178> | 2000-10-31 22:58:15 +0000 |
commit | 80e9eaef3a4486f2a24c97a600d49a8da0a6ff18 (patch) | |
tree | 0684d83887af2786eef77e2cf91602dcfd862956 | |
parent | dfeb8ad4f45d8374f6eb653f0bbd9d532a5b4142 (diff) |
Updating to check for HAVE_SOCKET_TYPE.
Added homegrown GetHostName function.
Some cosmetic changes.
Tom
git-svn-id: http://svn.cactuscode.org/arrangements/CactusPUGHIO/IsoSurfacer/trunk@17 bfcf8e34-485d-4d46-a995-1fd6fa6fb178
-rw-r--r-- | src/Sockets.c | 119 |
1 files changed, 89 insertions, 30 deletions
diff --git a/src/Sockets.c b/src/Sockets.c index cce9e0b..05d96ed 100644 --- a/src/Sockets.c +++ b/src/Sockets.c @@ -46,13 +46,13 @@ static char *rcsid = "$Header$"; -CCTK_FILEVERSION(DevThorns_isosurfacer_Socket_c) +CCTK_FILEVERSION(AlphaThorns_isosurfacer_Socket_c) /******************************************************************** ********************* Local Data Types *********************** ********************************************************************/ -#ifndef SOCKET +#ifndef HAVE_SOCKET_TYPE #define SOCKET int #endif @@ -87,6 +87,8 @@ typedef struct ISOSocket ********************* Local Routine Prototypes ********************* ********************************************************************/ +static int byteswap(void *buf,CCTK_INT8 nelements,int elementsize); + IsoCommand *Iso_PollCommand(cGH *cGH,IsoCommand *cmd); int Iso_Write(isoSocket *connection, const char *buffer, size_t count); @@ -97,6 +99,8 @@ static void SocketDestroy(isoSocket *this, isoSocket **list); static void SocketClose(isoSocket *this); int Iso_SetupServer(cGH *GH,isosurfacerGH *myGH, int dataport, int controlport, int queue_size, int hunt); + +static void GetHostName(char *name, int length); static int InitialiseTCP(void); /******************************************************************** @@ -129,33 +133,6 @@ static chosen_dataport = 0; /******************************************************************** - ********************* Internal Routines ********************** - ********************************************************************/ -static int byteswap(void *buf,CCTK_INT8 nelements,int elementsize) -{ - char *buffer; - CCTK_INT8 i; - int s,d; -#ifdef WORDS_BIGENDIAN - return 0; -#else - buffer=(char *)buf; - if(elementsize<=1) return 0; - - for(i=0;i<nelements;i++,buffer+=elementsize){ - // do the swap thing on each element - for(s=0,d=elementsize-1;s<d;s++,d--){ - char c=buffer[s]; - buffer[s]=buffer[d]; - buffer[d]=c; - } - } - return 1; -#endif -} - - -/******************************************************************** ********************* External Routines ********************** ********************************************************************/ @@ -207,7 +184,7 @@ int Iso_SetupServer(cGH *GH,isosurfacerGH *myGH,int dataport, int controlport, i exit (EXIT_FAILURE); } - gethostname(hostname, 1024); + GetHostName(hostname, 1024); printf("Isosurfacer listening for control connetcions on %s port %d/\n", hostname, hunt ? realcport : controlport); printf("Isosurfacer listening for data connections on %s port %d/\n", hostname, hunt ? realdport : dataport); @@ -645,6 +622,43 @@ int Iso_Read(isoSocket *connection, char *buffer, size_t count) ********************************************************************/ /*@@ + @routine byteswap + @date + @author John Shalf + @desc + + @enddesc + @calls + @calledby + @history + + @endhistory + +@@*/ +static int byteswap(void *buf,CCTK_INT8 nelements,int elementsize) +{ + char *buffer; + CCTK_INT8 i; + int s,d; +#ifdef WORDS_BIGENDIAN + return 0; +#else + buffer=(char *)buf; + if(elementsize<=1) return 0; + + for(i=0;i<nelements;i++,buffer+=elementsize){ + // do the swap thing on each element + for(s=0,d=elementsize-1;s<d;s++,d--){ + char c=buffer[s]; + buffer[s]=buffer[d]; + buffer[d]=c; + } + } + return 1; +#endif +} + + /*@@ @routine Iso_MakeSocket @date Wed Sep 13 20:39:15 2000 @author Tom Goodale @@ -830,6 +844,51 @@ static void SocketClose(isoSocket *this) } } + /*@@ + @routine GetHostName + @date Fri Oct 20 12:12:34 2000 + @author Tom Goodale + @desc + Gets the fully qualified name of this host if possible. + @enddesc + @calls + @calledby + @history + + @endhistory + @var name + @vdesc character buffer to store name in + @vtype char * + @vio out + @vcomment + + @endvar + @var length + @vdesc length of the character buffer + @vtype int + @vio in + @vcomment + + @endvar + +@@*/ +static void GetHostName(char *name, int length) +{ + gethostname(name, length); + + /* Does the name include the domain. */ + if(!strchr(name, '.')) + { +#ifdef HAVE_GETHOSTBYNAME + struct hostent *thishostent; + + thishostent = gethostbyname(name); + + strncpy(name, thishostent->h_name, length); +#endif + } +} + /****************************************************************************** ****************************************************************************** ******************************************************************************/ |