]> Pileus Git - ~andy/fetchmail/blob - socket.c
BeOS support.
[~andy/fetchmail] / socket.c
1 /*
2  * socket.c -- socket library functions
3  *
4  * Copyright 1998 by Eric S. Raymond.
5  * For license terms, see the file COPYING in this directory.
6  */
7
8 #include "config.h"
9 #include <stdio.h>
10 #include <errno.h>
11 #include <string.h>
12 #ifdef HAVE_MEMORY_H
13 #include <memory.h>
14 #endif /* HAVE_MEMORY_H */
15 #include <sys/types.h>
16 #ifndef HAVE_NET_SOCKET_H
17 #include <sys/socket.h>
18 #else
19 #include <net/socket.h>
20 #endif
21 #include <netinet/in.h>
22 #ifdef HAVE_ARPA_INET_H
23 #include <arpa/inet.h>
24 #endif
25 #include <netdb.h>
26 #if defined(STDC_HEADERS)
27 #include <stdlib.h>
28 #endif
29 #if defined(HAVE_UNISTD_H)
30 #include <unistd.h>
31 #endif
32 #if defined(HAVE_STDARG_H)
33 #include <stdarg.h>
34 #else
35 #include <varargs.h>
36 #endif
37 #include "socket.h"
38 #include "fetchmail.h"
39 #include "i18n.h"
40
41 /* Defines to allow BeOS to play nice... */
42 #ifdef __BEOS__
43 static char peeked;
44 #define fm_close(a)  closesocket(a)
45 #define fm_write(a,b,c)  send(a,b,c,0)
46 #define fm_peek(a,b,c)   recv(a,b,c,0)
47 #define fm_read(a,b,c)   recv(a,b,c,0)
48 #else
49 #define fm_close(a)  close(a)
50 #define fm_write(a,b,c)  write(a,b,c)
51 #define fm_peek(a,b,c)   recv(a,b,c, MSG_PEEK)
52 #define fm_read(a,b,c)   read(a,b,c)
53 #endif
54
55 /* We need to define h_errno only if it is not already */
56 #ifndef h_errno
57
58 #ifdef HAVE_RES_SEARCH
59 /* some versions of FreeBSD should declare this but don't */
60 extern int h_errno;
61 #else
62 /* pretend we have h_errno to avoid some #ifdef's later */
63 static int h_errno;
64 #endif
65
66 #endif /* ndef h_errno */
67
68 #if NET_SECURITY
69 #include <net/security.h>
70 #endif /* NET_SECURITY */
71
72 #ifdef HAVE_SOCKETPAIR
73 static int handle_plugin(const char *host,
74                          const char *service, const char *plugin)
75 /* get a socket mediated through a given external command */
76 {
77     int fds[2];
78     if (socketpair(AF_UNIX,SOCK_STREAM,0,fds))
79     {
80         report(stderr, _("fetchmail: socketpair failed\n"));
81         return -1;
82     }
83     switch (fork()) {
84         case -1:
85                 /* error */
86                 report(stderr, _("fetchmail: fork failed\n"));
87                 return -1;
88                 break;
89         case 0: /* child */
90                 /* fds[1] is the parent's end; close it for proper EOF
91                 ** detection */
92                 (void) close(fds[1]);
93                 if ( (dup2(fds[0],0) == -1) || (dup2(fds[0],1) == -1) ) {
94                         report(stderr, _("dup2 failed\n"));
95                         exit(1);
96                 }
97                 /* fds[0] is now connected to 0 and 1; close it */
98                 (void) close(fds[0]);
99                 if (outlevel >= O_VERBOSE)
100                     report(stderr, _("running %s %s %s\n"), plugin, host, service);
101                 execlp(plugin,plugin,host,service,0);
102                 report(stderr, _("execl(%s) failed\n"), plugin);
103                 exit(0);
104                 break;
105         default:        /* parent */
106                 /* NOP */
107                 break;
108     }
109     /* fds[0] is the child's end; close it for proper EOF detection */
110     (void) close(fds[0]);
111     return fds[1];
112 }
113 #endif /* HAVE_SOCKETPAIR */
114
115 #ifdef __UNUSED__
116 #include <sys/time.h>
117
118 int SockCheckOpen(int fd)
119 /* poll given socket; is it selectable? */
120 {
121     fd_set r, w, e;
122     int rt;
123     struct timeval tv;
124   
125     for (;;) 
126     {
127         FD_ZERO(&r); FD_ZERO(&w); FD_ZERO(&e);
128         FD_SET(fd, &e);
129     
130         tv.tv_sec = 0; tv.tv_usec = 0;
131         rt = select(fd+1, &r, &w, &e, &tv);
132         if (rt == -1 && (errno != EAGAIN && errno != EINTR))
133             return 0;
134         if (rt != -1)
135             return 1;
136     }
137 }
138 #endif /* __UNUSED__ */
139
140 #if INET6_ENABLE
141 int SockOpen(const char *host, const char *service, const char *options,
142              const char *plugin)
143 {
144     struct addrinfo *ai, *ai0, req;
145     int i;
146 #if NET_SECURITY
147     void *request = NULL;
148     int requestlen;
149 #endif /* NET_SECURITY */
150
151 #ifdef HAVE_SOCKETPAIR
152     if (plugin)
153         return handle_plugin(host,service,plugin);
154 #endif /* HAVE_SOCKETPAIR */
155     memset(&req, 0, sizeof(struct addrinfo));
156     req.ai_socktype = SOCK_STREAM;
157
158     if (getaddrinfo(host, service, &req, &ai0)) {
159         report(stderr, _("fetchmail: getaddrinfo(%s.%s)\n"), host,service);
160         return -1;
161     }
162
163 #if NET_SECURITY
164     if (!options)
165         requestlen = 0;
166     else
167         if (net_security_strtorequest((char *)options, &request, &requestlen))
168             goto ret;
169
170     i = inner_connect(ai0, request, requestlen, NULL, NULL, "fetchmail", NULL);
171     if (request)
172         free(request);
173
174  ret:
175 #else /* NET_SECURITY */
176 #ifdef HAVE_INNER_CONNECT
177     i = inner_connect(ai0, NULL, 0, NULL, NULL, "fetchmail", NULL);
178     if (i >= 0)
179         break;
180 #else
181     i = -1;
182     for (ai = ai0; ai; ai = ai->ai_next) {
183         i = socket(ai->ai_family, ai->ai_socktype, 0);
184         if (i < 0)
185             continue;
186         if (connect(i, (struct sockaddr *) ai->ai_addr, ai->ai_addrlen) < 0) {
187             fm_close(i);
188             i = -1;
189             continue;
190         }
191         break;
192     }
193 #endif
194 #endif /* NET_SECURITY */
195
196     freeaddrinfo(ai0);
197
198     return i;
199 }
200 #else /* INET6_ENABLE */
201 #ifndef HAVE_INET_ATON
202 #ifndef  INADDR_NONE
203 #ifdef   INADDR_BROADCAST
204 #define  INADDR_NONE    INADDR_BROADCAST
205 #else
206 #define  INADDR_NONE    -1
207 #endif
208 #endif
209 #endif /* HAVE_INET_ATON */
210
211 int SockOpen(const char *host, int clientPort, const char *options,
212              const char *plugin)
213 {
214     int sock = -1;      /* pacify -Wall */
215 #ifndef HAVE_INET_ATON
216     unsigned long inaddr;
217 #endif /* HAVE_INET_ATON */
218     struct sockaddr_in ad, **pptr;
219     struct hostent *hp;
220
221 #ifdef HAVE_SOCKETPAIR
222     if (plugin) {
223       char buf[10];
224       sprintf(buf,"%d",clientPort);
225       return handle_plugin(host,buf,plugin);
226     }
227 #endif /* HAVE_SOCKETPAIR */
228
229     memset(&ad, 0, sizeof(ad));
230     ad.sin_family = AF_INET;
231
232     /* we'll accept a quad address */
233 #ifndef HAVE_INET_ATON
234     inaddr = inet_addr(host);
235     if (inaddr != INADDR_NONE)
236     {
237         memcpy(&ad.sin_addr, &inaddr, sizeof(inaddr));
238 #else
239     if (inet_aton(host, &ad.sin_addr))
240     {
241 #endif /* HAVE_INET_ATON */
242         ad.sin_port = htons(clientPort);
243
244         sock = socket(AF_INET, SOCK_STREAM, 0);
245         if (sock < 0)
246         {
247             h_errno = 0;
248             return -1;
249         }
250         if (connect(sock, (struct sockaddr *) &ad, sizeof(ad)) < 0)
251         {
252             int olderr = errno;
253             fm_close(sock);     /* don't use SockClose, no traffic yet */
254             h_errno = 0;
255             errno = olderr;
256             return -1;
257         }
258 #ifndef HAVE_INET_ATON
259     }
260 #else
261     }
262 #endif /* HAVE_INET_ATON */
263     else {
264         hp = gethostbyname(host);
265
266         if (hp == NULL)
267         {
268             errno = 0;
269             return -1;
270         }
271         /*
272          * Add a check to make sure the address has a valid IPv4 or IPv6
273          * length.  This prevents buffer spamming by a broken DNS.
274          */
275         if(hp->h_length != 4 && hp->h_length != 8)
276         {
277             h_errno = errno = 0;
278             report(stderr, 
279                    _("fetchmail: illegal address length received for host %s\n"),host);
280             return -1;
281         }
282         /*
283          * Try all addresses of a possibly multihomed host until we get
284          * a successful connect or until we run out of addresses.
285          */
286         pptr = (struct sockaddr_in **)hp->h_addr_list;
287         for(; *pptr != NULL; pptr++)
288         {
289             sock = socket(AF_INET, SOCK_STREAM, 0);
290             if (sock < 0)
291             {
292                 h_errno = 0;
293                 return -1;
294             }
295             ad.sin_port = htons(clientPort);
296             memcpy(&ad.sin_addr, *pptr, sizeof(struct in_addr));
297             if (connect(sock, (struct sockaddr *) &ad, sizeof(ad)) == 0)
298                 break; /* success */
299             fm_close(sock);     /* don't use SockClose, no traffic yet */
300             memset(&ad, 0, sizeof(ad));
301             ad.sin_family = AF_INET;
302         }
303         if(*pptr == NULL)
304         {
305             int olderr = errno;
306             fm_close(sock);     /* don't use SockClose, no traffic yet */
307             h_errno = 0;
308             errno = olderr;
309             return -1;
310         }
311     }
312
313     return(sock);
314 }
315 #endif /* INET6_ENABLE */
316
317
318 #if defined(HAVE_STDARG_H)
319 int SockPrintf(int sock, const char* format, ...)
320 {
321 #else
322 int SockPrintf(sock,format,va_alist)
323 int sock;
324 char *format;
325 va_dcl {
326 #endif
327
328     va_list ap;
329     char buf[8192];
330
331 #if defined(HAVE_STDARG_H)
332     va_start(ap, format) ;
333 #else
334     va_start(ap);
335 #endif
336 #ifdef HAVE_VSNPRINTF
337     vsnprintf(buf, sizeof(buf), format, ap);
338 #else
339     vsprintf(buf, format, ap);
340 #endif
341     va_end(ap);
342     return SockWrite(sock, buf, strlen(buf));
343
344 }
345
346 #ifdef SSL_ENABLE
347 #include "ssl.h"
348 #include "err.h"
349 #include "pem.h"
350 #include "x509.h"
351
352 static  SSL_CTX *_ctx = NULL;
353 static  SSL *_ssl_context[FD_SETSIZE];
354
355 SSL     *SSLGetContext( int );
356 #endif /* SSL_ENABLE */
357
358 int SockWrite(int sock, char *buf, int len)
359 {
360     int n, wrlen = 0;
361 #ifdef  SSL_ENABLE
362     SSL *ssl;
363 #endif
364
365     while (len)
366     {
367 #ifdef SSL_ENABLE
368         if( NULL != ( ssl = SSLGetContext( sock ) ) )
369                 n = SSL_write(ssl, buf, len);
370         else
371         n = fm_write(sock, buf, len);
372 #else
373         n = fm_write(sock, buf, len);
374 #endif
375         if (n <= 0)
376             return -1;
377         len -= n;
378         wrlen += n;
379         buf += n;
380     }
381     return wrlen;
382 }
383
384 int SockRead(int sock, char *buf, int len)
385 {
386     char *newline, *bp = buf;
387     int n;
388 #ifdef  SSL_ENABLE
389     SSL *ssl;
390 #endif
391
392     if (--len < 1)
393         return(-1);
394 #ifdef __BEOS__
395     if (peeked != 0){
396         (*bp) = peeked;
397         bp++;
398         len--;
399         peeked = 0;
400     }
401 #endif        
402     do {
403         /* 
404          * The reason for these gymnastics is that we want two things:
405          * (1) to read \n-terminated lines,
406          * (2) to return the true length of data read, even if the
407          *     data coming in has embedded NULS.
408          */
409 #ifdef  SSL_ENABLE
410         if( NULL != ( ssl = SSLGetContext( sock ) ) ) {
411                 /* Hack alert! */
412                 /* OK...  SSL_peek works a little different from MSG_PEEK
413                         Problem is that SSL_peek can return 0 if there
414                         is no data currently available.  If, on the other
415                         hand, we loose the socket, we also get a zero, but
416                         the SSL_read then SEGFAULTS!  To deal with this,
417                         we'll check the error code any time we get a return
418                         of zero from SSL_peek.  If we have an error, we bail.
419                         If we don't, we read one character in SSL_read and
420                         loop.  This should continue to work even if they
421                         later change the behavior of SSL_peek
422                         to "fix" this problem...  :-(   */
423                 if ((n = SSL_peek(ssl, bp, len)) < 0) {
424                         return(-1);
425                 }
426                 if( 0 == n ) {
427                         /* SSL_peek says no data...  Does he mean no data
428                         or did the connection blow up?  If we got an error
429                         then bail! */
430                         if( 0 != ( n = ERR_get_error() ) ) {
431                                 return -1;
432                         }
433                         /* We didn't get an error so read at least one
434                                 character at this point and loop */
435                         n = 1;
436                         /* Make sure newline start out NULL!
437                          * We don't have a string to pass through
438                          * the strchr at this point yet */
439                         newline = NULL;
440                 } else if ((newline = memchr(bp, '\n', n)) != NULL)
441                         n = newline - bp + 1;
442                 if ((n = SSL_read(ssl, bp, n)) == -1) {
443                         return(-1);
444                 }
445                 /* Check for case where our single character turned out to
446                  * be a newline...  (It wasn't going to get caught by
447                  * the strchr above if it came from the hack...  ). */
448                 if( NULL == newline && 1 == n && '\n' == *bp ) {
449                         /* Got our newline - this will break
450                                 out of the loop now */
451                         newline = bp;
452                 }
453         } else {
454                 if ((n = fm_peek(sock, bp, len)) <= 0)
455                         return(-1);
456                 if ((newline = memchr(bp, '\n', n)) != NULL)
457                         n = newline - bp + 1;
458                 if ((n = fm_read(sock, bp, n)) == -1)
459                         return(-1);
460         }
461 #else
462
463 #ifdef __BEOS__
464     if ((n = fm_read(sock, bp, 1)) <= 0)
465 #else
466     if ((n = fm_peek(sock, bp, len)) <= 0)
467 #endif
468         return (-1);
469         if ((newline = memchr(bp, '\n', n)) != NULL)
470             n = newline - bp + 1;
471 #ifndef __BEOS__
472         if ((n = fm_read(sock, bp, n)) == -1)
473             return(-1);
474 #endif /* __BEOS__ */
475 #endif
476         bp += n;
477         len -= n;
478     } while 
479             (!newline && len);
480     *bp = '\0';
481     return bp - buf;
482 }
483
484 int SockPeek(int sock)
485 /* peek at the next socket character without actually reading it */
486 {
487     int n;
488     char ch;
489 #ifdef  SSL_ENABLE
490     SSL *ssl;
491 #endif
492
493 #ifdef  SSL_ENABLE
494         if( NULL != ( ssl = SSLGetContext( sock ) ) ) {
495                 n = SSL_peek(ssl, &ch, 1);
496                 if( 0 == n ) {
497                         /* This code really needs to implement a "hold back"
498                          * to simulate a functioning SSL_peek()...  sigh...
499                          * Has to be coordinated with the read code above.
500                          * Next on the list todo...     */
501
502                         /* SSL_peek says no data...  Does he mean no data
503                         or did the connection blow up?  If we got an error
504                         then bail! */
505                         if( 0 != ( n = ERR_get_error() ) ) {
506                                 return -1;
507                         }
508
509                         /* Haven't seen this case actually occur, but...
510                            if the problem in SockRead can occur, this should
511                            be possible...  Just not sure what to do here.
512                            This should be a safe "punt" the "peek" but don't
513                            "punt" the "session"... */
514
515                         return 0;       /* Give him a '\0' character */
516                 }
517         } else {
518                 n = fm_peek(sock, &ch, 1);
519         }
520 #else
521
522         n = fm_peek(sock, &ch, 1);
523
524 #endif /* SSL_ENABLE */
525         if (n == -1)
526                 return -1;
527
528 #ifdef __BEOS__
529     peeked = ch;
530 #endif
531     return(ch);
532 }
533
534 #ifdef SSL_ENABLE
535
536 static  char *_ssl_server_cname = NULL;
537
538 SSL *SSLGetContext( int sock )
539 {
540         /* If SSLOpen has never initialized - just return NULL */
541         if( NULL == _ctx )
542                 return NULL;
543
544         if( sock < 0 || sock > FD_SETSIZE )
545                 return NULL;
546         return _ssl_context[sock];
547 }
548
549
550 int SSL_verify_callback( int ok_return, X509_STORE_CTX *ctx )
551 {
552         char buf[260];
553         char cbuf[260];
554         char ibuf[260];
555         char *str_ptr;
556         X509 *x509_cert;
557         int err, depth;
558
559         x509_cert = X509_STORE_CTX_get_current_cert(ctx);
560         err = X509_STORE_CTX_get_error(ctx);
561         depth = X509_STORE_CTX_get_error_depth(ctx);
562
563         X509_NAME_oneline(X509_get_subject_name(x509_cert), buf, 256);
564         X509_NAME_oneline(X509_get_issuer_name(x509_cert), ibuf, 256);
565
566         /* Just to be sure those buffers are terminated...  I think the
567                 X509 libraries do, but... */
568         buf[256] = ibuf[256] = '\0';
569
570         if (depth == 0) {
571                 if( ( str_ptr = strstr( ibuf, "/O=" ) ) ) {
572                         str_ptr += 3;
573                         strcpy( cbuf, str_ptr );
574                         if( ( str_ptr = strchr(cbuf, '/' ) ) ) {
575                                 *str_ptr = '\0';
576                         }
577                         if (outlevel == O_VERBOSE)
578                                 report(stdout, "Issuer Organization: %s\n", cbuf );
579                 } else {
580                         if (outlevel == O_VERBOSE)
581                                 report(stdout, "Unknown Organization\n", cbuf );
582                 }
583                 if( ( str_ptr = strstr( ibuf, "/CN=" ) ) ) {
584                         str_ptr += 4;
585                         strcpy( cbuf, str_ptr );
586                         if( ( str_ptr = strchr(cbuf, '/' ) ) ) {
587                                 *str_ptr = '\0';
588                         }
589                         if (outlevel == O_VERBOSE)
590                                 report(stdout, "Issuer CommonName: %s\n", cbuf );
591                 } else {
592                         if (outlevel == O_VERBOSE)
593                                 report(stdout, "Unknown Issuer CommonName\n", cbuf );
594                 }
595                 if( ( str_ptr = strstr( buf, "/CN=" ) ) ) {
596                         str_ptr += 4;
597                         strcpy( cbuf, str_ptr );
598                         if( ( str_ptr = strchr(cbuf, '/' ) ) ) {
599                                 *str_ptr = '\0';
600                         }
601                         if (outlevel == O_VERBOSE)
602                                 report(stdout, "Server CommonName: %s\n", cbuf );
603                         /* Should we have some wildcarding here? */
604                         if ( NULL != _ssl_server_cname
605                              && 0 != strcmp( cbuf, _ssl_server_cname ) ) {
606                                 report(stdout,
607                                        "Server CommonName mismatch: %s != %s\n",
608                                        cbuf, _ssl_server_cname );
609                         }
610                 } else {
611                         if (outlevel == O_VERBOSE)
612                                 report(stdout, "Unknown Server CommonName\n", cbuf );
613                 }
614         }
615
616         switch (ctx->error) {
617         case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT:
618                 X509_NAME_oneline(X509_get_issuer_name(ctx->current_cert), buf, 256);
619                 report(stdout, "unknown issuer= %s", buf);
620                 break;
621         case X509_V_ERR_CERT_NOT_YET_VALID:
622         case X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD:
623                 report(stderr, "Server Certificate not yet valid");
624                 break;
625         case X509_V_ERR_CERT_HAS_EXPIRED:
626         case X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD:
627                 report(stderr, "Server Certificate expired");
628                 break;
629         }
630         /* We are not requiring or validating server or issuer id's as yet */
631         /* Always return OK from here */
632         ok_return = 1;
633         return( ok_return );
634 }
635
636
637 /* performs initial SSL handshake over the connected socket
638  * uses SSL *ssl global variable, which is currently defined
639  * in this file
640  */
641 int SSLOpen(int sock, char *mycert, char *mykey, char *servercname )
642 {
643         SSL_load_error_strings();
644         SSLeay_add_ssl_algorithms();
645         
646         if( sock < 0 || sock > FD_SETSIZE ) {
647                 report(stderr, "File descriptor out of range for SSL" );
648                 return( -1 );
649         }
650
651         if( ! _ctx ) {
652                 /* Be picky and make sure the memory is cleared */
653                 memset( _ssl_context, 0, sizeof( _ssl_context ) );
654                 _ctx = SSL_CTX_new(SSLv23_client_method());
655                 if(_ctx == NULL) {
656                         ERR_print_errors_fp(stderr);
657                         return(-1);
658                 }
659         }
660         
661         _ssl_context[sock] = SSL_new(_ctx);
662         
663         if(_ssl_context[sock] == NULL) {
664                 ERR_print_errors_fp(stderr);
665                 return(-1);
666         }
667         
668         /* This static is for the verify callback */
669         _ssl_server_cname = servercname;
670
671         SSL_CTX_set_verify(_ctx, SSL_VERIFY_PEER, SSL_verify_callback);
672
673         if( mycert || mykey ) {
674
675         /* Ok...  He has a certificate file defined, so lets declare it.  If
676          * he does NOT have a separate certificate and private key file then
677          * assume that it's a combined key and certificate file.
678          */
679                 if( !mykey )
680                         mykey = mycert;
681                 if( !mycert )
682                         mycert = mykey;
683                 SSL_use_certificate_file(_ssl_context[sock], mycert, SSL_FILETYPE_PEM);
684                 SSL_use_RSAPrivateKey_file(_ssl_context[sock], mykey, SSL_FILETYPE_PEM);
685         }
686
687         SSL_set_fd(_ssl_context[sock], sock);
688         
689         if(SSL_connect(_ssl_context[sock]) == -1) {
690                 ERR_print_errors_fp(stderr);
691                 return(-1);
692         }
693         
694         return(0);
695 }
696 #endif
697
698 int SockClose(int sock)
699 /* close a socket gracefully */
700 {
701     char ch;
702 #ifdef  SSL_ENABLE
703     SSL *ssl;
704
705     if( NULL != ( ssl = SSLGetContext( sock ) ) ) {
706         /* Clean up the SSL stack */
707         SSL_free( _ssl_context[sock] );
708         _ssl_context[sock] = NULL;
709     }
710 #endif
711
712     /* Half-close the connection first so the other end gets notified.
713      *
714      * This stops sends but allows receives (effectively, it sends a
715      * TCP <FIN>).
716      */
717     if (shutdown(sock, 1) == 0)
718         /* If there is any data still waiting in the queue, discard it.
719          * Call recv() until either it returns 0 (meaning we received a FIN)
720          * or any error occurs.  This makes sure all data sent by the other
721          * side is acknowledged at the TCP level.
722          */
723         if (fm_peek(sock, &ch, 1) > 0)
724             while (fm_read(sock, &ch, 1) > 0)
725                 continue;
726
727     /* if there's an error closing at this point, not much we can do */
728     return(fm_close(sock));     /* this is guarded */
729 }
730
731 #ifdef MAIN
732 /*
733  * Use the chargen service to test input buffering directly.
734  * You may have to uncomment the `chargen' service description in your
735  * inetd.conf (and then SIGHUP inetd) for this to work.  */
736 main()
737 {
738     int         sock = SockOpen("localhost", 19, NULL);
739     char        buf[80];
740
741     while (SockRead(sock, buf, sizeof(buf)-1))
742         SockWrite(1, buf, strlen(buf));
743     SockClose(sock);
744 }
745 #endif /* MAIN */
746
747 /* socket.c ends here */