aboutsummaryrefslogtreecommitdiff
path: root/libbb/inet_common.c
diff options
context:
space:
mode:
authorandersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277>2002-07-03 11:46:38 +0000
committerandersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277>2002-07-03 11:46:38 +0000
commit900987843e32563488974222031be9c97c060610 (patch)
tree905d4f1b1e557950272ac98e1540fa06f732f42f /libbb/inet_common.c
parent26e899536049e29919abd9101799745ceaffff25 (diff)
downloadbusybox-w32-900987843e32563488974222031be9c97c060610.tar.gz
busybox-w32-900987843e32563488974222031be9c97c060610.tar.bz2
busybox-w32-900987843e32563488974222031be9c97c060610.zip
This patch from Bart Visscher <magick@linux-fan.com> adds
IPV6 support to busybox. This patch does the following: * Add IPv6 support to libbb * Enable IPv6 interface address display * Add IPv6 config option * Adds ping6, an adaptation of the ping applet for IPv6 * Adds support routines for ping6: - xgethostbyname2 - create_icmp6_socket * Adds ifconfig support for IPv6 * Add support IPv6 to netstat * Add IPv6 support to route Thanks Bart! git-svn-id: svn://busybox.net/trunk/busybox@5003 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'libbb/inet_common.c')
-rw-r--r--libbb/inet_common.c64
1 files changed, 63 insertions, 1 deletions
diff --git a/libbb/inet_common.c b/libbb/inet_common.c
index c1e5953fe..c7bf409c4 100644
--- a/libbb/inet_common.c
+++ b/libbb/inet_common.c
@@ -4,7 +4,7 @@
4 * 4 *
5 * Heavily modified by Manuel Novoa III Mar 12, 2001 5 * Heavily modified by Manuel Novoa III Mar 12, 2001
6 * 6 *
7 * Version: $Id: inet_common.c,v 1.2 2002/06/06 12:11:55 andersen Exp $ 7 * Version: $Id: inet_common.c,v 1.3 2002/07/03 11:46:36 andersen Exp $
8 * 8 *
9 */ 9 */
10 10
@@ -177,3 +177,65 @@ int INET_rresolve(char *name, size_t len, struct sockaddr_in *s_in,
177 177
178 return (0); 178 return (0);
179} 179}
180
181#if CONFIG_FEATURE_IPV6
182
183int INET6_resolve(char *name, struct sockaddr_in6 *sin6)
184{
185 struct addrinfo req, *ai;
186 int s;
187
188 memset (&req, '\0', sizeof req);
189 req.ai_family = AF_INET6;
190 if ((s = getaddrinfo(name, NULL, &req, &ai))) {
191 fprintf(stderr, "getaddrinfo: %s: %d\n", name, s);
192 return -1;
193 }
194 memcpy(sin6, ai->ai_addr, sizeof(struct sockaddr_in6));
195
196 freeaddrinfo(ai);
197
198 return (0);
199}
200
201#ifndef IN6_IS_ADDR_UNSPECIFIED
202#define IN6_IS_ADDR_UNSPECIFIED(a) \
203 (((__u32 *) (a))[0] == 0 && ((__u32 *) (a))[1] == 0 && \
204 ((__u32 *) (a))[2] == 0 && ((__u32 *) (a))[3] == 0)
205#endif
206
207
208int INET6_rresolve(char *name, size_t len, struct sockaddr_in6 *sin6, int numeric)
209{
210 int s;
211
212 /* Grmpf. -FvK */
213 if (sin6->sin6_family != AF_INET6) {
214#ifdef DEBUG
215 fprintf(stderr, _("rresolve: unsupport address family %d !\n"),
216 sin6->sin6_family);
217#endif
218 errno = EAFNOSUPPORT;
219 return (-1);
220 }
221 if (numeric & 0x7FFF) {
222 inet_ntop(AF_INET6, &sin6->sin6_addr, name, len);
223 return (0);
224 }
225 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
226 if (numeric & 0x8000)
227 strcpy(name, "default");
228 else
229 strcpy(name, "*");
230 return (0);
231 }
232
233 if ((s = getnameinfo((struct sockaddr *) sin6, sizeof(struct sockaddr_in6),
234 name, len , NULL, 0, 0))) {
235 fputs("getnameinfo failed\n", stderr);
236 return -1;
237 }
238 return (0);
239}
240
241#endif /* CONFIG_FEATURE_IPV6 */