blob: 97b193d13e2a904cc3f9b6d4076ab20aac1208e7 [file] [log] [blame]
Paul Bakker5121ce52009-01-03 21:22:43 +00001/*
2 * TCP networking functions
3 *
Paul Bakkerfa9b1002013-07-03 15:31:03 +02004 * Copyright (C) 2006-2013, Brainspark B.V.
Paul Bakkerb96f1542010-07-18 20:36:00 +00005 *
6 * This file is part of PolarSSL (http://www.polarssl.org)
Paul Bakker84f12b72010-07-18 10:13:04 +00007 * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
Paul Bakkerb96f1542010-07-18 20:36:00 +00008 *
Paul Bakker77b385e2009-07-28 17:23:11 +00009 * All rights reserved.
Paul Bakkere0ccd0a2009-01-04 16:27:10 +000010 *
Paul Bakker5121ce52009-01-03 21:22:43 +000011 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License along
22 * with this program; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 */
25
Paul Bakker40e46942009-01-03 21:51:57 +000026#include "polarssl/config.h"
Paul Bakker5121ce52009-01-03 21:22:43 +000027
Paul Bakker40e46942009-01-03 21:51:57 +000028#if defined(POLARSSL_NET_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000029
Paul Bakker40e46942009-01-03 21:51:57 +000030#include "polarssl/net.h"
Paul Bakker5121ce52009-01-03 21:22:43 +000031
Paul Bakkerfa6a6202013-10-28 18:48:30 +010032#if (defined(_WIN32) || defined(_WIN32_WCE)) && !defined(EFIX64) && \
33 !defined(EFI32)
Paul Bakker5121ce52009-01-03 21:22:43 +000034
35#include <winsock2.h>
36#include <windows.h>
37
38#if defined(_WIN32_WCE)
39#pragma comment( lib, "ws2.lib" )
40#else
41#pragma comment( lib, "ws2_32.lib" )
42#endif
43
Paul Bakkerf4f69682011-04-24 16:08:12 +000044#define read(fd,buf,len) recv(fd,(char*)buf,(int) len,0)
45#define write(fd,buf,len) send(fd,(char*)buf,(int) len,0)
Paul Bakker5121ce52009-01-03 21:22:43 +000046#define close(fd) closesocket(fd)
47
48static int wsa_init_done = 0;
49
50#else
51
52#include <sys/types.h>
53#include <sys/socket.h>
54#include <netinet/in.h>
55#include <arpa/inet.h>
Paul Bakkerfa9b1002013-07-03 15:31:03 +020056#if defined(POLARSSL_HAVE_TIME)
Paul Bakker5121ce52009-01-03 21:22:43 +000057#include <sys/time.h>
Paul Bakkerfa9b1002013-07-03 15:31:03 +020058#endif
Paul Bakker5121ce52009-01-03 21:22:43 +000059#include <unistd.h>
60#include <signal.h>
61#include <fcntl.h>
62#include <netdb.h>
63#include <errno.h>
Paul Bakkerb3bb6c02009-07-27 21:09:47 +000064
Paul Bakker6a2f8572012-08-23 07:45:37 +000065#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || \
66 defined(__DragonflyBSD__)
Paul Bakker854963c2009-07-19 20:50:11 +000067#include <sys/endian.h>
Paul Bakkerfa6a6202013-10-28 18:48:30 +010068#elif defined(__APPLE__) || defined(HAVE_MACHINE_ENDIAN_H) || \
69 defined(EFIX64) || defined(EFI32)
Paul Bakkerb3bb6c02009-07-27 21:09:47 +000070#include <machine/endian.h>
Paul Bakker61264812012-04-03 07:54:30 +000071#elif defined(sun)
72#include <sys/isa_defs.h>
Paul Bakker1e6a1752013-07-26 14:10:22 +020073#elif defined(_AIX) || defined(HAVE_ARPA_NAMESER_COMPAT_H)
74#include <arpa/nameser_compat.h>
Paul Bakker854963c2009-07-19 20:50:11 +000075#else
Paul Bakker1d4f30c2009-04-19 18:55:16 +000076#include <endian.h>
Paul Bakker854963c2009-07-19 20:50:11 +000077#endif
Paul Bakker5121ce52009-01-03 21:22:43 +000078
79#endif
80
Paul Bakker5121ce52009-01-03 21:22:43 +000081#include <stdlib.h>
82#include <stdio.h>
Paul Bakkerfa9b1002013-07-03 15:31:03 +020083
Manuel Pégourié-Gonnard10934de2013-12-13 12:54:09 +010084#if defined(_MSC_VER) && !defined snprintf && !defined(EFIX64) && \
85 !defined(EFI32)
86#define snprintf _snprintf
87#endif
88
Paul Bakkerfa9b1002013-07-03 15:31:03 +020089#if defined(POLARSSL_HAVE_TIME)
Paul Bakker5121ce52009-01-03 21:22:43 +000090#include <time.h>
Paul Bakkerfa9b1002013-07-03 15:31:03 +020091#endif
Paul Bakker5121ce52009-01-03 21:22:43 +000092
Paul Bakkerfa6a6202013-10-28 18:48:30 +010093#if defined(_MSC_VER) && !defined(EFIX64) && !defined(EFI32)
Paul Bakker5c2364c2012-10-01 14:41:15 +000094#include <basetsd.h>
95typedef UINT32 uint32_t;
96#else
97#include <inttypes.h>
98#endif
99
Paul Bakker5121ce52009-01-03 21:22:43 +0000100/*
Paul Bakker1d4f30c2009-04-19 18:55:16 +0000101 * htons() is not always available.
102 * By default go for LITTLE_ENDIAN variant. Otherwise hope for _BYTE_ORDER and __BIG_ENDIAN
Paul Bakker60b1d102013-10-29 10:02:51 +0100103 * to help determine endianness.
Paul Bakker5121ce52009-01-03 21:22:43 +0000104 */
Paul Bakker1d4f30c2009-04-19 18:55:16 +0000105#if defined(__BYTE_ORDER) && defined(__BIG_ENDIAN) && __BYTE_ORDER == __BIG_ENDIAN
Paul Bakkerb3bb6c02009-07-27 21:09:47 +0000106#define POLARSSL_HTONS(n) (n)
Paul Bakker37286a52013-03-06 16:55:11 +0100107#define POLARSSL_HTONL(n) (n)
Paul Bakker1d4f30c2009-04-19 18:55:16 +0000108#else
Paul Bakker37286a52013-03-06 16:55:11 +0100109#define POLARSSL_HTONS(n) ((((unsigned short)(n) & 0xFF ) << 8 ) | \
110 (((unsigned short)(n) & 0xFF00 ) >> 8 ))
111#define POLARSSL_HTONL(n) ((((unsigned long )(n) & 0xFF ) << 24) | \
112 (((unsigned long )(n) & 0xFF00 ) << 8 ) | \
113 (((unsigned long )(n) & 0xFF0000 ) >> 8 ) | \
114 (((unsigned long )(n) & 0xFF000000) >> 24))
Paul Bakker1d4f30c2009-04-19 18:55:16 +0000115#endif
Paul Bakker5121ce52009-01-03 21:22:43 +0000116
Paul Bakker1d4f30c2009-04-19 18:55:16 +0000117unsigned short net_htons(unsigned short n);
Paul Bakker37286a52013-03-06 16:55:11 +0100118unsigned long net_htonl(unsigned long n);
Paul Bakkerb3bb6c02009-07-27 21:09:47 +0000119#define net_htons(n) POLARSSL_HTONS(n)
Paul Bakker37286a52013-03-06 16:55:11 +0100120#define net_htonl(n) POLARSSL_HTONL(n)
Paul Bakker5121ce52009-01-03 21:22:43 +0000121
122/*
Manuel Pégourié-Gonnard2e5c3162013-12-13 11:55:32 +0100123 * Prepare for using the sockets interface
Paul Bakker5121ce52009-01-03 21:22:43 +0000124 */
Manuel Pégourié-Gonnard2e5c3162013-12-13 11:55:32 +0100125static void net_prepare( void )
Paul Bakker5121ce52009-01-03 21:22:43 +0000126{
Paul Bakkerfa6a6202013-10-28 18:48:30 +0100127#if ( defined(_WIN32) || defined(_WIN32_WCE) ) && !defined(EFIX64) && \
128 !defined(EFI32)
Paul Bakker5121ce52009-01-03 21:22:43 +0000129 WSADATA wsaData;
130
131 if( wsa_init_done == 0 )
132 {
133 if( WSAStartup( MAKEWORD(2,0), &wsaData ) == SOCKET_ERROR )
Paul Bakker40e46942009-01-03 21:51:57 +0000134 return( POLARSSL_ERR_NET_SOCKET_FAILED );
Paul Bakker5121ce52009-01-03 21:22:43 +0000135
136 wsa_init_done = 1;
137 }
138#else
Paul Bakkerfa6a6202013-10-28 18:48:30 +0100139#if !defined(EFIX64) && !defined(EFI32)
Paul Bakker5121ce52009-01-03 21:22:43 +0000140 signal( SIGPIPE, SIG_IGN );
141#endif
Paul Bakkerfa6a6202013-10-28 18:48:30 +0100142#endif
Manuel Pégourié-Gonnard2e5c3162013-12-13 11:55:32 +0100143}
144
145/*
146 * Initiate a TCP connection with host:port
147 */
148int net_connect( int *fd, const char *host, int port )
149{
Manuel Pégourié-Gonnard10934de2013-12-13 12:54:09 +0100150#if defined(POLARSSL_HAVE_IPV6)
151 int ret = POLARSSL_ERR_NET_UNKNOWN_HOST;
152 struct addrinfo hints, *addr_list, *cur;
153 char port_str[6];
154
155 net_prepare();
156
157 /* getaddrinfo expects port as a string */
158 memset( port_str, 0, sizeof( port_str ) );
159 snprintf( port_str, sizeof( port_str ), "%d", port );
160
161 /* Do name resolution with both IPv6 and IPv4, but only TCP */
162 memset( &hints, 0, sizeof( hints ) );
163 hints.ai_family = AF_UNSPEC;
164 hints.ai_socktype = SOCK_STREAM;
165 hints.ai_protocol = IPPROTO_TCP;
166
167 if( getaddrinfo( host, port_str, &hints, &addr_list ) != 0 )
168 return( POLARSSL_ERR_NET_UNKNOWN_HOST );
169
170 /* Try the sockaddrs until a connection succeeds */
171 for( cur = addr_list; cur != NULL; cur = cur->ai_next )
172 {
173 *fd = socket( cur->ai_family, cur->ai_socktype, cur->ai_protocol );
174 if( *fd < 0 )
175 {
176 ret = POLARSSL_ERR_NET_SOCKET_FAILED;
177 continue;
178 }
179
180 if( connect( *fd, cur->ai_addr, cur->ai_addrlen ) == 0 )
181 {
182 ret = 0;
183 break;
184 }
185
186 close( *fd );
187 ret = POLARSSL_ERR_NET_CONNECT_FAILED;
188 }
189
190 freeaddrinfo( addr_list );
191
192 return( ret );
193
194#else
195 /* Legacy IPv4-only version */
196
Manuel Pégourié-Gonnard2e5c3162013-12-13 11:55:32 +0100197 struct sockaddr_in server_addr;
198 struct hostent *server_host;
199
200 net_prepare();
Paul Bakker5121ce52009-01-03 21:22:43 +0000201
202 if( ( server_host = gethostbyname( host ) ) == NULL )
Paul Bakker40e46942009-01-03 21:51:57 +0000203 return( POLARSSL_ERR_NET_UNKNOWN_HOST );
Paul Bakker5121ce52009-01-03 21:22:43 +0000204
Paul Bakkerbbc10072013-10-14 16:33:24 +0200205 if( ( *fd = (int) socket( AF_INET, SOCK_STREAM, IPPROTO_IP ) ) < 0 )
Paul Bakker40e46942009-01-03 21:51:57 +0000206 return( POLARSSL_ERR_NET_SOCKET_FAILED );
Paul Bakker5121ce52009-01-03 21:22:43 +0000207
208 memcpy( (void *) &server_addr.sin_addr,
209 (void *) server_host->h_addr,
210 server_host->h_length );
211
212 server_addr.sin_family = AF_INET;
213 server_addr.sin_port = net_htons( port );
214
215 if( connect( *fd, (struct sockaddr *) &server_addr,
216 sizeof( server_addr ) ) < 0 )
217 {
218 close( *fd );
Paul Bakker40e46942009-01-03 21:51:57 +0000219 return( POLARSSL_ERR_NET_CONNECT_FAILED );
Paul Bakker5121ce52009-01-03 21:22:43 +0000220 }
221
222 return( 0 );
Manuel Pégourié-Gonnard10934de2013-12-13 12:54:09 +0100223#endif /* POLARSSL_HAVE_IPV6 */
Paul Bakker5121ce52009-01-03 21:22:43 +0000224}
225
226/*
227 * Create a listening socket on bind_ip:port
228 */
Paul Bakkerff60ee62010-03-16 21:09:09 +0000229int net_bind( int *fd, const char *bind_ip, int port )
Paul Bakker5121ce52009-01-03 21:22:43 +0000230{
231 int n, c[4];
232 struct sockaddr_in server_addr;
233
Manuel Pégourié-Gonnard2e5c3162013-12-13 11:55:32 +0100234 net_prepare();
Paul Bakker5121ce52009-01-03 21:22:43 +0000235
Paul Bakkerbbc10072013-10-14 16:33:24 +0200236 if( ( *fd = (int) socket( AF_INET, SOCK_STREAM, IPPROTO_IP ) ) < 0 )
Paul Bakker40e46942009-01-03 21:51:57 +0000237 return( POLARSSL_ERR_NET_SOCKET_FAILED );
Paul Bakker5121ce52009-01-03 21:22:43 +0000238
239 n = 1;
240 setsockopt( *fd, SOL_SOCKET, SO_REUSEADDR,
241 (const char *) &n, sizeof( n ) );
242
Paul Bakker37286a52013-03-06 16:55:11 +0100243 server_addr.sin_addr.s_addr = net_htonl( INADDR_ANY );
Paul Bakker5121ce52009-01-03 21:22:43 +0000244 server_addr.sin_family = AF_INET;
245 server_addr.sin_port = net_htons( port );
246
247 if( bind_ip != NULL )
248 {
249 memset( c, 0, sizeof( c ) );
250 sscanf( bind_ip, "%d.%d.%d.%d", &c[0], &c[1], &c[2], &c[3] );
251
252 for( n = 0; n < 4; n++ )
253 if( c[n] < 0 || c[n] > 255 )
254 break;
255
256 if( n == 4 )
Paul Bakker37286a52013-03-06 16:55:11 +0100257 server_addr.sin_addr.s_addr = net_htonl(
Paul Bakker5c2364c2012-10-01 14:41:15 +0000258 ( (uint32_t) c[0] << 24 ) |
259 ( (uint32_t) c[1] << 16 ) |
260 ( (uint32_t) c[2] << 8 ) |
Paul Bakker37286a52013-03-06 16:55:11 +0100261 ( (uint32_t) c[3] ) );
Paul Bakker5121ce52009-01-03 21:22:43 +0000262 }
263
264 if( bind( *fd, (struct sockaddr *) &server_addr,
265 sizeof( server_addr ) ) < 0 )
266 {
267 close( *fd );
Paul Bakker40e46942009-01-03 21:51:57 +0000268 return( POLARSSL_ERR_NET_BIND_FAILED );
Paul Bakker5121ce52009-01-03 21:22:43 +0000269 }
270
Paul Bakker192381a2011-05-20 12:31:31 +0000271 if( listen( *fd, POLARSSL_NET_LISTEN_BACKLOG ) != 0 )
Paul Bakker5121ce52009-01-03 21:22:43 +0000272 {
273 close( *fd );
Paul Bakker40e46942009-01-03 21:51:57 +0000274 return( POLARSSL_ERR_NET_LISTEN_FAILED );
Paul Bakker5121ce52009-01-03 21:22:43 +0000275 }
276
277 return( 0 );
278}
279
280/*
281 * Check if the current operation is blocking
282 */
283static int net_is_blocking( void )
284{
Paul Bakkerfa6a6202013-10-28 18:48:30 +0100285#if ( defined(_WIN32) || defined(_WIN32_WCE) ) && !defined(EFIX64) && \
286 !defined(EFI32)
Paul Bakker5121ce52009-01-03 21:22:43 +0000287 return( WSAGetLastError() == WSAEWOULDBLOCK );
288#else
289 switch( errno )
290 {
291#if defined EAGAIN
292 case EAGAIN:
293#endif
294#if defined EWOULDBLOCK && EWOULDBLOCK != EAGAIN
295 case EWOULDBLOCK:
296#endif
297 return( 1 );
298 }
299 return( 0 );
300#endif
301}
302
303/*
304 * Accept a connection from a remote client
305 */
306int net_accept( int bind_fd, int *client_fd, void *client_ip )
307{
308 struct sockaddr_in client_addr;
309
Paul Bakker394c56f2011-12-20 12:19:03 +0000310#if defined(__socklen_t_defined) || defined(_SOCKLEN_T) || \
311 defined(_SOCKLEN_T_DECLARED)
Paul Bakker5121ce52009-01-03 21:22:43 +0000312 socklen_t n = (socklen_t) sizeof( client_addr );
313#else
314 int n = (int) sizeof( client_addr );
315#endif
316
Paul Bakkerbbc10072013-10-14 16:33:24 +0200317 *client_fd = (int) accept( bind_fd, (struct sockaddr *)
318 &client_addr, &n );
Paul Bakker5121ce52009-01-03 21:22:43 +0000319
320 if( *client_fd < 0 )
321 {
322 if( net_is_blocking() != 0 )
Paul Bakker831a7552011-05-18 13:32:51 +0000323 return( POLARSSL_ERR_NET_WANT_READ );
Paul Bakker5121ce52009-01-03 21:22:43 +0000324
Paul Bakker40e46942009-01-03 21:51:57 +0000325 return( POLARSSL_ERR_NET_ACCEPT_FAILED );
Paul Bakker5121ce52009-01-03 21:22:43 +0000326 }
327
328 if( client_ip != NULL )
329 memcpy( client_ip, &client_addr.sin_addr.s_addr,
330 sizeof( client_addr.sin_addr.s_addr ) );
331
332 return( 0 );
333}
334
335/*
336 * Set the socket blocking or non-blocking
337 */
338int net_set_block( int fd )
339{
Paul Bakkerfa6a6202013-10-28 18:48:30 +0100340#if ( defined(_WIN32) || defined(_WIN32_WCE) ) && !defined(EFIX64) && \
341 !defined(EFI32)
Paul Bakkerf4f69682011-04-24 16:08:12 +0000342 u_long n = 0;
Paul Bakker5121ce52009-01-03 21:22:43 +0000343 return( ioctlsocket( fd, FIONBIO, &n ) );
344#else
345 return( fcntl( fd, F_SETFL, fcntl( fd, F_GETFL ) & ~O_NONBLOCK ) );
346#endif
347}
348
349int net_set_nonblock( int fd )
350{
Paul Bakkerfa6a6202013-10-28 18:48:30 +0100351#if ( defined(_WIN32) || defined(_WIN32_WCE) ) && !defined(EFIX64) && \
352 !defined(EFI32)
Paul Bakkerf4f69682011-04-24 16:08:12 +0000353 u_long n = 1;
Paul Bakker5121ce52009-01-03 21:22:43 +0000354 return( ioctlsocket( fd, FIONBIO, &n ) );
355#else
356 return( fcntl( fd, F_SETFL, fcntl( fd, F_GETFL ) | O_NONBLOCK ) );
357#endif
358}
359
Paul Bakkerfa9b1002013-07-03 15:31:03 +0200360#if defined(POLARSSL_HAVE_TIME)
Paul Bakker5121ce52009-01-03 21:22:43 +0000361/*
362 * Portable usleep helper
363 */
364void net_usleep( unsigned long usec )
365{
366 struct timeval tv;
367 tv.tv_sec = 0;
368 tv.tv_usec = usec;
369 select( 0, NULL, NULL, NULL, &tv );
370}
Paul Bakkerfa9b1002013-07-03 15:31:03 +0200371#endif /* POLARSSL_HAVE_TIME */
Paul Bakker5121ce52009-01-03 21:22:43 +0000372
373/*
374 * Read at most 'len' characters
375 */
Paul Bakker23986e52011-04-24 08:57:21 +0000376int net_recv( void *ctx, unsigned char *buf, size_t len )
Paul Bakkerfa6a6202013-10-28 18:48:30 +0100377{
Paul Bakker5121ce52009-01-03 21:22:43 +0000378 int ret = read( *((int *) ctx), buf, len );
379
Paul Bakker5121ce52009-01-03 21:22:43 +0000380 if( ret < 0 )
381 {
382 if( net_is_blocking() != 0 )
Paul Bakker831a7552011-05-18 13:32:51 +0000383 return( POLARSSL_ERR_NET_WANT_READ );
Paul Bakker5121ce52009-01-03 21:22:43 +0000384
Paul Bakkerfa6a6202013-10-28 18:48:30 +0100385#if ( defined(_WIN32) || defined(_WIN32_WCE) ) && !defined(EFIX64) && \
386 !defined(EFI32)
Paul Bakker5121ce52009-01-03 21:22:43 +0000387 if( WSAGetLastError() == WSAECONNRESET )
Paul Bakker40e46942009-01-03 21:51:57 +0000388 return( POLARSSL_ERR_NET_CONN_RESET );
Paul Bakker5121ce52009-01-03 21:22:43 +0000389#else
390 if( errno == EPIPE || errno == ECONNRESET )
Paul Bakker40e46942009-01-03 21:51:57 +0000391 return( POLARSSL_ERR_NET_CONN_RESET );
Paul Bakker5121ce52009-01-03 21:22:43 +0000392
393 if( errno == EINTR )
Paul Bakker831a7552011-05-18 13:32:51 +0000394 return( POLARSSL_ERR_NET_WANT_READ );
Paul Bakker5121ce52009-01-03 21:22:43 +0000395#endif
396
Paul Bakker40e46942009-01-03 21:51:57 +0000397 return( POLARSSL_ERR_NET_RECV_FAILED );
Paul Bakker5121ce52009-01-03 21:22:43 +0000398 }
399
400 return( ret );
401}
402
403/*
404 * Write at most 'len' characters
405 */
Paul Bakker39bb4182011-06-21 07:36:43 +0000406int net_send( void *ctx, const unsigned char *buf, size_t len )
Paul Bakker5121ce52009-01-03 21:22:43 +0000407{
408 int ret = write( *((int *) ctx), buf, len );
409
410 if( ret < 0 )
411 {
412 if( net_is_blocking() != 0 )
Paul Bakker831a7552011-05-18 13:32:51 +0000413 return( POLARSSL_ERR_NET_WANT_WRITE );
Paul Bakker5121ce52009-01-03 21:22:43 +0000414
Paul Bakkerfa6a6202013-10-28 18:48:30 +0100415#if ( defined(_WIN32) || defined(_WIN32_WCE) ) && !defined(EFIX64) && \
416 !defined(EFI32)
Paul Bakker5121ce52009-01-03 21:22:43 +0000417 if( WSAGetLastError() == WSAECONNRESET )
Paul Bakker40e46942009-01-03 21:51:57 +0000418 return( POLARSSL_ERR_NET_CONN_RESET );
Paul Bakker5121ce52009-01-03 21:22:43 +0000419#else
420 if( errno == EPIPE || errno == ECONNRESET )
Paul Bakker40e46942009-01-03 21:51:57 +0000421 return( POLARSSL_ERR_NET_CONN_RESET );
Paul Bakker5121ce52009-01-03 21:22:43 +0000422
423 if( errno == EINTR )
Paul Bakker831a7552011-05-18 13:32:51 +0000424 return( POLARSSL_ERR_NET_WANT_WRITE );
Paul Bakker5121ce52009-01-03 21:22:43 +0000425#endif
426
Paul Bakker40e46942009-01-03 21:51:57 +0000427 return( POLARSSL_ERR_NET_SEND_FAILED );
Paul Bakker5121ce52009-01-03 21:22:43 +0000428 }
429
430 return( ret );
431}
432
433/*
434 * Gracefully close the connection
435 */
436void net_close( int fd )
437{
438 shutdown( fd, 2 );
439 close( fd );
440}
441
442#endif