blob: 04d87f320be5517cf8850b31671b27fc8d827c12 [file] [log] [blame]
James Kuszmaul82f6c042021-01-17 11:30:16 -08001/**
2 * @file re_net.h Interface to Networking module.
3 *
4 * Copyright (C) 2010 Creytiv.com
5 */
6#if defined(WIN32)
7#include <winsock2.h>
8#include <ws2tcpip.h>
9#else
10#include <sys/types.h>
11#ifndef _BSD_SOCKLEN_T_
12#define _BSD_SOCKLEN_T_ int /**< Defines the BSD socket length type */
13#endif
14#include <sys/socket.h>
15#include <netinet/in.h>
16#include <arpa/inet.h>
17#endif
18
19
20/** Length of IPv4 address string */
21#ifndef INET_ADDRSTRLEN
22#define INET_ADDRSTRLEN 16
23#endif
24
25/** Length of IPv6 address string */
26#ifndef INET6_ADDRSTRLEN
27#define INET6_ADDRSTRLEN 46
28#endif
29
30/** Length of IPv4/v6 address string */
31#ifdef HAVE_INET6
32#define NET_ADDRSTRLEN INET6_ADDRSTRLEN
33#else
34#define NET_ADDRSTRLEN INET_ADDRSTRLEN
35#endif
36
37/* forward declarations */
38struct sa;
39
40
41/* Net generic */
42int net_hostaddr(int af, struct sa *ip);
43int net_default_source_addr_get(int af, struct sa *ip);
44int net_default_gateway_get(int af, struct sa *gw);
45
46
47/* Net sockets */
48int net_sock_init(void);
49void net_sock_close(void);
50
51
52/* Net socket options */
53int net_sockopt_blocking_set(int fd, bool blocking);
54int net_sockopt_reuse_set(int fd, bool reuse);
55
56
57/* Net interface (if.c) */
58
59/**
60 * Defines the interface address handler - called once per interface
61 *
62 * @param ifname Name of the interface
63 * @param sa IP address of the interface
64 * @param arg Handler argument
65 *
66 * @return true to stop traversing, false to continue
67 */
68typedef bool (net_ifaddr_h)(const char *ifname, const struct sa *sa,
69 void *arg);
70
71int net_if_getname(char *ifname, size_t sz, int af, const struct sa *ip);
72int net_if_getaddr(const char *ifname, int af, struct sa *ip);
73int net_if_getaddr4(const char *ifname, int af, struct sa *ip);
74int net_if_list(net_ifaddr_h *ifh, void *arg);
75int net_if_apply(net_ifaddr_h *ifh, void *arg);
76int net_if_debug(struct re_printf *pf, void *unused);
77int net_if_getlinklocal(const char *ifname, int af, struct sa *ip);
78
79
80/* Net interface (ifaddrs.c) */
81int net_getifaddrs(net_ifaddr_h *ifh, void *arg);
82
83
84/* Net route */
85
86/**
87 * Defines the routing table handler - called once per route entry
88 *
89 * @param ifname Interface name
90 * @param dst Destination IP address/network
91 * @param dstlen Prefix length of destination
92 * @param gw Gateway IP address
93 * @param arg Handler argument
94 *
95 * @return true to stop traversing, false to continue
96 */
97typedef bool (net_rt_h)(const char *ifname, const struct sa *dst,
98 int dstlen, const struct sa *gw, void *arg);
99
100int net_rt_list(net_rt_h *rth, void *arg);
101int net_rt_default_get(int af, char *ifname, size_t size);
102int net_rt_debug(struct re_printf *pf, void *unused);
103
104
105/* Net strings */
106const char *net_proto2name(int proto);
107const char *net_af2name(int af);