Remove *xattr syscalls.
[glibc.git] / sysdeps / generic / ifreq.h
blobc96d1c8789b89aa41240054841f6de081111c940
1 /* Copyright (C) 1999,2002 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Andreas Jaeger <aj@suse.de>.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <unistd.h>
23 #include <net/if.h>
24 #include <sys/socket.h>
25 #include <sys/ioctl.h>
28 static inline void
29 __ifreq (struct ifreq **ifreqs, int *num_ifs, int sockfd)
31 int fd = sockfd;
32 struct ifconf ifc;
33 int rq_len;
34 int nifs;
35 # define RQ_IFS 4
37 if (fd < 0)
38 fd = __opensock ();
39 if (fd < 0)
41 *num_ifs = 0;
42 *ifreqs = NULL;
43 return;
46 ifc.ifc_buf = NULL;
47 rq_len = RQ_IFS * sizeof (struct ifreq);
50 ifc.ifc_len = rq_len;
51 ifc.ifc_buf = realloc (ifc.ifc_buf, ifc.ifc_len);
52 if (ifc.ifc_buf == NULL || __ioctl (fd, SIOCGIFCONF, &ifc) < 0)
54 if (ifc.ifc_buf)
55 free (ifc.ifc_buf);
57 if (fd != sockfd)
58 __close (fd);
59 *num_ifs = 0;
60 *ifreqs = NULL;
61 return;
63 rq_len *= 2;
65 while (rq_len < sizeof (struct ifreq) + ifc.ifc_len);
67 nifs = ifc.ifc_len / sizeof (struct ifreq);
69 if (fd != sockfd)
70 __close (fd);
72 *num_ifs = nifs;
73 *ifreqs = realloc (ifc.ifc_buf, nifs * sizeof (struct ifreq));
77 static inline void
78 __if_freereq (struct ifreq *ifreqs, int num_ifs)
80 free (ifreqs);