diff options
author | dm <> | 1996-02-19 19:53:30 +0000 |
---|---|---|
committer | dm <> | 1996-02-19 19:53:30 +0000 |
commit | 543eeae2382e5de0b9518bdd9f7a75e5686fd056 (patch) | |
tree | 094165ba891a348ad41b10f58ccb57f1a01f8e74 /src/lib/libc/net/nsap_addr.c | |
parent | 4a12c1341f3a7e10bd98cebfe52fc96867f82baf (diff) | |
download | openbsd-543eeae2382e5de0b9518bdd9f7a75e5686fd056.tar.gz openbsd-543eeae2382e5de0b9518bdd9f7a75e5686fd056.tar.bz2 openbsd-543eeae2382e5de0b9518bdd9f7a75e5686fd056.zip |
netbsd: bind 4.9.3
Diffstat (limited to 'src/lib/libc/net/nsap_addr.c')
-rw-r--r-- | src/lib/libc/net/nsap_addr.c | 130 |
1 files changed, 130 insertions, 0 deletions
diff --git a/src/lib/libc/net/nsap_addr.c b/src/lib/libc/net/nsap_addr.c new file mode 100644 index 0000000000..e4583a3db8 --- /dev/null +++ b/src/lib/libc/net/nsap_addr.c | |||
@@ -0,0 +1,130 @@ | |||
1 | /* $NetBSD: nsap_addr.c,v 1.1 1996/02/02 15:22:24 mrg Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 1989, 1993 | ||
5 | * The Regents of the University of California. All rights reserved. | ||
6 | * | ||
7 | * Redistribution and use in source and binary forms, with or without | ||
8 | * modification, are permitted provided that the following conditions | ||
9 | * are met: | ||
10 | * 1. Redistributions of source code must retain the above copyright | ||
11 | * notice, this list of conditions and the following disclaimer. | ||
12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer in the | ||
14 | * documentation and/or other materials provided with the distribution. | ||
15 | * 3. All advertising materials mentioning features or use of this software | ||
16 | * must display the following acknowledgement: | ||
17 | * This product includes software developed by the University of | ||
18 | * California, Berkeley and its contributors. | ||
19 | * 4. Neither the name of the University nor the names of its contributors | ||
20 | * may be used to endorse or promote products derived from this software | ||
21 | * without specific prior written permission. | ||
22 | * | ||
23 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
26 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
27 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
28 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
29 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
30 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
32 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
33 | * SUCH DAMAGE. | ||
34 | */ | ||
35 | |||
36 | #if defined(LIBC_SCCS) && !defined(lint) | ||
37 | #if 0 | ||
38 | static char rcsid[] = "$Id: lib-libc-net,v 8.1 1995/12/22 21:59:52 vixie Exp "; | ||
39 | #else | ||
40 | static char rcsid[] = "$NetBSD: nsap_addr.c,v 1.1 1996/02/02 15:22:24 mrg Exp $"; | ||
41 | #endif | ||
42 | #endif /* LIBC_SCCS and not lint */ | ||
43 | |||
44 | #include <sys/param.h> | ||
45 | #include <sys/socket.h> | ||
46 | #include <netinet/in.h> | ||
47 | #include <arpa/nameser.h> | ||
48 | #include <ctype.h> | ||
49 | #include <resolv.h> | ||
50 | |||
51 | static char | ||
52 | xtob(c) | ||
53 | register int c; | ||
54 | { | ||
55 | return (c - (((c >= '0') && (c <= '9')) ? '0' : '7')); | ||
56 | } | ||
57 | |||
58 | /* These have to be here for BIND and its utilities (DiG, nslookup, et al) | ||
59 | * but should not be promulgated since the calling interface is not pretty. | ||
60 | * (They do, however, implement the RFC standard way of representing ISO NSAPs | ||
61 | * and as such, are preferred over the more general iso_addr.c routines. | ||
62 | */ | ||
63 | |||
64 | u_int | ||
65 | inet_nsap_addr(ascii, binary, maxlen) | ||
66 | const char *ascii; | ||
67 | u_char *binary; | ||
68 | int maxlen; | ||
69 | { | ||
70 | register u_char c, nib; | ||
71 | u_int len = 0; | ||
72 | |||
73 | while ((c = *ascii++) != '\0' && len < maxlen) { | ||
74 | if (c == '.' || c == '+' || c == '/') | ||
75 | continue; | ||
76 | if (!isascii(c)) | ||
77 | return (0); | ||
78 | if (islower(c)) | ||
79 | c = toupper(c); | ||
80 | if (isxdigit(c)) { | ||
81 | nib = xtob(c); | ||
82 | if (c = *ascii++) { | ||
83 | c = toupper(c); | ||
84 | if (isxdigit(c)) { | ||
85 | *binary++ = (nib << 4) | xtob(c); | ||
86 | len++; | ||
87 | } else | ||
88 | return (0); | ||
89 | } | ||
90 | else | ||
91 | return (0); | ||
92 | } | ||
93 | else | ||
94 | return (0); | ||
95 | } | ||
96 | return (len); | ||
97 | } | ||
98 | |||
99 | char * | ||
100 | inet_nsap_ntoa(binlen, binary, ascii) | ||
101 | int binlen; | ||
102 | register const u_char *binary; | ||
103 | register char *ascii; | ||
104 | { | ||
105 | register int nib; | ||
106 | int i; | ||
107 | static char tmpbuf[255*3]; | ||
108 | char *start; | ||
109 | |||
110 | if (ascii) | ||
111 | start = ascii; | ||
112 | else { | ||
113 | ascii = tmpbuf; | ||
114 | start = tmpbuf; | ||
115 | } | ||
116 | |||
117 | if (binlen > 255) | ||
118 | binlen = 255; | ||
119 | |||
120 | for (i = 0; i < binlen; i++) { | ||
121 | nib = *binary >> 4; | ||
122 | *ascii++ = nib + (nib < 10 ? '0' : '7'); | ||
123 | nib = *binary++ & 0x0f; | ||
124 | *ascii++ = nib + (nib < 10 ? '0' : '7'); | ||
125 | if (((i % 2) == 0 && (i + 1) < binlen)) | ||
126 | *ascii++ = '.'; | ||
127 | } | ||
128 | *ascii = '\0'; | ||
129 | return (start); | ||
130 | } | ||