Include "stdio-common/_itoa.h" instead of "stdio/_itoa.h".
[glibc.git] / resolv / nsap_addr.c
blob6a8b75c0dec115050d88dc199856da92881176cb
1 #if defined(LIBC_SCCS) && !defined(lint)
2 static char rcsid[] = "$Id$";
3 #endif /* LIBC_SCCS and not lint */
5 #include <sys/param.h>
6 #include <sys/socket.h>
7 #include <netinet/in.h>
8 #include <arpa/nameser.h>
9 #include <ctype.h>
10 #include <resolv.h>
12 #include "../conf/portability.h"
14 #if !defined(isxdigit) /* XXX - could be a function */
15 static int
16 isxdigit(c)
17 register int c;
19 return ((c >= '0') && (c <= '9')) || ((c >= 'A') && (c <= 'F'));
21 #endif
23 static char
24 xtob(c)
25 register int c;
27 return (c - (((c >= '0') && (c <= '9')) ? '0' : '7'));
30 u_int
31 inet_nsap_addr(ascii, binary, maxlen)
32 const char *ascii;
33 u_char *binary;
34 int maxlen;
36 register u_char c, nib;
37 u_int len = 0;
39 while ((c = *ascii++) != '\0' && len < maxlen) {
40 if (c == '.' || c == '+' || c == '/')
41 continue;
42 if (!isascii(c))
43 return (0);
44 if (islower(c))
45 c = toupper(c);
46 if (isxdigit(c)) {
47 nib = xtob(c);
48 if (c = *ascii++) {
49 c = toupper(c);
50 if (isxdigit(c)) {
51 *binary++ = (nib << 4) | xtob(c);
52 len++;
53 } else
54 return (0);
56 else
57 return (0);
59 else
60 return (0);
62 return (len);
65 char *
66 inet_nsap_ntoa(binlen, binary, ascii)
67 int binlen;
68 register const u_char *binary;
69 register char *ascii;
71 register int nib;
72 int i;
73 static char tmpbuf[255*3];
74 char *start;
76 if (ascii)
77 start = ascii;
78 else {
79 ascii = tmpbuf;
80 start = tmpbuf;
83 if (binlen > 255)
84 binlen = 255;
86 for (i = 0; i < binlen; i++) {
87 nib = *binary >> 4;
88 *ascii++ = nib + (nib < 10 ? '0' : '7');
89 nib = *binary++ & 0x0f;
90 *ascii++ = nib + (nib < 10 ? '0' : '7');
91 if (((i % 2) == 0 && (i + 1) < binlen))
92 *ascii++ = '.';
94 *ascii = '\0';
95 return (start);