Version 1.8.0.0
[socat.git] / sysutils.h
blob5e8ae109ca9e69cfa8604be555aa4c042247c0ff
1 /* source: sysutils.h */
2 /* Copyright Gerhard Rieger and contributors (see file CHANGES) */
3 /* Published under the GNU General Public License V.2, see file COPYING */
5 #ifndef __sysutils_h_included
6 #define __sysutils_h_included 1
8 #if WITH_IP6
9 /* not all OSes provide in6_addr that allows splitting to 16 or 32 bit junks of
10 the host address part of sockaddr_in6; here we help ourselves */
11 union xioin6_u {
12 uint8_t u6_addr8[16];
13 uint16_t u6_addr16[8];
14 uint32_t u6_addr32[4];
15 } ;
16 #endif /* WITH_IP6 */
18 #if _WITH_SOCKET
19 union sockaddr_union {
20 struct sockaddr soa;
21 #if WITH_UNIX
22 struct sockaddr_un un;
23 #endif /* WITH_UNIX */
24 #if _WITH_IP4
25 struct sockaddr_in ip4;
26 #endif /* _WITH_IP4 */
27 #if WITH_IP6
28 struct sockaddr_in6 ip6;
29 #endif /* WITH_IP6 */
30 #if WITH_VSOCK
31 struct sockaddr_vm vm;
32 #endif /* WITH_IP6 */
33 #if _WITH_INTERFACE
34 struct sockaddr_ll ll;
35 #endif
36 } ;
37 #endif /* _WITH_SOCKET */
39 #if _WITH_SOCKET
40 struct xiorange {
41 union sockaddr_union netaddr;
42 union sockaddr_union netmask;
43 } ;
44 #endif /* _WITH_SOCKET */
46 #if _WITH_INTERFACE
47 extern const int one;
48 #endif
50 extern ssize_t writefull(int fd, const void *buff, size_t bytes);
52 #if _WITH_SOCKET
53 extern socklen_t socket_init(int af, union sockaddr_union *sa);
54 #endif
55 #if WITH_UNIX
56 extern void socket_un_init(struct sockaddr_un *sa);
57 #endif /* WITH_UNIX */
58 #if _WITH_IP4
59 extern void socket_in_init(struct sockaddr_in *sa);
60 #endif /* _WITH_IP4 */
61 #if _WITH_IP6
62 extern void socket_in6_init(struct sockaddr_in6 *sa);
63 #endif /* _WITH_IP4 */
65 #if _WITH_SOCKET
66 extern char *sockaddr_info(const struct sockaddr *sa, socklen_t salen, char *buff, size_t blen);
67 #endif
68 #if WITH_UNIX
69 extern char *sockaddr_unix_info(const struct sockaddr_un *sa, socklen_t salen, char *buff, size_t blen);
70 #endif /* WITH_UNIX */
71 #if WITH_IP4
72 extern char *inet4addr_info(uint32_t addr, char *buff, size_t blen);
73 extern char *sockaddr_inet4_info(const struct sockaddr_in *sa, char *buff, size_t blen);
74 #endif /* WITH_IP4 */
75 #if WITH_IP6
76 extern char *sockaddr_inet6_info(const struct sockaddr_in6 *sa, char *buff, size_t blen);
77 #endif /* WITH_IP6 */
78 #if WITH_VSOCK
79 extern char *sockaddr_vm_info(const struct sockaddr_vm *sa, char *buff, size_t blen);
80 extern int sockaddr_vm_parse(struct sockaddr_vm *sa, const char *cid_str,
81 const char *port_str);
82 #endif /* WITH_VSOCK */
83 #if !HAVE_INET_NTOP
84 extern const char *inet_ntop(int pf, const void *binaddr,
85 char *addrtext, socklen_t textlen);
86 #endif
87 extern int check_ip4addr(const char *address);
88 extern int check_ip6addr(const char *address);
89 extern int check_ipaddr(const char *address);
91 #if defined(HAVE_SETGRENT) && defined(HAVE_GETGRENT) && defined(HAVE_ENDGRENT)
92 extern int getusergroups(const char *user, gid_t *list, int *ngroups);
93 #endif
95 #if !HAVE_HSTRERROR
96 extern const char *hstrerror(int err);
97 #endif
99 extern int xiopoll(struct pollfd fds[], unsigned long nfds, struct timeval *timeout);
101 extern int parseport(const char *portname, int proto);
103 extern int ifindexbyname(const char *ifname, int anysock);
104 extern int ifindex(const char *ifname, unsigned int *ifindex, int anysock);
106 extern int xiosetenv(const char *varname, const char *value, int overwrite, const char *sep);
107 extern int
108 xiosetenv2(const char *varname, const char *varname2, const char *value,
109 int overwrite, const char *sep);
110 extern int
111 xiosetenv3(const char *varname, const char *varname2, const char *varname3,
112 const char *value, int overwrite, const char *sep);
113 extern int xiosetenvulong(const char *varname, unsigned long value,
114 int overwrite);
115 extern int xiosetenvushort(const char *varname, unsigned short value,
116 int overwrite);
117 extern unsigned long int Strtoul(const char *nptr, char **endptr, int base, const char *txt);
118 extern long long int Strtoll(const char *nptr, char **endptr, int base, const char *txt);
119 extern double Strtod(const char *nptr, char **endptr, const char *txt);
120 extern int xio_opensnifffile(const char *a, struct timeval *tv);
122 #endif /* !defined(__sysutils_h_included) */