]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/nss-myhostname/legacy.c
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of nss-myhostname.
6 Copyright 2008-2011 Lennart Poettering
7 Copyright 2011 Robert millan
9 nss-myhostname is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Lesser General Public License
11 as published by the Free Software Foundation; either version 2.1 of
12 the License, or (at your option) any later version.
14 nss-myhostname is distributed in the hope that it will be useful,
15 but 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.
19 You should have received a copy of the GNU Lesser General Public
20 License along with nss-myhostname; If not, see
21 <http://www.gnu.org/licenses/>.
24 #include <sys/types.h>
29 #include <netinet/in.h>
33 int ifconf_acquire_addresses(struct address
**_list
, unsigned *_n_list
) {
34 struct address
*list
= NULL
;
36 struct ifaddrs
*ifa
= NULL
;
41 if (getifaddrs(&ifa
) == -1) {
46 for (i
= ifa
; i
!= NULL
; i
= i
->ifa_next
) {
49 struct sockaddr_in6
*in6
= (struct sockaddr_in6
*) i
->ifa_addr
;
50 struct sockaddr_in
*in
= (struct sockaddr_in
*) i
->ifa_addr
;
55 af
= i
->ifa_addr
->sa_family
;
57 if (af
!= AF_INET
&& af
!= AF_INET6
)
60 list
= realloc(list
, (n_list
+1) * sizeof(struct address
));
71 list
[n_list
].family
= af
;
72 list
[n_list
].scope
= 0;
73 memcpy(list
[n_list
].address
, cp
, PROTO_ADDRESS_SIZE(af
));
74 list
[n_list
].ifindex
= ifindex
++;
85 qsort(list
, n_list
, sizeof(struct address
), address_compare
);