1
/* Copyright (C) 1999, 2002 Free Software Foundation, Inc.
2
This file is part of the GNU C Library.
4
The GNU C Library is free software; you can redistribute it and/or
5
modify it under the terms of the GNU Lesser General Public
6
License as published by the Free Software Foundation; either
7
version 2.1 of the License, or (at your option) any later version.
9
The GNU C Library is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
Lesser General Public License for more details.
14
You should have received a copy of the GNU Lesser General Public
15
License along with the GNU C Library; if not, write to the Free
16
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
23
#include <sys/socket.h>
24
#include <sys/ioctl.h>
28
/* The FreeBSD ioctl SIOCGIFCONF returns the list if interfaces as a
29
concatenation of records of different size, each having at least
30
sizeof (struct ifreq) bytes. */
34
__ifreq (struct ifreq **ifreqs, int *num_ifs, int sockfd)
43
/* FreeBSD has many interfaces, many of them are usually down. */
45
/* We have to assume all records are of limited size, so that we know
46
when we can stop enlarging the buffer. */
47
# define RQ_MAXSIZE 256
59
rq_len = RQ_IFS * sizeof (struct ifreq) + RQ_MAXSIZE;
63
ifc.ifc_buf = realloc (ifc.ifc_buf, ifc.ifc_len);
64
if (ifc.ifc_buf == NULL || __ioctl (fd, SIOCGIFCONF, &ifc) < 0)
75
if (ifc.ifc_len + RQ_MAXSIZE <= rq_len)
81
ifstart = (char *) ifc.ifc_buf;
82
ifend = ifstart + ifc.ifc_len;
83
for (ifr = (struct ifreq *) ifstart;
85
ifr = __if_nextreq (ifr))
92
*ifreqs = realloc (ifc.ifc_buf, ifc.ifc_len);