2 * usock - socket helper functions
4 * Copyright (C) 2010 Steven Barth <steven@midlink.org>
5 * Copyright (C) 2011-2012 Felix Fietkau <nbd@openwrt.org>
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
25 #define USOCK_SERVER 0x0100
26 #define USOCK_NOCLOEXEC 0x0200
27 #define USOCK_NONBLOCK 0x0400
28 #define USOCK_NUMERIC 0x0800
29 #define USOCK_IPV6ONLY 0x2000
30 #define USOCK_IPV4ONLY 0x4000
31 #define USOCK_UNIX 0x8000
33 const char *usock_port(int port
);
34 int usock(int type
, const char *host
, const char *service
);
35 int usock_inet_timeout(int type
, const char *host
, const char *service
,
36 void *addr
, int timeout
);
38 usock_inet(int type
, const char *host
, const char *service
, void *addr
)
40 return usock_inet_timeout(type
, host
, service
, addr
, -1);
44 * Wait for a socket to become ready.
46 * This may be useful for users of USOCK_NONBLOCK to wait (with a timeout)
49 * @param fd file descriptor of socket
50 * @param msecs timeout in microseconds
52 int usock_wait_ready(int fd
, int msecs
);