more distros
[privoxy.git] / jbsockets.c
1 const char jbsockets_rcs[] = "$Id: jbsockets.c,v 1.23 2002/03/05 00:36:01 jongfoster Exp $";
2 /*********************************************************************
3  *
4  * File        :  $Source: /cvsroot/ijbswa/current/jbsockets.c,v $
5  *
6  * Purpose     :  Contains wrappers for system-specific sockets code,
7  *                so that the rest of JunkBuster can be more
8  *                OS-independent.  Contains #ifdefs to make this work
9  *                on many platforms.
10  *
11  * Copyright   :  Written by and Copyright (C) 2001 the SourceForge
12  *                IJBSWA team.  http://ijbswa.sourceforge.net
13  *
14  *                Based on the Internet Junkbuster originally written
15  *                by and Copyright (C) 1997 Anonymous Coders and 
16  *                Junkbusters Corporation.  http://www.junkbusters.com
17  *
18  *                This program is free software; you can redistribute it 
19  *                and/or modify it under the terms of the GNU General
20  *                Public License as published by the Free Software
21  *                Foundation; either version 2 of the License, or (at
22  *                your option) any later version.
23  *
24  *                This program is distributed in the hope that it will
25  *                be useful, but WITHOUT ANY WARRANTY; without even the
26  *                implied warranty of MERCHANTABILITY or FITNESS FOR A
27  *                PARTICULAR PURPOSE.  See the GNU General Public
28  *                License for more details.
29  *
30  *                The GNU General Public License should be included with
31  *                this file.  If not, you can view it at
32  *                http://www.gnu.org/copyleft/gpl.html
33  *                or write to the Free Software Foundation, Inc., 59
34  *                Temple Place - Suite 330, Boston, MA  02111-1307, USA.
35  *
36  * Revisions   :
37  *    $Log: jbsockets.c,v $
38  *    Revision 1.23  2002/03/05 00:36:01  jongfoster
39  *    Fixing bug 514988 - unable to restart JunkBuster
40  *
41  *    Revision 1.22  2002/03/04 02:08:02  david__schmidt
42  *    Enable web editing of actions file on OS/2 (it had been broken all this time!)
43  *
44  *    Revision 1.21  2002/01/09 14:32:33  oes
45  *    Added support for gethostbyname_r and gethostbyaddr_r.
46  *
47  *    Revision 1.20  2001/11/16 00:48:48  jongfoster
48  *    Enabling duplicate-socket detection for all platforms, not
49  *    just Win32.
50  *
51  *    Revision 1.19  2001/10/25 03:40:47  david__schmidt
52  *    Change in porting tactics: OS/2's EMX porting layer doesn't allow multiple
53  *    threads to call select() simultaneously.  So, it's time to do a real, live,
54  *    native OS/2 port.  See defines for __EMX__ (the porting layer) vs. __OS2__
55  *    (native). Both versions will work, but using __OS2__ offers multi-threading.
56  *
57  *    Revision 1.18  2001/09/21 23:02:02  david__schmidt
58  *    Cleaning up 2 compiler warnings on OS/2.
59  *
60  *    Revision 1.17  2001/09/13 20:11:46  jongfoster
61  *    Fixing 2 compiler warnings under Win32
62  *
63  *    Revision 1.16  2001/07/30 22:08:36  jongfoster
64  *    Tidying up #defines:
65  *    - All feature #defines are now of the form FEATURE_xxx
66  *    - Permanently turned off WIN_GUI_EDIT
67  *    - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
68  *
69  *    Revision 1.15  2001/07/29 17:40:43  jongfoster
70  *    Fixed compiler warning by adding a cast
71  *
72  *    Revision 1.14  2001/07/18 13:47:59  oes
73  *    Eliminated dirty hack for getsockbyname()
74  *
75  *    Revision 1.13  2001/07/15 13:56:57  jongfoster
76  *    Removing unused local variable.
77  *
78  *    Revision 1.12  2001/07/01 17:04:11  oes
79  *    Bugfix: accept_connection no longer uses the obsolete hstrerror() function
80  *
81  *    Revision 1.11  2001/06/29 21:45:41  oes
82  *    Indentation, CRLF->LF, Tab-> Space
83  *
84  *    Revision 1.10  2001/06/29 13:29:15  oes
85  *    - Added remote (server) host IP to csp->http->host_ip_addr_str
86  *    - Added detection of local socket IP and fqdn
87  *    - Removed logentry from cancelled commit
88  *
89  *    Revision 1.9  2001/06/07 23:06:09  jongfoster
90  *    The host parameter to connect_to() is now const.
91  *
92  *    Revision 1.8  2001/06/03 19:12:07  oes
93  *    filled comment
94  *
95  *    Revision 1.7  2001/05/28 16:14:00  jongfoster
96  *    Fixing bug in LOG_LEVEL_LOG
97  *
98  *    Revision 1.6  2001/05/26 17:28:32  jongfoster
99  *    Fixed LOG_LEVEL_LOG
100  *
101  *    Revision 1.5  2001/05/26 15:26:15  jongfoster
102  *    ACL feature now provides more security by immediately dropping
103  *    connections from untrusted hosts.
104  *
105  *    Revision 1.4  2001/05/26 00:37:42  jongfoster
106  *    Cosmetic indentation correction.
107  *
108  *    Revision 1.3  2001/05/25 21:57:54  jongfoster
109  *    Now gives a warning under Windows if you try to bind
110  *    it to a port that's already in use.
111  *
112  *    Revision 1.2  2001/05/17 23:01:01  oes
113  *     - Cleaned CRLF's from the sources and related files
114  *
115  *    Revision 1.1.1.1  2001/05/15 13:58:54  oes
116  *    Initial import of version 2.9.3 source tree
117  *
118  *
119  *********************************************************************/
120 \f
121
122 #include "config.h"
123
124 #include <stdlib.h>
125 #include <stdio.h>
126 #include <string.h>
127 #include <errno.h>
128 #include <fcntl.h>
129 #include <sys/types.h>
130
131 #ifdef _WIN32
132
133 #include <windows.h>
134 #include <sys/timeb.h>
135 #include <io.h>
136
137 #else
138
139 #ifndef __OS2__
140 #include <unistd.h>
141 #endif
142 #include <sys/time.h>
143 #include <netinet/in.h>
144 #include <sys/ioctl.h>
145 #include <netdb.h>
146 #include <sys/socket.h>
147
148 #ifndef __BEOS__
149 #include <netinet/tcp.h>
150 #ifndef __OS2__
151 #include <arpa/inet.h>
152 #endif
153 #else
154 #include <socket.h>
155 #endif
156
157 #if defined(__EMX__) || defined (__OS2__)
158 #include <sys/select.h>  /* OS/2/EMX needs a little help with select */
159 #include <nerrno.h>
160 #endif
161
162 #endif
163
164 #include "project.h"
165 #include "jbsockets.h"
166 #include "filters.h"
167 #include "errlog.h"
168
169 const char jbsockets_h_rcs[] = JBSOCKETS_H_VERSION;
170
171
172 /*********************************************************************
173  *
174  * Function    :  connect_to
175  *
176  * Description :  Open a socket and connect to it.  Will check
177  *                that this is allowed according to ACL.
178  *
179  * Parameters  :
180  *          1  :  host = hostname to connect to
181  *          2  :  portnum = port to connent on
182  *          3  :  csp = Current client state (buffers, headers, etc...)
183  *                      Not modified, only used for source IP and ACL.
184  *
185  * Returns     :  -1 => failure, else it is the socket file descriptor.
186  *
187  *********************************************************************/
188 int connect_to(const char *host, int portnum, struct client_state *csp)
189 {
190    struct sockaddr_in inaddr;
191    int   fd, addr;
192    fd_set wfds;
193    struct timeval tv[1];
194 #if !defined(_WIN32) && !defined(__BEOS__) && !defined(AMIGA)
195    int   flags;
196 #endif /* !defined(_WIN32) && !defined(__BEOS__) && !defined(AMIGA) */
197
198 #ifdef FEATURE_ACL
199    struct access_control_addr dst[1];
200 #endif /* def FEATURE_ACL */
201
202    memset((char *)&inaddr, 0, sizeof inaddr);
203
204    if ((addr = resolve_hostname_to_ip(host)) == INADDR_NONE)
205    {
206       csp->http->host_ip_addr_str = strdup("unknown");
207       return(-1);
208    }
209
210 #ifdef FEATURE_ACL
211    dst->addr = ntohl((unsigned long) addr);
212    dst->port = portnum;
213
214    if (block_acl(dst, csp))
215    {
216 #ifdef __OS2__
217       errno = SOCEPERM;
218 #else
219       errno = EPERM;
220 #endif
221       return(-1);
222    }
223 #endif /* def FEATURE_ACL */
224
225    inaddr.sin_addr.s_addr = addr;
226    inaddr.sin_family      = AF_INET;
227    csp->http->host_ip_addr_str = strdup(inet_ntoa(inaddr.sin_addr));
228
229 #ifndef _WIN32
230    if (sizeof(inaddr.sin_port) == sizeof(short))
231 #endif /* ndef _WIN32 */
232    {
233       inaddr.sin_port = htons((unsigned short) portnum);
234    }
235 #ifndef _WIN32
236    else
237    {
238       inaddr.sin_port = htonl((unsigned long)portnum);
239    }
240 #endif /* ndef _WIN32 */
241
242    if ((fd = socket(inaddr.sin_family, SOCK_STREAM, 0)) < 0)
243    {
244       return(-1);
245    }
246
247 #ifdef TCP_NODELAY
248    {  /* turn off TCP coalescence */
249       int mi = 1;
250       setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, (char *) &mi, sizeof (int));
251    }
252 #endif /* def TCP_NODELAY */
253
254 #if !defined(_WIN32) && !defined(__BEOS__) && !defined(AMIGA) && !defined(__OS2__)
255    if ((flags = fcntl(fd, F_GETFL, 0)) != -1)
256    {
257       flags |= O_NDELAY;
258       fcntl(fd, F_SETFL, flags);
259    }
260 #endif /* !defined(_WIN32) && !defined(__BEOS__) && !defined(AMIGA) && !defined(__OS2__) */
261
262    while (connect(fd, (struct sockaddr *) & inaddr, sizeof inaddr) == -1)
263    {
264 #ifdef _WIN32
265       if (errno == WSAEINPROGRESS)
266 #elif __OS2__ 
267       if (sock_errno() == EINPROGRESS)
268 #else /* ifndef _WIN32 */
269       if (errno == EINPROGRESS)
270 #endif /* ndef _WIN32 || __OS2__ */
271       {
272          break;
273       }
274
275 #ifdef __OS2__ 
276       if (sock_errno() != EINTR)
277 #else
278       if (errno != EINTR)
279 #endif /* __OS2__ */
280       {
281          close_socket(fd);
282          return(-1);
283       }
284    }
285
286 #if !defined(_WIN32) && !defined(__BEOS__) && !defined(AMIGA) && !defined(__OS2__)
287    if (flags != -1)
288    {
289       flags &= ~O_NDELAY;
290       fcntl(fd, F_SETFL, flags);
291    }
292 #endif /* !defined(_WIN32) && !defined(__BEOS__) && !defined(AMIGA) && !defined(__OS2__) */
293
294    /* wait for connection to complete */
295    FD_ZERO(&wfds);
296    FD_SET(fd, &wfds);
297
298    tv->tv_sec  = 30;
299    tv->tv_usec = 0;
300
301    if (select(fd + 1, NULL, &wfds, NULL, tv) <= 0)
302    {
303       close_socket(fd);
304       return(-1);
305    }
306    return(fd);
307
308 }
309
310
311 /*********************************************************************
312  *
313  * Function    :  write_socket
314  *
315  * Description :  Write the contents of buf (for n bytes) to socket fd.
316  *
317  * Parameters  :
318  *          1  :  fd = file descriptor (aka. handle) of socket to write to.
319  *          2  :  buf = pointer to data to be written.
320  *          3  :  len = length of data to be written to the socket "fd".
321  *
322  * Returns     :  Win32 & Unix: If no error occurs, returns the total number of
323  *                bytes sent, which can be less than the number
324  *                indicated by len. Otherwise, returns (-1).
325  *
326  *********************************************************************/
327 size_t write_socket(int fd, const char *buf, size_t len)
328 {
329    if (len <= 0)
330    {
331       return(0);
332    }
333
334    log_error(LOG_LEVEL_LOG, "%N", len, buf);
335
336 #if defined(_WIN32) || defined(__BEOS__) || defined(AMIGA)
337    return(send(fd, buf, len, 0));
338 #elif defined(__OS2__)
339    /*
340     * Break the data up into SOCKET_SEND_MAX chunks for sending...
341     * OS/2 seemed to complain when the chunks were too large.
342     */
343 #define SOCKET_SEND_MAX 65000
344    {
345       int write_len = 0, send_len, send_rc = 0, i = 0;
346       while ((i < len) && (send_rc != -1))
347       {
348          if ((i + SOCKET_SEND_MAX) > len)
349             send_len = len - i;
350          else
351             send_len = SOCKET_SEND_MAX;
352          send_rc = send(fd,(char*)buf + i, send_len, 0);
353          if (send_rc == -1)
354             return(0);
355          i = i + send_len;
356    }
357    return len;
358    }
359 #else
360    return(write(fd, buf, len));
361 #endif
362
363 }
364
365
366 /*********************************************************************
367  *
368  * Function    :  read_socket
369  *
370  * Description :  Read from a TCP/IP socket in a platform independent way.
371  *
372  * Parameters  :
373  *          1  :  fd = file descriptor of the socket to read
374  *          2  :  buf = pointer to buffer where data will be written
375  *                Must be >= len bytes long.
376  *          3  :  len = maximum number of bytes to read
377  *
378  * Returns     :  On success, the number of bytes read is returned (zero
379  *                indicates end of file), and the file position is advanced
380  *                by this number.  It is not an error if this number is
381  *                smaller than the number of bytes requested; this may hap-
382  *                pen for example because fewer bytes are actually available
383  *                right now (maybe because we were close to end-of-file, or
384  *                because we are reading from a pipe, or from a terminal),
385  *                or because read() was interrupted by a signal.  On error,
386  *                -1 is returned, and errno is set appropriately.  In this
387  *                case it is left unspecified whether the file position (if
388  *                any) changes.
389  *
390  *********************************************************************/
391 size_t read_socket(int fd, char *buf, size_t len)
392 {
393    if (len <= 0)
394    {
395       return(0);
396    }
397
398 #if defined(_WIN32) || defined(__BEOS__) || defined(AMIGA) || defined(__OS2__)
399    return(recv(fd, buf, len, 0));
400 #else
401    return(read(fd, buf, len));
402 #endif
403 }
404
405
406 /*********************************************************************
407  *
408  * Function    :  close_socket
409  *
410  * Description :  Closes a TCP/IP socket
411  *
412  * Parameters  :
413  *          1  :  fd = file descriptor of socket to be closed
414  *
415  * Returns     :  void
416  *
417  *********************************************************************/
418 void close_socket(int fd)
419 {
420 #if defined(_WIN32) || defined(__BEOS__)
421    closesocket(fd);
422 #elif defined(AMIGA)
423    CloseSocket(fd); 
424 #elif defined(__OS2__)
425    soclose(fd);
426 #else
427    close(fd);
428 #endif
429
430 }
431
432
433 /*********************************************************************
434  *
435  * Function    :  bind_port
436  *
437  * Description :  Call socket, set socket options, and listen.
438  *                Called by listen_loop to "boot up" our proxy address.
439  *
440  * Parameters  :
441  *          1  :  hostnam = TCP/IP address to bind/listen to
442  *          2  :  portnum = port to listen on
443  *
444  * Returns     :  if success, return file descriptor
445  *                if failure, returns -3 if address is in use,
446  *                                    -2 if address unresolvable,
447  *                                    -1 otherwise
448  *
449  *********************************************************************/
450 int bind_port(const char *hostnam, int portnum)
451 {
452    struct sockaddr_in inaddr;
453    int fd;
454 #ifndef _WIN32
455    int one = 1;
456 #endif /* ndef _WIN32 */
457
458    memset((char *)&inaddr, '\0', sizeof inaddr);
459
460    inaddr.sin_family      = AF_INET;
461    inaddr.sin_addr.s_addr = resolve_hostname_to_ip(hostnam);
462
463    if (inaddr.sin_addr.s_addr == INADDR_NONE)
464    {
465       return(-2);
466    }
467
468 #ifndef _WIN32
469    if (sizeof(inaddr.sin_port) == sizeof(short))
470 #endif /* ndef _WIN32 */
471    {
472       inaddr.sin_port = htons((unsigned short) portnum);
473    }
474 #ifndef _WIN32
475    else
476    {
477       inaddr.sin_port = htonl((unsigned long) portnum);
478    }
479 #endif /* ndef _WIN32 */
480
481    fd = socket(AF_INET, SOCK_STREAM, 0);
482
483    if (fd < 0)
484    {
485       return(-1);
486    }
487
488 #ifndef _WIN32
489    /*
490     * This is not needed for Win32 - in fact, it stops
491     * duplicate instances of JunkBuster from being caught.
492     *
493     * On UNIX, we assume the user is sensible enough not
494     * to start JunkBuster multiple times on the same IP.
495     * Without this, stopping and restarting JunkBuster
496     * from a script fails.
497     * Note: SO_REUSEADDR is meant to only take over
498     * sockets which are *not* in listen state in Linux,
499     * e.g. sockets in TIME_WAIT. YMMV.
500     */
501    setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *)&one, sizeof(one));
502 #endif /* ndef _WIN32 */
503
504    if (bind (fd, (struct sockaddr *)&inaddr, sizeof(inaddr)) < 0)
505    {
506       close_socket (fd);
507 #ifdef _WIN32
508       if (errno == WSAEADDRINUSE)
509 #else
510       if (errno == EADDRINUSE)
511 #endif
512       {
513          return(-3);
514       }
515       else
516       {
517          return(-1);
518       }
519    }
520
521    while (listen(fd, 5) == -1)
522    {
523       if (errno != EINTR)
524       {
525          return(-1);
526       }
527    }
528
529    return fd;
530
531 }
532
533
534 /*********************************************************************
535  *
536  * Function    :  accept_connection
537  *
538  * Description :  Accepts a connection on a socket.  Socket must have
539  *                been created using bind_port().
540  *
541  * Parameters  :
542  *          1  :  csp = Client state, cfd, ip_addr_str, and 
543  *                ip_addr_long will be set by this routine.
544  *          2  :  fd  = file descriptor returned from bind_port
545  *
546  * Returns     :  when a connection is accepted, it returns 1 (TRUE).
547  *                On an error it returns 0 (FALSE).
548  *
549  *********************************************************************/
550 int accept_connection(struct client_state * csp, int fd)
551 {
552    struct sockaddr_in client, server;
553    struct hostent *host = NULL;
554    int afd;
555    size_t c_length, s_length;
556 #if defined(HAVE_GETHOSTBYADDR_R_8_ARGS) ||  defined(HAVE_GETHOSTBYADDR_R_7_ARGS) || defined(HAVE_GETHOSTBYADDR_R_5_ARGS)
557    struct hostent result;
558 #if defined(HAVE_GETHOSTBYADDR_R_5_ARGS)
559    struct hostent_data hdata;
560 #else
561    char hbuf[HOSTENT_BUFFER_SIZE];
562    int thd_err;
563 #endif /* def HAVE_GETHOSTBYADDR_R_5_ARGS */
564 #endif /* def HAVE_GETHOSTBYADDR_R_(8|7|5)_ARGS */
565
566    c_length = s_length = sizeof(client);
567
568    do
569    {
570       afd = accept (fd, (struct sockaddr *) &client, &c_length);
571    } while (afd < 1 && errno == EINTR);
572
573    if (afd < 0)
574    {
575       return 0;
576    }
577
578    /* 
579     * Determine the IP-Adress that the client used to reach us
580     * and the hostname associated with that address
581     */
582    if (!getsockname(afd, (struct sockaddr *) &server, &s_length))
583    {
584       csp->my_ip_addr_str = strdup(inet_ntoa(server.sin_addr));
585 #if defined(HAVE_GETHOSTBYADDR_R_8_ARGS)
586       gethostbyaddr_r((const char *)&server.sin_addr,
587                       sizeof(server.sin_addr), AF_INET,
588                       &result, hbuf, HOSTENT_BUFFER_SIZE,
589                       &host, &thd_err);
590 #elif defined(HAVE_GETHOSTBYADDR_R_7_ARGS)
591       host = gethostbyaddr_r((const char *)&server.sin_addr,
592                       sizeof(server.sin_addr), AF_INET,
593                       &result, hbuf, HOSTENT_BUFFER_SIZE, &thd_err);
594 #elif defined(HAVE_GETHOSTBYADDR_R_5_ARGS)
595       if (0 == gethostbyaddr_r((const char *)&server.sin_addr,
596                                sizeof(server.sin_addr), AF_INET,
597                                &result, &hdata))
598       {
599          host = &result;
600       }
601       else
602       {
603          host = NULL;
604       }
605 #else
606       host = gethostbyaddr((const char *)&server.sin_addr, 
607                            sizeof(server.sin_addr), AF_INET);
608 #endif
609       if (host == NULL)
610       {
611          log_error(LOG_LEVEL_ERROR, "Unable to get my own hostname: %E\n");
612       }
613       else
614       {
615          csp->my_hostname = strdup(host->h_name);
616       }
617    }
618
619    csp->cfd    = afd;
620    csp->ip_addr_str  = strdup(inet_ntoa(client.sin_addr));
621    csp->ip_addr_long = ntohl(client.sin_addr.s_addr);
622
623    return 1;
624
625 }
626
627
628 /*********************************************************************
629  *
630  * Function    :  resolve_hostname_to_ip
631  *
632  * Description :  Resolve a hostname to an internet tcp/ip address.
633  *                NULL or an empty string resolve to INADDR_ANY.
634  *
635  * Parameters  :
636  *          1  :  host = hostname to resolve
637  *
638  * Returns     :  INADDR_NONE => failure, INADDR_ANY or tcp/ip address if succesful.
639  *
640  *********************************************************************/
641 unsigned long resolve_hostname_to_ip(const char *host)
642 {
643    struct sockaddr_in inaddr;
644    struct hostent *hostp;
645 #if defined(HAVE_GETHOSTBYNAME_R_6_ARGS) || defined(HAVE_GETHOSTBYNAME_R_5_ARGS) || defined(HAVE_GETHOSTBYNAME_R_3_ARGS)
646    struct hostent result;
647 #if defined(HAVE_GETHOSTBYNAME_R_6_ARGS) || defined(HAVE_GETHOSTBYNAME_R_5_ARGS)
648    char hbuf[HOSTENT_BUFFER_SIZE];
649    int thd_err;
650 #else /* defined(HAVE_GETHOSTBYNAME_R_3_ARGS) */
651    struct hostent_data hdata;
652 #endif /* def HAVE_GETHOSTBYNAME_R_(6|5)_ARGS */
653 #endif /* def HAVE_GETHOSTBYNAME_R_(6|5|3)_ARGS */
654
655    if ((host == NULL) || (*host == '\0'))
656    {
657       return(INADDR_ANY);
658    }
659
660    memset((char *) &inaddr, 0, sizeof inaddr);
661
662    if ((inaddr.sin_addr.s_addr = inet_addr(host)) == -1)
663    {
664 #if defined(HAVE_GETHOSTBYNAME_R_6_ARGS)
665       gethostbyname_r(host, &result, hbuf,
666                       HOSTENT_BUFFER_SIZE, &hostp, &thd_err);
667 #elif defined(HAVE_GETHOSTBYNAME_R_5_ARGS)
668       hostp = gethostbyname_r(host, &result, hbuf,
669                       HOSTENT_BUFFER_SIZE, &thd_err);
670 #elif defined(HAVE_GETHOSTBYNAME_R_3_ARGS)
671       if (0 == gethostbyname_r(host, &result, &hdata))
672       {
673          hostp = &result;
674       }
675       else
676       {
677          hostp = NULL;
678       }
679 #else
680       hostp = gethostbyname(host);
681 #endif /* def HAVE_GETHOSTBYNAME_R_(6|5|3)_ARGS */
682       if (hostp == NULL)
683       {
684          errno = EINVAL;
685          log_error(LOG_LEVEL_ERROR, "could not resolve hostname %s", host);
686          return(INADDR_NONE);
687       }
688       if (hostp->h_addrtype != AF_INET)
689       {
690 #ifdef _WIN32
691          errno = WSAEPROTOTYPE;
692 #else
693          errno = EPROTOTYPE;
694 #endif 
695          log_error(LOG_LEVEL_ERROR, "hostname %s resolves to unknown address type.", host);
696          return(INADDR_NONE);
697       }
698       memcpy(
699          (char *) &inaddr.sin_addr,
700          (char *) hostp->h_addr,
701          sizeof(inaddr.sin_addr)
702       );
703    }
704    return(inaddr.sin_addr.s_addr);
705
706 }
707
708
709 /*
710   Local Variables:
711   tab-width: 3
712   end:
713 */