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