open62541 1.4.19
Open source implementation of OPC UA
Loading...
Searching...
No Matches
inet.h
Go to the documentation of this file.
1/** IPv4/IPv6 address helpers, cf. the inet.[ch] wrapper in SMCRoute */
2#ifndef MDNSD_INET_H_
3#define MDNSD_INET_H_
4
5#include <netinet/in.h>
6#include <sys/socket.h>
7
8#define INET_ADDRSTR_LEN INET6_ADDRSTRLEN /* fits AF_INET and AF_INET6 */
9
10/*
11 * Wrapper for an IPv4 or IPv6 socket address. Everything is kept in a
12 * sockaddr_storage and the family is inspected through the helpers below,
13 * so the rest of mdnsd does not need to special-case AF_INET vs AF_INET6.
14 */
15typedef struct sockaddr_storage inet_addr_t;
16
17/** Family of @ss, AF_INET or AF_INET6 */
18sa_family_t inet_family(const inet_addr_t *ss);
19
20/** Length of the concrete sockaddr in @ss, for bind()/connect()/sendto() */
21socklen_t inet_len(const inet_addr_t *ss);
22
23/** Port in host byte order, regardless of family */
24in_port_t inet_port(const inet_addr_t *ss);
25
26/** Set the port (host byte order) in the correct family-specific field */
27void inet_set_port(inet_addr_t *ss, in_port_t port);
28
29/** Initialize @ss to the wildcard address of @family with @port */
30void inet_anyaddr(sa_family_t family, in_port_t port, inet_addr_t *ss);
31
32/** Presentation string of the address in @ss, e.g. for logging */
33const char *inet_ntop2(const inet_addr_t *ss, char *buf, size_t len);
34
35#endif /* MDNSD_INET_H_ */
in_port_t inet_port(const inet_addr_t *ss)
Port in host byte order, regardless of family.
socklen_t inet_len(const inet_addr_t *ss)
Length of the concrete sockaddr in @ss, for bind()/connect()/sendto()
struct sockaddr_storage inet_addr_t
Definition inet.h:15
void inet_set_port(inet_addr_t *ss, in_port_t port)
Set the port (host byte order) in the correct family-specific field.
sa_family_t inet_family(const inet_addr_t *ss)
Family of @ss, AF_INET or AF_INET6.
void inet_anyaddr(sa_family_t family, in_port_t port, inet_addr_t *ss)
Initialize @ss to the wildcard address of @family with @port.
const char * inet_ntop2(const inet_addr_t *ss, char *buf, size_t len)
Presentation string of the address in @ss, e.g.