Deleted Added
sdiff udiff text old ( 78527 ) new ( 90926 )
full compact
1/*
2 * Copyright (c) 2000 - 2001 Kungliga Tekniska H�gskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 19 unchanged lines hidden (view full) ---

28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34#ifdef HAVE_CONFIG_H
35#include <config.h>
36RCSID("$Id: getifaddrs.c,v 1.5 2001/04/17 08:27:47 joda Exp $");
37#endif
38#include "roken.h"
39
40#ifdef __osf__
41/* hate */
42struct rtentry;
43struct mbuf;
44#endif

--- 16 unchanged lines hidden (view full) ---

61 int af, int siocgifconf, int siocgifflags,
62 size_t ifreq_sz)
63{
64 int ret;
65 int fd;
66 size_t buf_size;
67 char *buf;
68 struct ifconf ifconf;
69 int num, j = 0;
70 char *p;
71 size_t sz;
72 struct sockaddr sa_zero;
73 struct ifreq *ifr;
74
75 struct ifaddrs *start, **end = &start;
76
77 buf = NULL;
78
79 memset (&sa_zero, 0, sizeof(sa_zero));
80 fd = socket(af, SOCK_DGRAM, 0);
81 if (fd < 0)
82 return -1;
83
84 buf_size = 8192;

--- 19 unchanged lines hidden (view full) ---

104 */
105
106 if (ifconf.ifc_len < buf_size)
107 break;
108 free (buf);
109 buf_size *= 2;
110 }
111
112 num = ifconf.ifc_len / ifreq_sz;
113 j = 0;
114 for (p = ifconf.ifc_buf;
115 p < ifconf.ifc_buf + ifconf.ifc_len;
116 p += sz) {
117 struct ifreq ifreq;
118 struct sockaddr *sa;
119 size_t salen;
120
121 ifr = (struct ifreq *)p;

--- 13 unchanged lines hidden (view full) ---

135 memcpy (ifreq.ifr_name, ifr->ifr_name, sizeof(ifr->ifr_name));
136
137 if (ioctl(fd, siocgifflags, &ifreq) < 0) {
138 ret = errno;
139 goto error_out;
140 }
141
142 *end = malloc(sizeof(**end));
143
144 (*end)->ifa_next = NULL;
145 (*end)->ifa_name = strdup(ifr->ifr_name);
146 (*end)->ifa_flags = ifreq.ifr_flags;
147 (*end)->ifa_addr = malloc(salen);
148 memcpy((*end)->ifa_addr, sa, salen);
149 (*end)->ifa_netmask = NULL;
150

--- 18 unchanged lines hidden (view full) ---

169 end = &(*end)->ifa_next;
170
171 }
172 *ifap = start;
173 close(fd);
174 free(buf);
175 return 0;
176 error_out:
177 close(fd);
178 free(buf);
179 errno = ret;
180 return -1;
181}
182
183int
184getifaddrs(struct ifaddrs **ifap)
185{
186 int ret = -1;
187 errno = ENXIO;
188#if defined(AF_INET6) && defined(SIOCGIF6CONF) && defined(SIOCGIF6FLAGS)
189 if (ret)
190 ret = getifaddrs2 (ifap, AF_INET6, SIOCGIF6CONF, SIOCGIF6FLAGS,
191 sizeof(struct in6_ifreq));
192#endif
193#if defined(HAVE_IPV6) && defined(SIOCGIFCONF)
194 if (ret)
195 ret = getifaddrs2 (ifap, AF_INET6, SIOCGIFCONF, SIOCGIFFLAGS,
196 sizeof(struct ifreq));
197#endif
198#if defined(AF_INET) && defined(SIOCGIFCONF) && defined(SIOCGIFFLAGS)
199 if (ret)
200 ret = getifaddrs2 (ifap, AF_INET, SIOCGIFCONF, SIOCGIFFLAGS,

--- 73 unchanged lines hidden ---