source: rtems/cpukit/libnetworking/libc/nsap_addr.c @ cb2f320

4.104.114.84.9
Last change on this file since cb2f320 was cb2f320, checked in by Joel Sherrill <joel.sherrill@…>, on Mar 5, 2004 at 6:02:41 PM

2004-03-05 Joel Sherrill <joel@…>

  • libblock/src/bdbuf.c, libblock/src/ramdisk.c, libcsupport/src/newlibc.c, libcsupport/src/sync.c, libmisc/cpuuse/cpuuse.c, libmisc/monitor/mon-symbols.c, libmisc/shell/cmds.c, libmisc/shell/shell.c, libnetworking/kern/kern_sysctl.c, libnetworking/lib/ftpfs.c, libnetworking/lib/tftpDriver.c, libnetworking/libc/gethostbydns.c, libnetworking/libc/gethostbyht.c, libnetworking/libc/gethostnamadr.c, libnetworking/libc/getnetbyht.c, libnetworking/libc/getnetnamadr.c, libnetworking/libc/inet_addr.c, libnetworking/libc/linkaddr.c, libnetworking/libc/map_v4v6.c, libnetworking/libc/ns_print.c, libnetworking/libc/ns_ttl.c, libnetworking/libc/nsap_addr.c, libnetworking/libc/rcmd.c, libnetworking/libc/res_debug.c, libnetworking/libc/res_mkupdate.c, libnetworking/libc/res_query.c, libnetworking/libc/res_send.c, libnetworking/libc/res_update.c, libnetworking/net/radix.c, libnetworking/rtems/mkrootfs.c, librpc/src/rpc/clnt_perror.c, librpc/src/rpc/svc.c, score/macros/rtems/score/chain.inl, score/src/objectidtoname.c: Too much was accidentally committed -- revert.
  • Property mode set to 100644
File size: 2.3 KB
Line 
1/*
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)
19static char rcsid[] = "$Id$";
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
31static char
32xtob(c)
33        register int c;
34{
35        return (c - (((c >= '0') && (c <= '9')) ? '0' : '7'));
36}
37
38u_int
39inet_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
74char *
75inet_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}
Note: See TracBrowser for help on using the repository browser.