3 * \author written by Emmanuel Roullit emmanuel.roullit@gmail.com (c) 2012
7 /* __LICENSE_HEADER_BEGIN__ */
10 * Copyright (C) 2012 Emmanuel Roullit <emmanuel.roullit@gmail.com>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or (at
15 * your option) any later version.
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 * You should have received a copy of the GNU General Public License along
23 * with this program; if not, write to the Free Software Foundation, Inc.,
24 * 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
28 /* __LICENSE_HEADER_END__ */
32 #include <sys/types.h>
34 #include <libdabba/macros.h>
35 #include <libdabba/strlcpy.h>
36 #include <dabbad/list.h>
39 * \brief Get the list of usable interfaces by dabbad and give it to the user
40 * \param[in,out] msg Dabba daemon IPC message
41 * \return 0 on success, -1 if the interface list could not be fetched.
43 * This function only retrieves interfaces which belong to the packet family.
46 int dabbad_ifconf_get(struct dabba_ipc_msg
*msg
)
48 size_t a
, off
, ifconf_size
;
49 struct ifaddrs
*ifaddr
, *ifa
;
51 if (getifaddrs(&ifaddr
) != 0)
54 ifconf_size
= ARRAY_SIZE(msg
->msg_body
.msg
.ifconf
);
57 for (off
= 0; ifa
&& off
< msg
->msg_body
.offset
; ifa
= ifa
->ifa_next
) {
58 if (!ifa
->ifa_addr
|| ifa
->ifa_addr
->sa_family
!= AF_PACKET
)
63 for (a
= 0; ifa
&& a
< ifconf_size
; ifa
= ifa
->ifa_next
) {
64 if (!ifa
->ifa_addr
|| ifa
->ifa_addr
->sa_family
!= AF_PACKET
)
67 strlcpy(msg
->msg_body
.msg
.ifconf
[a
].name
, ifa
->ifa_name
,
72 msg
->msg_body
.elem_nr
= a
;