chiark / gitweb /
nss-myhostname: remove duplicate LICENCE
[elogind.git] / src / nss-myhostname / ifconf.h
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3 #ifndef fooifconfhfoo
4 #define fooifconfhfoo
5
6 #include <sys/socket.h>
7
8 /***
9   This file is part of systemd.
10
11   Copyright 2008-2011 Lennart Poettering
12
13   systemd is free software; you can redistribute it and/or modify it
14   under the terms of the GNU Lesser General Public License as published by
15   the Free Software Foundation; either version 2.1 of the License, or
16   (at your option) any later version.
17
18   systemd is distributed in the hope that it will be useful, but
19   WITHOUT ANY WARRANTY; without even the implied warranty of
20   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21   Lesser General Public License for more details.
22
23   You should have received a copy of the GNU Lesser General Public License
24   along with systemd; If not, see <http://www.gnu.org/licenses/>.
25 ***/
26
27 #include <inttypes.h>
28 #include <sys/types.h>
29 #include <assert.h>
30
31 struct address {
32         unsigned char family;
33         uint8_t address[16];
34         unsigned char scope;
35         int ifindex;
36 };
37
38 #define _public_ __attribute__ ((visibility("default")))
39 #define _hidden_ __attribute__ ((visibility("hidden")))
40
41 int ifconf_acquire_addresses(struct address **_list, unsigned *_n_list) _hidden_;
42
43 static inline size_t PROTO_ADDRESS_SIZE(int proto) {
44         assert(proto == AF_INET || proto == AF_INET6);
45
46         return proto == AF_INET6 ? 16 : 4;
47 }
48
49 static inline int address_compare(const void *_a, const void *_b) {
50         const struct address *a = _a, *b = _b;
51
52         /* Order lowest scope first, IPv4 before IPv6, lowest interface index first */
53
54         if (a->scope < b->scope)
55                 return -1;
56         if (a->scope > b->scope)
57                 return 1;
58
59         if (a->family == AF_INET && b->family == AF_INET6)
60                 return -1;
61         if (a->family == AF_INET6 && b->family == AF_INET)
62                 return 1;
63
64         if (a->ifindex < b->ifindex)
65                 return -1;
66         if (a->ifindex > b->ifindex)
67                 return 1;
68
69         return 0;
70 }
71
72
73 #endif