|
Packit |
6c4009 |
/*
|
|
Packit |
6c4009 |
* Copyright (c) 1996-1999 by Internet Software Consortium.
|
|
Packit |
6c4009 |
*
|
|
Packit |
6c4009 |
* Permission to use, copy, modify, and distribute this software for any
|
|
Packit |
6c4009 |
* purpose with or without fee is hereby granted, provided that the above
|
|
Packit |
6c4009 |
* copyright notice and this permission notice appear in all copies.
|
|
Packit |
6c4009 |
*
|
|
Packit |
6c4009 |
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
|
|
Packit |
6c4009 |
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
|
|
Packit |
6c4009 |
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
|
|
Packit |
6c4009 |
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
|
Packit |
6c4009 |
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
|
|
Packit |
6c4009 |
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
|
|
Packit |
6c4009 |
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
|
Packit |
6c4009 |
* SOFTWARE.
|
|
Packit |
6c4009 |
*/
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <sys/types.h>
|
|
Packit |
6c4009 |
#include <sys/param.h>
|
|
Packit |
6c4009 |
#include <sys/socket.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <netinet/in.h>
|
|
Packit |
6c4009 |
#include <arpa/inet.h>
|
|
Packit |
6c4009 |
#include <arpa/nameser.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <ctype.h>
|
|
Packit |
6c4009 |
#include <resolv.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
static char
|
|
Packit |
6c4009 |
xtob(int c) {
|
|
Packit |
6c4009 |
return (c - (((c >= '0') && (c <= '9')) ? '0' : '7'));
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
u_int
|
|
Packit |
6c4009 |
inet_nsap_addr(const char *ascii, u_char *binary, int maxlen) {
|
|
Packit |
6c4009 |
u_char c, nib;
|
|
Packit |
6c4009 |
u_int len = 0;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
while ((c = *ascii++) != '\0' && len < (u_int)maxlen) {
|
|
Packit |
6c4009 |
if (c == '.' || c == '+' || c == '/')
|
|
Packit |
6c4009 |
continue;
|
|
Packit |
6c4009 |
if (!isascii(c))
|
|
Packit |
6c4009 |
return (0);
|
|
Packit |
6c4009 |
c = toupper(c);
|
|
Packit |
6c4009 |
if (isxdigit(c)) {
|
|
Packit |
6c4009 |
nib = xtob(c);
|
|
Packit |
6c4009 |
c = *ascii++;
|
|
Packit |
6c4009 |
if (c != '\0') {
|
|
Packit |
6c4009 |
c = toupper(c);
|
|
Packit |
6c4009 |
if (isxdigit(c)) {
|
|
Packit |
6c4009 |
*binary++ = (nib << 4) | xtob(c);
|
|
Packit |
6c4009 |
len++;
|
|
Packit |
6c4009 |
} else
|
|
Packit |
6c4009 |
return (0);
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
else
|
|
Packit |
6c4009 |
return (0);
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
else
|
|
Packit |
6c4009 |
return (0);
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
return (len);
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
char *
|
|
Packit |
6c4009 |
inet_nsap_ntoa(int binlen, const u_char *binary, char *ascii) {
|
|
Packit |
6c4009 |
int nib;
|
|
Packit |
6c4009 |
int i;
|
|
Packit |
6c4009 |
static char tmpbuf[255*2 + 128];
|
|
Packit |
6c4009 |
char *start;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
if (ascii)
|
|
Packit |
6c4009 |
start = ascii;
|
|
Packit |
6c4009 |
else {
|
|
Packit |
6c4009 |
ascii = tmpbuf;
|
|
Packit |
6c4009 |
start = tmpbuf;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
if (binlen > 255)
|
|
Packit |
6c4009 |
binlen = 255;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
for (i = 0; i < binlen; i++) {
|
|
Packit |
6c4009 |
nib = *binary >> 4;
|
|
Packit |
6c4009 |
*ascii++ = nib + (nib < 10 ? '0' : '7');
|
|
Packit |
6c4009 |
nib = *binary++ & 0x0f;
|
|
Packit |
6c4009 |
*ascii++ = nib + (nib < 10 ? '0' : '7');
|
|
Packit |
6c4009 |
if (((i % 2) == 0 && (i + 1) < binlen))
|
|
Packit |
6c4009 |
*ascii++ = '.';
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
*ascii = '\0';
|
|
Packit |
6c4009 |
return (start);
|
|
Packit |
6c4009 |
}
|