OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [libnetworking/] [libc/] [nsap_addr.c] - Blame information for rev 173

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 30 unneback
/*
2
 * Copyright (c) 1996, 1998 by Internet Software Consortium.
3
 *
4
 * Permission to use, copy, modify, and distribute this software for any
5
 * purpose with or without fee is hereby granted, provided that the above
6
 * copyright notice and this permission notice appear in all copies.
7
 *
8
 * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
9
 * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
10
 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
11
 * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
12
 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
13
 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
14
 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
15
 * SOFTWARE.
16
 */
17
 
18
#if defined(LIBC_SCCS) && !defined(lint)
19
static char rcsid[] = "$Id: nsap_addr.c,v 1.2 2001-09-27 12:01:53 chris Exp $";
20
#endif /* LIBC_SCCS and not lint */
21
 
22
#include <sys/types.h>
23
#include <sys/param.h>
24
#include <sys/socket.h>
25
#include <netinet/in.h>
26
#include <arpa/inet.h>
27
#include <arpa/nameser.h>
28
#include <ctype.h>
29
#include <resolv.h>
30
 
31
static char
32
xtob(c)
33
        register int c;
34
{
35
        return (c - (((c >= '0') && (c <= '9')) ? '0' : '7'));
36
}
37
 
38
u_int
39
inet_nsap_addr(ascii, binary, maxlen)
40
        const char *ascii;
41
        u_char *binary;
42
        int maxlen;
43
{
44
        u_char c, nib;
45
        u_int len = 0;
46
 
47
        while ((c = *ascii++) != '\0' && len < (u_int)maxlen) {
48
                if (c == '.' || c == '+' || c == '/')
49
                        continue;
50
                if (!isascii(c))
51
                        return (0);
52
                if (islower(c))
53
                        c = toupper(c);
54
                if (isxdigit(c)) {
55
                        nib = xtob(c);
56
                        c = *ascii++;
57
                        if (c != '\0') {
58
                                c = toupper(c);
59
                                if (isxdigit(c)) {
60
                                        *binary++ = (nib << 4) | xtob(c);
61
                                        len++;
62
                                } else
63
                                        return (0);
64
                        }
65
                        else
66
                                return (0);
67
                }
68
                else
69
                        return (0);
70
        }
71
        return (len);
72
}
73
 
74
char *
75
inet_nsap_ntoa(binlen, binary, ascii)
76
        int binlen;
77
        register const u_char *binary;
78
        register char *ascii;
79
{
80
        register int nib;
81
        int i;
82
        static char tmpbuf[255*3];
83
        char *start;
84
 
85
        if (ascii)
86
                start = ascii;
87
        else {
88
                ascii = tmpbuf;
89
                start = tmpbuf;
90
        }
91
 
92
        if (binlen > 255)
93
                binlen = 255;
94
 
95
        for (i = 0; i < binlen; i++) {
96
                nib = *binary >> 4;
97
                *ascii++ = nib + (nib < 10 ? '0' : '7');
98
                nib = *binary++ & 0x0f;
99
                *ascii++ = nib + (nib < 10 ? '0' : '7');
100
                if (((i % 2) == 0 && (i + 1) < binlen))
101
                        *ascii++ = '.';
102
        }
103
        *ascii = '\0';
104
        return (start);
105
}

powered by: WebSVN 2.1.0

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