2 * lib/inet6.c This file contains an implementation of the "INET6"
3 * support functions for the net-tools.
4 * (most of it copied from lib/inet.c 1.26).
6 * Version: lib/inet6.c 0.02 1998-07-01
8 * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
9 * Copyright 1993 MicroWalt Corporation
12 *960808 {0.01} Frank Strauss : adapted for IPv6 support
13 *980701 {0.02} Arnaldo C. Melo: GNU gettext instead of catgets
15 * This program is free software; you can redistribute it
16 * and/or modify it under the terms of the GNU General
17 * Public License as published by the Free Software
18 * Foundation; either version 2 of the License, or (at
19 * your option) any later version.
24 #include <asm/types.h>
25 #include <sys/types.h>
26 #include <sys/socket.h>
27 #include <netinet/in.h>
28 #include <arpa/inet.h>
29 #include <arpa/nameser.h>
39 #include "net-support.h"
40 #include "pathnames.h"
43 extern int h_errno; /* some netdb.h versions don't export this */
46 INET6_resolve(char *name, struct sockaddr_in6 *sin6)
48 struct addrinfo req, *ai;
51 req.ai_family = AF_INET6;
52 if ((s = getaddrinfo(name, NULL, &req, &ai))) {
53 fprintf(stderr, "getaddrinfo: %s: %s\n", name, gai_strerror(s));
57 memcpy(sin6, ai->ai_addr, sizeof(struct sockaddr_in6));
66 INET6_rresolve(char *name, struct sockaddr_in6 *sin6, int numeric)
71 if (sin6->sin6_family != AF_INET6) {
73 fprintf(stderr, _("rresolve: unsupport address family %d !\n"),
80 if (numeric & 0x7FFF) {
81 inet_ntop(AF_INET6, &sin6->sin6_addr, name, 80);
85 if ((s = getnameinfo((struct sockaddr *)sin6, sizeof(struct sockaddr_in6),
86 name, 255 /* !! */, NULL, 0, 0))) {
87 fprintf(stderr, "getnameinfo: %s\n", gai_strerror(s));
96 INET6_reserror(char *text)
102 /* Display an Internet socket address. */
104 INET6_print(unsigned char *ptr)
106 static char name[80];
108 inet_ntop(AF_INET6, (struct in6_addr *)ptr, name, 80);
113 /* Display an Internet socket address. */
114 /* dirty! struct sockaddr usually doesn't suffer for inet6 addresses, fst. */
116 INET6_sprint(struct sockaddr *sap, int numeric)
118 static char buff[128];
120 if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
121 return strncpy (buff, _("[NONE SET]"), sizeof (buff));
122 if (INET6_rresolve(buff, (struct sockaddr_in6 *) sap, numeric) != 0)
129 INET6_getsock(char *bufp, struct sockaddr *sap)
131 struct sockaddr_in6 *sin6;
133 sin6 = (struct sockaddr_in6 *) sap;
134 sin6->sin6_family = AF_INET6;
137 if (inet_pton(AF_INET6, bufp, sin6->sin6_addr.s6_addr) <= 0)
144 INET6_input(int type, char *bufp, struct sockaddr *sap)
148 return(INET6_getsock(bufp, sap));
150 return(INET6_resolve(bufp, (struct sockaddr_in6 *) sap));
155 struct aftype inet6_aftype = {
156 "inet6", NULL, /*"IPv6",*/ AF_INET6, sizeof(struct in6_addr),
157 INET6_print, INET6_sprint, INET6_input, INET6_reserror,
158 INET6_rprint, INET6_rinput, NULL,
165 #endif /* HAVE_AFINET6 */