]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/basic/in-addr-util.h
in-addr-util: prefix return parameters with ret_
[thirdparty/systemd.git] / src / basic / in-addr-util.h
CommitLineData
3b653205
LP
1#pragma once
2
3/***
4 This file is part of systemd.
5
6 Copyright 2014 Lennart Poettering
7
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
12
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20***/
21
22#include <netinet/in.h>
11c3a366
TA
23#include <stddef.h>
24#include <sys/socket.h>
3b653205
LP
25
26#include "macro.h"
27#include "util.h"
28
29union in_addr_union {
30 struct in_addr in;
31 struct in6_addr in6;
32};
33
97e5d693
LP
34struct in_addr_data {
35 int family;
36 union in_addr_union address;
37};
38
34380032 39bool in4_addr_is_null(const struct in_addr *a);
af93291c 40int in_addr_is_null(int family, const union in_addr_union *u);
fdedbe26 41
85257f48
SS
42int in_addr_is_multicast(int family, const union in_addr_union *u);
43
fdedbe26 44bool in4_addr_is_link_local(const struct in_addr *a);
af93291c 45int in_addr_is_link_local(int family, const union in_addr_union *u);
fdedbe26
LP
46
47bool in4_addr_is_localhost(const struct in_addr *a);
d830ebbd 48int in_addr_is_localhost(int family, const union in_addr_union *u);
fdedbe26 49
623a4c97 50int in_addr_equal(int family, const union in_addr_union *a, const union in_addr_union *b);
0dd25fb9
LP
51int in_addr_prefix_intersect(int family, const union in_addr_union *a, unsigned aprefixlen, const union in_addr_union *b, unsigned bprefixlen);
52int in_addr_prefix_next(int family, union in_addr_union *u, unsigned prefixlen);
53int in_addr_to_string(int family, const union in_addr_union *u, char **ret);
2817157b 54int in_addr_ifindex_to_string(int family, const union in_addr_union *u, int ifindex, char **ret);
0dd25fb9 55int in_addr_from_string(int family, const char *s, union in_addr_union *ret);
4e2d5273 56int in_addr_from_string_auto(const char *s, int *ret_family, union in_addr_union *ret);
2817157b 57int in_addr_ifindex_from_string_auto(const char *s, int *family, union in_addr_union *ret, int *ifindex);
5a941f5f
LP
58unsigned char in4_addr_netmask_to_prefixlen(const struct in_addr *addr);
59struct in_addr* in4_addr_prefixlen_to_netmask(struct in_addr *addr, unsigned char prefixlen);
60int in4_addr_default_prefixlen(const struct in_addr *addr, unsigned char *prefixlen);
61int in4_addr_default_subnet_mask(const struct in_addr *addr, struct in_addr *mask);
5a8bcb67 62int in_addr_mask(int family, union in_addr_union *addr, unsigned char prefixlen);
f7bf1abe 63int in_addr_prefix_from_string(const char *p, int family, union in_addr_union *ret_prefix, uint8_t *ret_prefixlen);
3b653205 64
9d485985
LP
65static inline size_t FAMILY_ADDRESS_SIZE(int family) {
66 assert(family == AF_INET || family == AF_INET6);
67 return family == AF_INET6 ? 16 : 4;
3b653205 68}
5a8bcb67
LP
69
70#define IN_ADDR_NULL ((union in_addr_union) {})