OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [uclinux/] [userland/] [route/] [lib/] [inet6.c] - Blame information for rev 1767

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 745 simons
/*
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).
5
 *
6
 * Version:     $Id: inet6.c,v 1.1 2002-03-17 19:58:53 simons Exp $
7
 *
8
 * Author:      Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
9
 *              Copyright 1993 MicroWalt Corporation
10
 *
11
 * Modified:
12
 *960808 {0.01} Frank Strauss :         adapted for IPv6 support
13
 *980701 {0.02} Arnaldo C. Melo:        GNU gettext instead of catgets
14
 *
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.
20
 */
21
#include "config.h"
22
 
23
#if HAVE_AFINET6
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>
30
#include <ctype.h>
31
#include <errno.h>
32
#include <netdb.h>
33
#include <resolv.h>
34
#include <stdlib.h>
35
#include <string.h>
36
#include <stdio.h>
37
#include <unistd.h>
38
#include "version.h"
39
#include "net-support.h"
40
#include "pathnames.h"
41
#include "intl.h"
42
#include "util.h"
43
 
44
extern int h_errno;             /* some netdb.h versions don't export this */
45
 
46
static int INET6_resolve(char *name, struct sockaddr_in6 *sin6)
47
{
48
    struct addrinfo req, *ai;
49
    int s;
50
 
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));
54
        return -1;
55
    }
56
    memcpy(sin6, ai->ai_addr, sizeof(struct sockaddr_in6));
57
 
58
    freeaddrinfo(ai);
59
 
60
    return (0);
61
}
62
 
63
 
64
static int INET6_rresolve(char *name, struct sockaddr_in6 *sin6, int numeric)
65
{
66
    int s;
67
 
68
    /* Grmpf. -FvK */
69
    if (sin6->sin6_family != AF_INET6) {
70
#ifdef DEBUG
71
        fprintf(stderr, _("rresolve: unsupport address family %d !\n"),
72
                sin6->sin6_family);
73
#endif
74
        errno = EAFNOSUPPORT;
75
        return (-1);
76
    }
77
    if (numeric & 0x7FFF) {
78
        inet_ntop(AF_INET6, &sin6->sin6_addr, name, 80);
79
        return (0);
80
    }
81
    if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
82
        if (numeric & 0x8000)
83
            strcpy(name, "default");
84
        else
85
            strcpy(name, "*");
86
        return (0);
87
    }
88
 
89
    if ((s = getnameinfo((struct sockaddr *) sin6, sizeof(struct sockaddr_in6),
90
                         name, 255 /* !! */ , NULL, 0, 0))) {
91
        fprintf(stderr, "getnameinfo: %s\n", gai_strerror(s));
92
        return -1;
93
    }
94
    return (0);
95
}
96
 
97
 
98
static void INET6_reserror(char *text)
99
{
100
    herror(text);
101
}
102
 
103
 
104
/* Display an Internet socket address. */
105
static char *INET6_print(unsigned char *ptr)
106
{
107
    static char name[80];
108
 
109
    inet_ntop(AF_INET6, (struct in6_addr *) ptr, name, 80);
110
    return name;
111
}
112
 
113
 
114
/* Display an Internet socket address. */
115
/* dirty! struct sockaddr usually doesn't suffer for inet6 addresses, fst. */
116
static char *INET6_sprint(struct sockaddr *sap, int numeric)
117
{
118
    static char buff[128];
119
 
120
    if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
121
        return safe_strncpy(buff, _("[NONE SET]"), sizeof(buff));
122
    if (INET6_rresolve(buff, (struct sockaddr_in6 *) sap, numeric) != 0)
123
        return (NULL);
124
    return (buff);
125
}
126
 
127
 
128
static int INET6_getsock(char *bufp, struct sockaddr *sap)
129
{
130
    struct sockaddr_in6 *sin6;
131
 
132
    sin6 = (struct sockaddr_in6 *) sap;
133
    sin6->sin6_family = AF_INET6;
134
    sin6->sin6_port = 0;
135
 
136
    if (inet_pton(AF_INET6, bufp, sin6->sin6_addr.s6_addr) <= 0)
137
        return (-1);
138
 
139
    return 16;                  /* ?;) */
140
}
141
 
142
static int INET6_input(int type, char *bufp, struct sockaddr *sap)
143
{
144
    switch (type) {
145
    case 1:
146
        return (INET6_getsock(bufp, sap));
147
    default:
148
        return (INET6_resolve(bufp, (struct sockaddr_in6 *) sap));
149
    }
150
}
151
 
152
 
153
struct aftype inet6_aftype =
154
{
155
    "inet6", NULL, /*"IPv6", */ AF_INET6, sizeof(struct in6_addr),
156
    INET6_print, INET6_sprint, INET6_input, INET6_reserror,
157
    INET6_rprint, INET6_rinput, NULL,
158
 
159
    -1,
160
    "/proc/net/if_inet6"
161
};
162
 
163
 
164
#endif                          /* HAVE_AFINET6 */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.