2 * socket.c -- socket library functions
4 * Copyright 1998 by Eric S. Raymond.
5 * For license terms, see the file COPYING in this directory.
12 #include <ctype.h> /* isspace() */
15 #endif /* HAVE_MEMORY_H */
16 #include <sys/types.h>
17 #ifndef HAVE_NET_SOCKET_H
18 #include <sys/socket.h>
20 #include <net/socket.h>
23 #include <netinet/in.h>
24 #ifdef HAVE_ARPA_INET_H
25 #include <arpa/inet.h>
28 #if defined(STDC_HEADERS)
31 #if defined(HAVE_UNISTD_H)
34 #if defined(HAVE_STDARG_H)
41 #include "fetchmail.h"
44 /* Defines to allow BeOS to play nice... */
47 #define fm_close(a) closesocket(a)
48 #define fm_write(a,b,c) send(a,b,c,0)
49 #define fm_peek(a,b,c) recv(a,b,c,0)
50 #define fm_read(a,b,c) recv(a,b,c,0)
52 #define fm_close(a) close(a)
53 #define fm_write(a,b,c) write(a,b,c)
54 #define fm_peek(a,b,c) recv(a,b,c, MSG_PEEK)
55 #define fm_read(a,b,c) read(a,b,c)
58 /* We need to define h_errno only if it is not already */
61 #ifdef HAVE_RES_SEARCH
62 /* some versions of FreeBSD should declare this but don't */
65 /* pretend we have h_errno to avoid some #ifdef's later */
69 #endif /* ndef h_errno */
72 #include <net/security.h>
73 #endif /* NET_SECURITY */
75 #ifdef HAVE_SOCKETPAIR
76 char *const *parse_plugin(const char *plugin, const char *host, const char *service)
77 { const char **argvec;
79 char *cp, *plugin_copy;
80 unsigned int plugin_copy_len;
81 unsigned int plugin_offset = 0, plugin_copy_offset = 0;
82 unsigned int i, s = 2 * sizeof(char*), host_count = 0, service_count = 0;
83 unsigned int plugin_len = strlen(plugin);
84 unsigned int host_len = strlen(host);
85 unsigned int service_len = strlen(service);
87 for (c = p = plugin; *c; c++)
88 { if (isspace(*c) && !isspace(*p))
90 if (*p == '%' && *c == 'h')
92 if (*p == '%' && *c == 'p')
97 plugin_copy_len = plugin_len + host_len * host_count + service_len * service_count;
98 plugin_copy = malloc(plugin_copy_len + 1);
101 report(stderr, GT_("fetchmail: malloc failed\n"));
105 while (plugin_copy_offset < plugin_copy_len)
106 { if ((plugin[plugin_offset] == '%') && (plugin[plugin_offset + 1] == 'h'))
107 { strcpy(plugin_copy + plugin_copy_offset, host);
109 plugin_copy_offset += host_len;
111 else if ((plugin[plugin_offset] == '%') && (plugin[plugin_offset + 1] == 'p'))
112 { strcpy(plugin_copy + plugin_copy_offset, service);
114 plugin_copy_offset += service_len;
117 { plugin_copy[plugin_copy_offset] = plugin[plugin_offset];
119 plugin_copy_offset++;
122 plugin_copy[plugin_copy_len] = 0;
127 report(stderr, GT_("fetchmail: malloc failed\n"));
130 memset(argvec, 0, s);
131 for (c = p = plugin_copy, i = 0; *c; c++)
132 { if ((!isspace(*c)) && (c == p ? 1 : isspace(*p))) {
138 for (cp = plugin_copy; *cp; cp++)
142 return (char *const*)argvec;
145 static int handle_plugin(const char *host,
146 const char *service, const char *plugin)
147 /* get a socket mediated through a given external command */
153 * The author of this code, Felix von Leitner <felix@convergence.de>, says:
154 * he chose socketpair() instead of pipe() because socketpair creates
155 * bidirectional sockets while allegedly some pipe() implementations don't.
157 if (socketpair(AF_UNIX,SOCK_STREAM,0,fds))
159 report(stderr, GT_("fetchmail: socketpair failed\n"));
165 report(stderr, GT_("fetchmail: fork failed\n"));
169 /* fds[1] is the parent's end; close it for proper EOF
171 (void) close(fds[1]);
172 if ( (dup2(fds[0],0) == -1) || (dup2(fds[0],1) == -1) ) {
173 report(stderr, GT_("dup2 failed\n"));
176 /* fds[0] is now connected to 0 and 1; close it */
177 (void) close(fds[0]);
178 if (outlevel >= O_VERBOSE)
179 report(stderr, GT_("running %s (host %s service %s)\n"), plugin, host, service);
180 argvec = parse_plugin(plugin,host,service);
181 execvp(*argvec, argvec);
182 report(stderr, GT_("execvp(%s) failed\n"), *argvec);
185 default: /* parent */
189 /* fds[0] is the child's end; close it for proper EOF detection */
190 (void) close(fds[0]);
193 #endif /* HAVE_SOCKETPAIR */
196 #include <sys/time.h>
198 int SockCheckOpen(int fd)
199 /* poll given socket; is it selectable? */
207 FD_ZERO(&r); FD_ZERO(&w); FD_ZERO(&e);
210 tv.tv_sec = 0; tv.tv_usec = 0;
211 rt = select(fd+1, &r, &w, &e, &tv);
212 if (rt == -1 && (errno != EAGAIN && errno != EINTR))
218 #endif /* __UNUSED__ */
220 int UnixOpen(const char *path)
222 #ifdef HAVE_SIGPROCMASK
224 #endif /* HAVE_SIGPROCMASK */
227 struct sockaddr_un ad;
228 memset(&ad, 0, sizeof(ad));
229 ad.sun_family = AF_UNIX;
230 strncpy(ad.sun_path, path, sizeof(ad.sun_path)-1);
232 sock = socket( AF_UNIX, SOCK_STREAM, 0 );
239 #ifdef HAVE_SIGPROCMASK
240 /* avoid socket leak on alarm signal during connect(2) */
241 sigfillset(&allsigs);
242 sigprocmask(SIG_BLOCK, &allsigs, NULL);
243 #endif /* HAVE_SIGPROCMASK */
245 if (connect(sock, (struct sockaddr *) &ad, sizeof(ad)) < 0)
248 fm_close(sock); /* don't use SockClose, no traffic yet */
254 #ifdef HAVE_SIGPROCMASK
255 sigprocmask(SIG_UNBLOCK, &allsigs, NULL);
256 #endif /* HAVE_SIGPROCMASK */
262 int SockOpen(const char *host, const char *service, const char *options,
265 #ifdef HAVE_SIGPROCMASK
267 #endif /* HAVE_SIGPROCMASK */
269 struct addrinfo *ai, *ai0, req;
272 void *request = NULL;
274 #endif /* NET_SECURITY */
276 #ifdef HAVE_SOCKETPAIR
278 return handle_plugin(host,service,plugin);
279 #endif /* HAVE_SOCKETPAIR */
280 memset(&req, 0, sizeof(struct addrinfo));
281 req.ai_socktype = SOCK_STREAM;
283 if (getaddrinfo(host, service, &req, &ai0)) {
284 report(stderr, GT_("fetchmail: getaddrinfo(%s.%s)\n"), host,service);
292 if (net_security_strtorequest((char *)options, &request, &requestlen))
295 i = inner_connect(ai0, request, requestlen, NULL, NULL, "fetchmail", NULL);
300 #else /* NET_SECURITY */
301 #ifdef HAVE_INNER_CONNECT
302 i = inner_connect(ai0, NULL, 0, NULL, NULL, "fetchmail", NULL);
307 #ifdef HAVE_SIGPROCMASK
308 /* avoid socket leak on alarm signal during connect(2) */
309 sigfillset(&allsigs);
310 sigprocmask(SIG_BLOCK, &allsigs, NULL);
311 #endif /* HAVE_SIGPROCMASK */
314 for (ai = ai0; ai; ai = ai->ai_next) {
315 i = socket(ai->ai_family, ai->ai_socktype, 0);
318 if (connect(i, (struct sockaddr *) ai->ai_addr, ai->ai_addrlen) < 0) {
326 #ifdef HAVE_SIGPROCMASK
327 sigprocmask(SIG_UNBLOCK, &allsigs, NULL);
328 #endif /* HAVE_SIGPROCMASK */
331 #endif /* NET_SECURITY */
337 #else /* INET6_ENABLE */
338 #ifndef HAVE_INET_ATON
340 #ifdef INADDR_BROADCAST
341 #define INADDR_NONE INADDR_BROADCAST
343 #define INADDR_NONE -1
346 #endif /* HAVE_INET_ATON */
348 int SockOpen(const char *host, int clientPort, const char *options,
351 int sock = -1; /* pacify -Wall */
352 #ifndef HAVE_INET_ATON
353 unsigned long inaddr;
354 #endif /* HAVE_INET_ATON */
355 struct sockaddr_in ad, **pptr;
358 #ifdef HAVE_SOCKETPAIR
362 snprintf(buf, sizeof(buf), /* Yeah, paranoic. So what? :P */
365 #endif /* HAVE_SNPRINTF */
367 return handle_plugin(host,buf,plugin);
369 #endif /* HAVE_SOCKETPAIR */
371 memset(&ad, 0, sizeof(ad));
372 ad.sin_family = AF_INET;
374 /* we'll accept a quad address */
375 #ifndef HAVE_INET_ATON
376 inaddr = inet_addr((char*)host);
377 if (inaddr != INADDR_NONE)
379 memcpy(&ad.sin_addr, &inaddr, sizeof(inaddr));
381 if (inet_aton(host, &ad.sin_addr))
383 #endif /* HAVE_INET_ATON */
384 ad.sin_port = htons(clientPort);
386 sock = socket(AF_INET, SOCK_STREAM, 0);
392 if (connect(sock, (struct sockaddr *) &ad, sizeof(ad)) < 0)
395 fm_close(sock); /* don't use SockClose, no traffic yet */
400 #ifndef HAVE_INET_ATON
404 #endif /* HAVE_INET_ATON */
406 hp = gethostbyname((char*)host);
414 * Add a check to make sure the address has a valid IPv4 or IPv6
415 * length. This prevents buffer spamming by a broken DNS.
417 if(hp->h_length != 4 && hp->h_length != 8)
421 GT_("fetchmail: illegal address length received for host %s\n"),host);
425 * Try all addresses of a possibly multihomed host until we get
426 * a successful connect or until we run out of addresses.
428 pptr = (struct sockaddr_in **)hp->h_addr_list;
429 for(; *pptr != NULL; pptr++)
431 sock = socket(AF_INET, SOCK_STREAM, 0);
437 ad.sin_port = htons(clientPort);
438 memcpy(&ad.sin_addr, *pptr, sizeof(struct in_addr));
439 if (connect(sock, (struct sockaddr *) &ad, sizeof(ad)) == 0)
441 fm_close(sock); /* don't use SockClose, no traffic yet */
442 memset(&ad, 0, sizeof(ad));
443 ad.sin_family = AF_INET;
448 fm_close(sock); /* don't use SockClose, no traffic yet */
457 #endif /* INET6_ENABLE */
460 #if defined(HAVE_STDARG_H)
461 int SockPrintf(int sock, const char* format, ...)
464 int SockPrintf(sock,format,va_alist)
473 #if defined(HAVE_STDARG_H)
474 va_start(ap, format) ;
478 #ifdef HAVE_VSNPRINTF
479 vsnprintf(buf, sizeof(buf), format, ap);
481 vsprintf(buf, format, ap);
484 return SockWrite(sock, buf, strlen(buf));
489 #include "openssl/ssl.h"
490 #include "openssl/err.h"
491 #include "openssl/pem.h"
492 #include "openssl/x509.h"
494 static SSL_CTX *_ctx = NULL;
495 static SSL *_ssl_context[FD_SETSIZE];
497 SSL *SSLGetContext( int );
498 #endif /* SSL_ENABLE */
500 int SockWrite(int sock, char *buf, int len)
510 if( NULL != ( ssl = SSLGetContext( sock ) ) )
511 n = SSL_write(ssl, buf, len);
513 n = fm_write(sock, buf, len);
515 n = fm_write(sock, buf, len);
526 int SockRead(int sock, char *buf, int len)
528 char *newline, *bp = buf;
546 * The reason for these gymnastics is that we want two things:
547 * (1) to read \n-terminated lines,
548 * (2) to return the true length of data read, even if the
549 * data coming in has embedded NULS.
552 if( NULL != ( ssl = SSLGetContext( sock ) ) ) {
554 /* OK... SSL_peek works a little different from MSG_PEEK
555 Problem is that SSL_peek can return 0 if there
556 is no data currently available. If, on the other
557 hand, we loose the socket, we also get a zero, but
558 the SSL_read then SEGFAULTS! To deal with this,
559 we'll check the error code any time we get a return
560 of zero from SSL_peek. If we have an error, we bail.
561 If we don't, we read one character in SSL_read and
562 loop. This should continue to work even if they
563 later change the behavior of SSL_peek
564 to "fix" this problem... :-( */
565 if ((n = SSL_peek(ssl, bp, len)) < 0) {
569 /* SSL_peek says no data... Does he mean no data
570 or did the connection blow up? If we got an error
572 if( 0 != ( n = ERR_get_error() ) ) {
575 /* We didn't get an error so read at least one
576 character at this point and loop */
578 /* Make sure newline start out NULL!
579 * We don't have a string to pass through
580 * the strchr at this point yet */
582 } else if ((newline = memchr(bp, '\n', n)) != NULL)
583 n = newline - bp + 1;
584 if ((n = SSL_read(ssl, bp, n)) == -1) {
587 /* Check for case where our single character turned out to
588 * be a newline... (It wasn't going to get caught by
589 * the strchr above if it came from the hack... ). */
590 if( NULL == newline && 1 == n && '\n' == *bp ) {
591 /* Got our newline - this will break
592 out of the loop now */
596 if ((n = fm_peek(sock, bp, len)) <= 0)
598 if ((newline = memchr(bp, '\n', n)) != NULL)
599 n = newline - bp + 1;
600 if ((n = fm_read(sock, bp, n)) == -1)
606 if ((n = fm_read(sock, bp, 1)) <= 0)
608 if ((n = fm_peek(sock, bp, len)) <= 0)
611 if ((newline = memchr(bp, '\n', n)) != NULL)
612 n = newline - bp + 1;
614 if ((n = fm_read(sock, bp, n)) == -1)
616 #endif /* __BEOS__ */
626 int SockPeek(int sock)
627 /* peek at the next socket character without actually reading it */
636 if( NULL != ( ssl = SSLGetContext( sock ) ) ) {
637 n = SSL_peek(ssl, &ch, 1);
639 /* This code really needs to implement a "hold back"
640 * to simulate a functioning SSL_peek()... sigh...
641 * Has to be coordinated with the read code above.
642 * Next on the list todo... */
644 /* SSL_peek says no data... Does he mean no data
645 or did the connection blow up? If we got an error
647 if( 0 != ( n = ERR_get_error() ) ) {
651 /* Haven't seen this case actually occur, but...
652 if the problem in SockRead can occur, this should
653 be possible... Just not sure what to do here.
654 This should be a safe "punt" the "peek" but don't
655 "punt" the "session"... */
657 return 0; /* Give him a '\0' character */
660 n = fm_peek(sock, &ch, 1);
664 n = fm_peek(sock, &ch, 1);
666 #endif /* SSL_ENABLE */
678 static char *_ssl_server_cname = NULL;
679 static int _check_fp;
680 static char *_check_digest;
681 static char *_server_label;
682 static int _depth0ck;
684 SSL *SSLGetContext( int sock )
686 /* If SSLOpen has never initialized - just return NULL */
690 if( sock < 0 || sock > FD_SETSIZE )
692 return _ssl_context[sock];
696 int SSL_verify_callback( int ok_return, X509_STORE_CTX *ctx, int strict )
701 unsigned char digest[EVP_MAX_MD_SIZE];
702 char text[EVP_MAX_MD_SIZE * 3 + 1], *tp, *te;
704 unsigned int dsz, i, esz;
705 X509_NAME *subj, *issuer;
707 x509_cert = X509_STORE_CTX_get_current_cert(ctx);
708 err = X509_STORE_CTX_get_error(ctx);
709 depth = X509_STORE_CTX_get_error_depth(ctx);
711 subj = X509_get_subject_name(x509_cert);
712 issuer = X509_get_issuer_name(x509_cert);
717 if (outlevel == O_VERBOSE) {
718 if ((i = X509_NAME_get_text_by_NID(issuer, NID_organizationName, buf, sizeof(buf))) != -1) {
719 report(stdout, GT_("Issuer Organization: %s\n"), buf);
720 if (i >= sizeof(buf) - 1)
721 report(stdout, GT_("Warning: Issuer Organization Name too long (possibly truncated).\n"));
723 report(stdout, GT_("Unknown Organization\n"));
724 if ((i = X509_NAME_get_text_by_NID(issuer, NID_commonName, buf, sizeof(buf))) != -1) {
725 report(stdout, GT_("Issuer CommonName: %s\n"), buf);
726 if (i >= sizeof(buf) - 1)
727 report(stdout, GT_("Warning: Issuer CommonName too long (possibly truncated).\n"));
729 report(stdout, GT_("Unknown Issuer CommonName\n"));
731 if ((i = X509_NAME_get_text_by_NID(subj, NID_commonName, buf, sizeof(buf))) != -1) {
732 if (outlevel == O_VERBOSE)
733 report(stdout, GT_("Server CommonName: %s\n"), buf);
734 if (i >= sizeof(buf) - 1) {
735 /* Possible truncation. In this case, this is a DNS name, so this
736 * is really bad. We do not tolerate this even in the non-strict case. */
737 report(stderr, GT_("Bad certificate: Subject CommonName too long!\n"));
740 if (_ssl_server_cname != NULL) {
742 char *p2 = _ssl_server_cname;
747 n = strlen(p2) - strlen(p1);
751 if (0 != strcasecmp(p1, p2)) {
753 GT_("Server CommonName mismatch: %s != %s\n"),
754 buf, _ssl_server_cname );
755 if (ok_return && strict)
758 } else if (ok_return && strict) {
759 report(stderr, GT_("Server name not set, could not verify certificate!\n"));
763 if (outlevel == O_VERBOSE)
764 report(stdout, GT_("Unknown Server CommonName\n"));
765 if (ok_return && strict) {
766 report(stderr, GT_("Server name not specified in certificate!\n"));
770 /* Print the finger print. Note that on errors, we might print it more than once
771 * normally; we kluge around that by using a global variable. */
774 digest_tp = EVP_md5();
775 if (digest_tp == NULL) {
776 report(stderr, GT_("EVP_md5() failed!\n"));
779 if (!X509_digest(x509_cert, digest_tp, digest, &dsz)) {
780 report(stderr, GT_("Out of memory!\n"));
784 te = text + sizeof(text);
785 for (i = 0; i < dsz; i++) {
787 esz = snprintf(tp, te - tp, i > 0 ? ":%02X" : "%02X", digest[i]);
789 esz = sprintf(tp, i > 0 ? ":%02X" : "%02X", digest[i]);
791 if (esz >= te - tp) {
792 report(stderr, GT_("Digest text buffer too small!\n"));
797 report(stdout, GT_("%s key fingerprint: %s\n"), _server_label, text);
798 if (_check_digest != NULL) {
799 if (strcmp(text, _check_digest) == 0)
800 report(stdout, GT_("%s fingerprints match.\n"), _server_label);
802 report(stderr, GT_("%s fingerprints do not match!\n"), _server_label);
809 if (err != X509_V_OK && (strict || outlevel == O_VERBOSE)) {
810 report(strict ? stderr : stdout, GT_("Warning: server certificate verification: %s\n"), X509_verify_cert_error_string(err));
811 /* We gave the error code, but maybe we can add some more details for debugging */
813 case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT:
814 X509_NAME_oneline(issuer, buf, sizeof(buf));
815 buf[sizeof(buf) - 1] = '\0';
816 report(stdout, GT_("unknown issuer (first %d characters): %s\n"), sizeof(buf), buf);
825 int SSL_nock_verify_callback( int ok_return, X509_STORE_CTX *ctx )
827 return SSL_verify_callback(ok_return, ctx, 0);
830 int SSL_ck_verify_callback( int ok_return, X509_STORE_CTX *ctx )
832 return SSL_verify_callback(ok_return, ctx, 1);
835 /* performs initial SSL handshake over the connected socket
836 * uses SSL *ssl global variable, which is currently defined
839 int SSLOpen(int sock, char *mycert, char *mykey, char *myproto, int certck, char *certpath,
840 char *fingerprint, char *servercname, char *label)
844 SSL_load_error_strings();
845 SSLeay_add_ssl_algorithms();
847 if( sock < 0 || sock > FD_SETSIZE ) {
848 report(stderr, GT_("File descriptor out of range for SSL") );
853 /* Be picky and make sure the memory is cleared */
854 memset( _ssl_context, 0, sizeof( _ssl_context ) );
856 if(!strcmp("ssl2",myproto)) {
857 _ctx = SSL_CTX_new(SSLv2_client_method());
858 } else if(!strcmp("ssl3",myproto)) {
859 _ctx = SSL_CTX_new(SSLv3_client_method());
860 } else if(!strcmp("tls1",myproto)) {
861 _ctx = SSL_CTX_new(TLSv1_client_method());
863 fprintf(stderr,GT_("Invalid SSL protocol '%s' specified, using default (SSLv23).\n"), myproto);
868 _ctx = SSL_CTX_new(SSLv23_client_method());
871 ERR_print_errors_fp(stderr);
877 SSL_CTX_set_verify(_ctx, SSL_VERIFY_PEER, SSL_ck_verify_callback);
879 SSL_CTX_load_verify_locations(_ctx, NULL, certpath);
881 /* In this case, we do not fail if verification fails. However,
882 * we provide the callback for output and possible fingerprint checks. */
883 SSL_CTX_set_verify(_ctx, SSL_VERIFY_PEER, SSL_nock_verify_callback);
886 _ssl_context[sock] = SSL_new(_ctx);
888 if(_ssl_context[sock] == NULL) {
889 ERR_print_errors_fp(stderr);
893 /* This static is for the verify callback */
894 _ssl_server_cname = servercname;
895 _server_label = label;
897 _check_digest = fingerprint;
900 if( mycert || mykey ) {
902 /* Ok... He has a certificate file defined, so lets declare it. If
903 * he does NOT have a separate certificate and private key file then
904 * assume that it's a combined key and certificate file.
910 SSL_use_certificate_file(_ssl_context[sock], mycert, SSL_FILETYPE_PEM);
911 SSL_use_RSAPrivateKey_file(_ssl_context[sock], mykey, SSL_FILETYPE_PEM);
914 SSL_set_fd(_ssl_context[sock], sock);
916 if(SSL_connect(_ssl_context[sock]) == -1) {
917 ERR_print_errors_fp(stderr);
921 /* Paranoia: was the callback not called as we expected? */
922 if ((fingerprint != NULL || certck) && !_depth0ck) {
923 report(stderr, GT_("Certificate/fingerprint verification was somehow skipped!\n"));
925 if( NULL != ( ssl = SSLGetContext( sock ) ) ) {
926 /* Clean up the SSL stack */
927 SSL_free( _ssl_context[sock] );
928 _ssl_context[sock] = NULL;
937 int SockClose(int sock)
938 /* close a socket gracefully */
943 if( NULL != ( ssl = SSLGetContext( sock ) ) ) {
944 /* Clean up the SSL stack */
945 SSL_free( _ssl_context[sock] );
946 _ssl_context[sock] = NULL;
952 * This hangs in RedHat 6.2 after fetchmail runs for a while a
953 * FIN_WAIT2 comes up in netstat and fetchmail never returns from
954 * the recv system call. (Reported from jtnews
955 * <jtnews@bellatlantic.net>, Wed, 24 May 2000 21:26:02.)
957 * Half-close the connection first so the other end gets notified.
959 * This stops sends but allows receives (effectively, it sends a
961 if (shutdown(sock, 1) == 0) {
963 /* If there is any data still waiting in the queue, discard it.
964 * Call recv() until either it returns 0 (meaning we received a FIN)
965 * or any error occurs. This makes sure all data sent by the other
966 * side is acknowledged at the TCP level.
968 if (fm_peek(sock, &ch, 1) > 0)
969 while (fm_read(sock, &ch, 1) > 0)
972 #endif /* __UNUSED__ */
974 /* if there's an error closing at this point, not much we can do */
975 return(fm_close(sock)); /* this is guarded */
980 * Use the chargen service to test input buffering directly.
981 * You may have to uncomment the `chargen' service description in your
982 * inetd.conf (and then SIGHUP inetd) for this to work. */
985 int sock = SockOpen("localhost", 19, NULL);
988 while (SockRead(sock, buf, sizeof(buf)-1))
989 SockWrite(1, buf, strlen(buf));
994 /* socket.c ends here */