--- HTTCP.c._orig Tue Jan 13 11:14:02 1998 +++ HTTCP.c Wed Jan 14 06:14:41 1998 @@ -14,6 +14,7 @@ ** 20 May 94 Andy Harper Added support for CMU TCP/IP transport ** 17 Nov 94 Andy Harper Added support for SOCKETSHR transport ** 16 Jul 95 S. Bjorndahl added kluge to deal with LIBCMU bug +** 13 Jan 98 Ryan Nielsen added clone-based gethostbyname() */ #include "HTUtils.h" @@ -298,6 +299,37 @@ } #endif /* !DECNET */ +#ifdef NSL_CLONE + +#include +#include +#include /* clone prototype and flags */ + +/* avoid incompatible pointer type warning */ +typedef int (*clone_fn_t) +#ifdef __STDC__ +(void *, ...); +#else +(); +#endif + +int NSL_clone_gethostbyname ARGS2( + SockA *, sin, + CONST char *, host) +{ + struct hostent *phost; + + phost = gethostbyname(host); + + if (phost != NULL) + memcpy(&sin->sin_addr.s_addr, phost->h_addr, phost->h_length); + else + sin->sin_addr.s_addr = 0; + + return 0; +} +#endif + /* Parse a network node address and port ** ------------------------------------- ** @@ -416,6 +448,50 @@ } #endif /* MVS */ +#ifdef NSL_CLONE + /* + * Linux clone-based gethostbyname() by Ryan Nielsen + * checks for interrupts. (based on fork code below) + */ + { + pid_t fpid, waitret = (pid_t)0; + int cst1; + void *newstack[16384]; + void **newstackptr = (void **)(16384 + (unsigned char *)newstack); + + fpid = clone( + (clone_fn_t)NSL_clone_gethostbyname, + newstackptr, + CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|SIGCHLD, + 2, + sin, + host); + + while ((waitret = waitpid(fpid, &cst1, WNOHANG)) <= 0) { + if (HTCheckForInterrupt()) { + if (TRACE) { + fprintf(stderr, + "HTParseInet: INTERRUPTED gethostbyname.\n"); + } + kill(fpid, SIGKILL); + waitpid(fpid, NULL, 0); + FREE(host); + return HT_INTERRUPTED; + } + /* be nice to the system */ + sleep(1); + } + if ( !sin->sin_addr.s_addr ) { + if (TRACE) { + fprintf(stderr, + "HTParseInet: Can't find internet node name `%s'.\n", + host); + } + FREE(host); + return -1; + } + } +#else #ifdef NSL_FORK /* ** Start block for fork-based gethostbyname() with @@ -475,6 +551,7 @@ "HTParseInet: INTERRUPTED gethostbyname.\n"); } kill(fpid , SIGKILL); + waitpid(fpid, NULL, 0); FREE(host); close(pfd[0]); close(pfd[1]); @@ -603,6 +680,7 @@ #endif /* VMS && CMU_TCP */ #endif /* DJGPP */ #endif /* NSL_FORK */ +#endif /* NSL_CLONE */ } if (TRACE) {