xref: /minix3/crypto/external/bsd/heimdal/dist/lib/roken/socket.c (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc /*	$NetBSD: socket.c,v 1.1.1.2 2014/04/24 12:45:52 pettai Exp $	*/
2ebfedea0SLionel Sambuc 
3ebfedea0SLionel Sambuc /*
4ebfedea0SLionel Sambuc  * Copyright (c) 1999 - 2000 Kungliga Tekniska Högskolan
5ebfedea0SLionel Sambuc  * (Royal Institute of Technology, Stockholm, Sweden).
6ebfedea0SLionel Sambuc  * All rights reserved.
7ebfedea0SLionel Sambuc  *
8ebfedea0SLionel Sambuc  * Redistribution and use in source and binary forms, with or without
9ebfedea0SLionel Sambuc  * modification, are permitted provided that the following conditions
10ebfedea0SLionel Sambuc  * are met:
11ebfedea0SLionel Sambuc  *
12ebfedea0SLionel Sambuc  * 1. Redistributions of source code must retain the above copyright
13ebfedea0SLionel Sambuc  *    notice, this list of conditions and the following disclaimer.
14ebfedea0SLionel Sambuc  *
15ebfedea0SLionel Sambuc  * 2. Redistributions in binary form must reproduce the above copyright
16ebfedea0SLionel Sambuc  *    notice, this list of conditions and the following disclaimer in the
17ebfedea0SLionel Sambuc  *    documentation and/or other materials provided with the distribution.
18ebfedea0SLionel Sambuc  *
19ebfedea0SLionel Sambuc  * 3. Neither the name of the Institute nor the names of its contributors
20ebfedea0SLionel Sambuc  *    may be used to endorse or promote products derived from this software
21ebfedea0SLionel Sambuc  *    without specific prior written permission.
22ebfedea0SLionel Sambuc  *
23ebfedea0SLionel Sambuc  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
24ebfedea0SLionel Sambuc  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25ebfedea0SLionel Sambuc  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26ebfedea0SLionel Sambuc  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
27ebfedea0SLionel Sambuc  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28ebfedea0SLionel Sambuc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29ebfedea0SLionel Sambuc  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30ebfedea0SLionel Sambuc  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31ebfedea0SLionel Sambuc  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32ebfedea0SLionel Sambuc  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33ebfedea0SLionel Sambuc  * SUCH DAMAGE.
34ebfedea0SLionel Sambuc  */
35ebfedea0SLionel Sambuc 
36ebfedea0SLionel Sambuc #include <config.h>
37ebfedea0SLionel Sambuc 
38ebfedea0SLionel Sambuc #include <krb5/roken.h>
39ebfedea0SLionel Sambuc #include <err.h>
40ebfedea0SLionel Sambuc 
41ebfedea0SLionel Sambuc /*
42ebfedea0SLionel Sambuc  * Set `sa' to the unitialized address of address family `af'
43ebfedea0SLionel Sambuc  */
44ebfedea0SLionel Sambuc 
45ebfedea0SLionel Sambuc ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
socket_set_any(struct sockaddr * sa,int af)46ebfedea0SLionel Sambuc socket_set_any (struct sockaddr *sa, int af)
47ebfedea0SLionel Sambuc {
48ebfedea0SLionel Sambuc     switch (af) {
49ebfedea0SLionel Sambuc     case AF_INET : {
50ebfedea0SLionel Sambuc 	struct sockaddr_in *sin4 = (struct sockaddr_in *)sa;
51ebfedea0SLionel Sambuc 
52ebfedea0SLionel Sambuc 	memset (sin4, 0, sizeof(*sin4));
53ebfedea0SLionel Sambuc 	sin4->sin_family = AF_INET;
54ebfedea0SLionel Sambuc 	sin4->sin_port   = 0;
55ebfedea0SLionel Sambuc 	sin4->sin_addr.s_addr = INADDR_ANY;
56ebfedea0SLionel Sambuc 	break;
57ebfedea0SLionel Sambuc     }
58ebfedea0SLionel Sambuc #ifdef HAVE_IPV6
59ebfedea0SLionel Sambuc     case AF_INET6 : {
60ebfedea0SLionel Sambuc 	struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa;
61ebfedea0SLionel Sambuc 
62ebfedea0SLionel Sambuc 	memset (sin6, 0, sizeof(*sin6));
63ebfedea0SLionel Sambuc 	sin6->sin6_family = AF_INET6;
64ebfedea0SLionel Sambuc 	sin6->sin6_port   = 0;
65ebfedea0SLionel Sambuc 	sin6->sin6_addr   = in6addr_any;
66ebfedea0SLionel Sambuc 	break;
67ebfedea0SLionel Sambuc     }
68ebfedea0SLionel Sambuc #endif
69ebfedea0SLionel Sambuc     default :
70ebfedea0SLionel Sambuc 	errx (1, "unknown address family %d", sa->sa_family);
71ebfedea0SLionel Sambuc 	break;
72ebfedea0SLionel Sambuc     }
73ebfedea0SLionel Sambuc }
74ebfedea0SLionel Sambuc 
75ebfedea0SLionel Sambuc /*
76ebfedea0SLionel Sambuc  * set `sa' to (`ptr', `port')
77ebfedea0SLionel Sambuc  */
78ebfedea0SLionel Sambuc 
79ebfedea0SLionel Sambuc ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
socket_set_address_and_port(struct sockaddr * sa,const void * ptr,int port)80ebfedea0SLionel Sambuc socket_set_address_and_port (struct sockaddr *sa, const void *ptr, int port)
81ebfedea0SLionel Sambuc {
82ebfedea0SLionel Sambuc     switch (sa->sa_family) {
83ebfedea0SLionel Sambuc     case AF_INET : {
84ebfedea0SLionel Sambuc 	struct sockaddr_in *sin4 = (struct sockaddr_in *)sa;
85ebfedea0SLionel Sambuc 
86ebfedea0SLionel Sambuc 	memset (sin4, 0, sizeof(*sin4));
87ebfedea0SLionel Sambuc 	sin4->sin_family = AF_INET;
88ebfedea0SLionel Sambuc 	sin4->sin_port   = port;
89ebfedea0SLionel Sambuc 	memcpy (&sin4->sin_addr, ptr, sizeof(struct in_addr));
90ebfedea0SLionel Sambuc 	break;
91ebfedea0SLionel Sambuc     }
92ebfedea0SLionel Sambuc #ifdef HAVE_IPV6
93ebfedea0SLionel Sambuc     case AF_INET6 : {
94ebfedea0SLionel Sambuc 	struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa;
95ebfedea0SLionel Sambuc 
96ebfedea0SLionel Sambuc 	memset (sin6, 0, sizeof(*sin6));
97ebfedea0SLionel Sambuc 	sin6->sin6_family = AF_INET6;
98ebfedea0SLionel Sambuc 	sin6->sin6_port   = port;
99ebfedea0SLionel Sambuc 	memcpy (&sin6->sin6_addr, ptr, sizeof(struct in6_addr));
100ebfedea0SLionel Sambuc 	break;
101ebfedea0SLionel Sambuc     }
102ebfedea0SLionel Sambuc #endif
103ebfedea0SLionel Sambuc     default :
104ebfedea0SLionel Sambuc 	errx (1, "unknown address family %d", sa->sa_family);
105ebfedea0SLionel Sambuc 	break;
106ebfedea0SLionel Sambuc     }
107ebfedea0SLionel Sambuc }
108ebfedea0SLionel Sambuc 
109ebfedea0SLionel Sambuc /*
110ebfedea0SLionel Sambuc  * Return the size of an address of the type in `sa'
111ebfedea0SLionel Sambuc  */
112ebfedea0SLionel Sambuc 
113ebfedea0SLionel Sambuc ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL
socket_addr_size(const struct sockaddr * sa)114ebfedea0SLionel Sambuc socket_addr_size (const struct sockaddr *sa)
115ebfedea0SLionel Sambuc {
116ebfedea0SLionel Sambuc     switch (sa->sa_family) {
117ebfedea0SLionel Sambuc     case AF_INET :
118ebfedea0SLionel Sambuc 	return sizeof(struct in_addr);
119ebfedea0SLionel Sambuc #ifdef HAVE_IPV6
120ebfedea0SLionel Sambuc     case AF_INET6 :
121ebfedea0SLionel Sambuc 	return sizeof(struct in6_addr);
122ebfedea0SLionel Sambuc #endif
123ebfedea0SLionel Sambuc     default :
124ebfedea0SLionel Sambuc 	return 0;
125ebfedea0SLionel Sambuc     }
126ebfedea0SLionel Sambuc }
127ebfedea0SLionel Sambuc 
128ebfedea0SLionel Sambuc /*
129ebfedea0SLionel Sambuc  * Return the size of a `struct sockaddr' in `sa'.
130ebfedea0SLionel Sambuc  */
131ebfedea0SLionel Sambuc 
132ebfedea0SLionel Sambuc ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL
socket_sockaddr_size(const struct sockaddr * sa)133ebfedea0SLionel Sambuc socket_sockaddr_size (const struct sockaddr *sa)
134ebfedea0SLionel Sambuc {
135ebfedea0SLionel Sambuc     switch (sa->sa_family) {
136ebfedea0SLionel Sambuc     case AF_INET :
137ebfedea0SLionel Sambuc 	return sizeof(struct sockaddr_in);
138ebfedea0SLionel Sambuc #ifdef HAVE_IPV6
139ebfedea0SLionel Sambuc     case AF_INET6 :
140ebfedea0SLionel Sambuc 	return sizeof(struct sockaddr_in6);
141ebfedea0SLionel Sambuc #endif
142ebfedea0SLionel Sambuc     default:
143ebfedea0SLionel Sambuc 	return 0;
144ebfedea0SLionel Sambuc     }
145ebfedea0SLionel Sambuc }
146ebfedea0SLionel Sambuc 
147ebfedea0SLionel Sambuc /*
148ebfedea0SLionel Sambuc  * Return the binary address of `sa'.
149ebfedea0SLionel Sambuc  */
150ebfedea0SLionel Sambuc 
151ebfedea0SLionel Sambuc ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL
socket_get_address(const struct sockaddr * sa)152ebfedea0SLionel Sambuc socket_get_address (const struct sockaddr *sa)
153ebfedea0SLionel Sambuc {
154ebfedea0SLionel Sambuc     switch (sa->sa_family) {
155ebfedea0SLionel Sambuc     case AF_INET : {
156ebfedea0SLionel Sambuc 	const struct sockaddr_in *sin4 = (const struct sockaddr_in *)sa;
157ebfedea0SLionel Sambuc 	return rk_UNCONST(&sin4->sin_addr);
158ebfedea0SLionel Sambuc     }
159ebfedea0SLionel Sambuc #ifdef HAVE_IPV6
160ebfedea0SLionel Sambuc     case AF_INET6 : {
161ebfedea0SLionel Sambuc 	const struct sockaddr_in6 *sin6 = (const struct sockaddr_in6 *)sa;
162ebfedea0SLionel Sambuc 	return rk_UNCONST(&sin6->sin6_addr);
163ebfedea0SLionel Sambuc     }
164ebfedea0SLionel Sambuc #endif
165ebfedea0SLionel Sambuc     default:
166ebfedea0SLionel Sambuc 	return NULL;
167ebfedea0SLionel Sambuc     }
168ebfedea0SLionel Sambuc }
169ebfedea0SLionel Sambuc 
170ebfedea0SLionel Sambuc /*
171ebfedea0SLionel Sambuc  * Return the port number from `sa'.
172ebfedea0SLionel Sambuc  */
173ebfedea0SLionel Sambuc 
174ebfedea0SLionel Sambuc ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
socket_get_port(const struct sockaddr * sa)175ebfedea0SLionel Sambuc socket_get_port (const struct sockaddr *sa)
176ebfedea0SLionel Sambuc {
177ebfedea0SLionel Sambuc     switch (sa->sa_family) {
178ebfedea0SLionel Sambuc     case AF_INET : {
179ebfedea0SLionel Sambuc 	const struct sockaddr_in *sin4 = (const struct sockaddr_in *)sa;
180ebfedea0SLionel Sambuc 	return sin4->sin_port;
181ebfedea0SLionel Sambuc     }
182ebfedea0SLionel Sambuc #ifdef HAVE_IPV6
183ebfedea0SLionel Sambuc     case AF_INET6 : {
184ebfedea0SLionel Sambuc 	const struct sockaddr_in6 *sin6 = (const struct sockaddr_in6 *)sa;
185ebfedea0SLionel Sambuc 	return sin6->sin6_port;
186ebfedea0SLionel Sambuc     }
187ebfedea0SLionel Sambuc #endif
188ebfedea0SLionel Sambuc     default :
189ebfedea0SLionel Sambuc 	return 0;
190ebfedea0SLionel Sambuc     }
191ebfedea0SLionel Sambuc }
192ebfedea0SLionel Sambuc 
193ebfedea0SLionel Sambuc /*
194ebfedea0SLionel Sambuc  * Set the port in `sa' to `port'.
195ebfedea0SLionel Sambuc  */
196ebfedea0SLionel Sambuc 
197ebfedea0SLionel Sambuc ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
socket_set_port(struct sockaddr * sa,int port)198ebfedea0SLionel Sambuc socket_set_port (struct sockaddr *sa, int port)
199ebfedea0SLionel Sambuc {
200ebfedea0SLionel Sambuc     switch (sa->sa_family) {
201ebfedea0SLionel Sambuc     case AF_INET : {
202ebfedea0SLionel Sambuc 	struct sockaddr_in *sin4 = (struct sockaddr_in *)sa;
203ebfedea0SLionel Sambuc 	sin4->sin_port = port;
204ebfedea0SLionel Sambuc 	break;
205ebfedea0SLionel Sambuc     }
206ebfedea0SLionel Sambuc #ifdef HAVE_IPV6
207ebfedea0SLionel Sambuc     case AF_INET6 : {
208ebfedea0SLionel Sambuc 	struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa;
209ebfedea0SLionel Sambuc 	sin6->sin6_port = port;
210ebfedea0SLionel Sambuc 	break;
211ebfedea0SLionel Sambuc     }
212ebfedea0SLionel Sambuc #endif
213ebfedea0SLionel Sambuc     default :
214ebfedea0SLionel Sambuc 	errx (1, "unknown address family %d", sa->sa_family);
215ebfedea0SLionel Sambuc 	break;
216ebfedea0SLionel Sambuc     }
217ebfedea0SLionel Sambuc }
218ebfedea0SLionel Sambuc 
219ebfedea0SLionel Sambuc /*
220ebfedea0SLionel Sambuc  * Set the range of ports to use when binding with port = 0.
221ebfedea0SLionel Sambuc  */
222ebfedea0SLionel Sambuc ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
socket_set_portrange(rk_socket_t sock,int restr,int af)223ebfedea0SLionel Sambuc socket_set_portrange (rk_socket_t sock, int restr, int af)
224ebfedea0SLionel Sambuc {
225ebfedea0SLionel Sambuc #if defined(IP_PORTRANGE)
226ebfedea0SLionel Sambuc 	if (af == AF_INET) {
227ebfedea0SLionel Sambuc 		int on = restr ? IP_PORTRANGE_HIGH : IP_PORTRANGE_DEFAULT;
228ebfedea0SLionel Sambuc 		setsockopt (sock, IPPROTO_IP, IP_PORTRANGE, &on, sizeof(on));
229ebfedea0SLionel Sambuc 	}
230ebfedea0SLionel Sambuc #endif
231ebfedea0SLionel Sambuc #if defined(IPV6_PORTRANGE)
232ebfedea0SLionel Sambuc 	if (af == AF_INET6) {
233ebfedea0SLionel Sambuc 		int on = restr ? IPV6_PORTRANGE_HIGH : IPV6_PORTRANGE_DEFAULT;
234ebfedea0SLionel Sambuc 		setsockopt (sock, IPPROTO_IPV6, IPV6_PORTRANGE, &on, sizeof(on));
235ebfedea0SLionel Sambuc 	}
236ebfedea0SLionel Sambuc #endif
237ebfedea0SLionel Sambuc }
238ebfedea0SLionel Sambuc 
239ebfedea0SLionel Sambuc /*
240ebfedea0SLionel Sambuc  * Enable debug on `sock'.
241ebfedea0SLionel Sambuc  */
242ebfedea0SLionel Sambuc 
243ebfedea0SLionel Sambuc ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
socket_set_debug(rk_socket_t sock)244ebfedea0SLionel Sambuc socket_set_debug (rk_socket_t sock)
245ebfedea0SLionel Sambuc {
246ebfedea0SLionel Sambuc #if defined(SO_DEBUG) && defined(HAVE_SETSOCKOPT)
247ebfedea0SLionel Sambuc     int on = 1;
248ebfedea0SLionel Sambuc     setsockopt (sock, SOL_SOCKET, SO_DEBUG, (void *) &on, sizeof (on));
249ebfedea0SLionel Sambuc #endif
250ebfedea0SLionel Sambuc }
251ebfedea0SLionel Sambuc 
252ebfedea0SLionel Sambuc /*
253ebfedea0SLionel Sambuc  * Set the type-of-service of `sock' to `tos'.
254ebfedea0SLionel Sambuc  */
255ebfedea0SLionel Sambuc 
256ebfedea0SLionel Sambuc ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
socket_set_tos(rk_socket_t sock,int tos)257ebfedea0SLionel Sambuc socket_set_tos (rk_socket_t sock, int tos)
258ebfedea0SLionel Sambuc {
259ebfedea0SLionel Sambuc #if defined(IP_TOS) && defined(HAVE_SETSOCKOPT)
260ebfedea0SLionel Sambuc     setsockopt (sock, IPPROTO_IP, IP_TOS, (void *) &tos, sizeof(int));
261ebfedea0SLionel Sambuc #endif
262ebfedea0SLionel Sambuc }
263ebfedea0SLionel Sambuc 
264ebfedea0SLionel Sambuc /*
265ebfedea0SLionel Sambuc  * set the reuse of addresses on `sock' to `val'.
266ebfedea0SLionel Sambuc  */
267ebfedea0SLionel Sambuc 
268ebfedea0SLionel Sambuc ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
socket_set_reuseaddr(rk_socket_t sock,int val)269ebfedea0SLionel Sambuc socket_set_reuseaddr (rk_socket_t sock, int val)
270ebfedea0SLionel Sambuc {
271ebfedea0SLionel Sambuc #if defined(SO_REUSEADDR) && defined(HAVE_SETSOCKOPT)
272ebfedea0SLionel Sambuc     setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (void *)&val, sizeof(val));
273ebfedea0SLionel Sambuc #endif
274ebfedea0SLionel Sambuc }
275ebfedea0SLionel Sambuc 
276ebfedea0SLionel Sambuc /*
277ebfedea0SLionel Sambuc  * Set the that the `sock' should bind to only IPv6 addresses.
278ebfedea0SLionel Sambuc  */
279ebfedea0SLionel Sambuc 
280ebfedea0SLionel Sambuc ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
socket_set_ipv6only(rk_socket_t sock,int val)281ebfedea0SLionel Sambuc socket_set_ipv6only (rk_socket_t sock, int val)
282ebfedea0SLionel Sambuc {
283ebfedea0SLionel Sambuc #if defined(IPV6_V6ONLY) && defined(HAVE_SETSOCKOPT)
284ebfedea0SLionel Sambuc     setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, (void *)&val, sizeof(val));
285ebfedea0SLionel Sambuc #endif
286ebfedea0SLionel Sambuc }
287ebfedea0SLionel Sambuc 
288ebfedea0SLionel Sambuc /**
289ebfedea0SLionel Sambuc  * Create a file descriptor from a socket
290ebfedea0SLionel Sambuc  *
291ebfedea0SLionel Sambuc  * While the socket handle in \a sock can be used with WinSock
292ebfedea0SLionel Sambuc  * functions after calling socket_to_fd(), it should not be closed
293ebfedea0SLionel Sambuc  * with rk_closesocket().  The socket will be closed when the associated
294ebfedea0SLionel Sambuc  * file descriptor is closed.
295ebfedea0SLionel Sambuc  */
296ebfedea0SLionel Sambuc ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
socket_to_fd(rk_socket_t sock,int flags)297ebfedea0SLionel Sambuc socket_to_fd(rk_socket_t sock, int flags)
298ebfedea0SLionel Sambuc {
299ebfedea0SLionel Sambuc #ifndef _WIN32
300ebfedea0SLionel Sambuc     return sock;
301ebfedea0SLionel Sambuc #else
302ebfedea0SLionel Sambuc     return _open_osfhandle((intptr_t) sock, flags);
303ebfedea0SLionel Sambuc #endif
304ebfedea0SLionel Sambuc }
305ebfedea0SLionel Sambuc 
306ebfedea0SLionel Sambuc #ifdef HAVE_WINSOCK
307ebfedea0SLionel Sambuc ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
rk_SOCK_IOCTL(SOCKET s,long cmd,int * argp)308ebfedea0SLionel Sambuc rk_SOCK_IOCTL(SOCKET s, long cmd, int * argp) {
309ebfedea0SLionel Sambuc     u_long ul = (argp)? *argp : 0;
310ebfedea0SLionel Sambuc     int rv;
311ebfedea0SLionel Sambuc 
312ebfedea0SLionel Sambuc     rv = ioctlsocket(s, cmd, &ul);
313ebfedea0SLionel Sambuc     if (argp)
314ebfedea0SLionel Sambuc 	*argp = (int) ul;
315ebfedea0SLionel Sambuc     return rv;
316ebfedea0SLionel Sambuc }
317ebfedea0SLionel Sambuc #endif
318ebfedea0SLionel Sambuc 
319ebfedea0SLionel Sambuc #ifndef HEIMDAL_SMALLER
320ebfedea0SLionel Sambuc #undef socket
321ebfedea0SLionel Sambuc 
322ebfedea0SLionel Sambuc int rk_socket(int, int, int);
323ebfedea0SLionel Sambuc 
324ebfedea0SLionel Sambuc int
rk_socket(int domain,int type,int protocol)325ebfedea0SLionel Sambuc rk_socket(int domain, int type, int protocol)
326ebfedea0SLionel Sambuc {
327ebfedea0SLionel Sambuc     int s;
328ebfedea0SLionel Sambuc     s = socket (domain, type, protocol);
329ebfedea0SLionel Sambuc #ifdef SOCK_CLOEXEC
330ebfedea0SLionel Sambuc     if ((SOCK_CLOEXEC & type) && s < 0 && errno == EINVAL) {
331ebfedea0SLionel Sambuc 	type &= ~SOCK_CLOEXEC;
332ebfedea0SLionel Sambuc 	s = socket (domain, type, protocol);
333ebfedea0SLionel Sambuc     }
334ebfedea0SLionel Sambuc #endif
335ebfedea0SLionel Sambuc     return s;
336ebfedea0SLionel Sambuc }
337ebfedea0SLionel Sambuc 
338ebfedea0SLionel Sambuc #endif /* HEIMDAL_SMALLER */
339