* Copyright (c) 1986 Regents of the University of California.
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
* This code is derived from software contributed to Berkeley by
* J.Q. Johnson at Cornell University.
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid
[] = "@(#)ns_addr.c 6.4 (Berkeley) 8/12/88";
#endif /* LIBC_SCCS and not lint */
static struct ns_addr addr
, zero_addr
;
char *hostname
, *socketname
, *cp
;
(void)strncpy(buf
, name
, 49);
* First, figure out what he intends as a field separtor.
* Despite the way this routine is written, the prefered
* form 2-272.AA001234H.01777, i.e. XDE standard.
* Great efforts are made to insure backward compatability.
if (hostname
= index(buf
, '#'))
hostname
= index(buf
, '.');
if ((cp
= index(buf
, ':')) &&
( (hostname
&& cp
< hostname
) || (hostname
== 0))) {
Field(buf
, addr
.x_net
.c_net
, 4);
return (addr
); /* No separator means net only */
socketname
= index(hostname
, separator
);
Field(socketname
, (u_char
*)&addr
.x_port
, 2);
Field(hostname
, addr
.x_host
.c_host
, 6);
int i
, ibase
, base16
= 0, base10
= 0, clen
= 0;
* first try 2-273#2-852-151-014#socket
(1 < (i
= sscanf(buf
, "%d-%d-%d-%d-%d",
&hb
[0], &hb
[1], &hb
[2], &hb
[3], &hb
[4])))) {
cvtbase(1000L, 256, hb
, i
, out
, len
);
* try form 8E1#0.0.AA.0.5E.E6#socket
if (1 < (i
= sscanf(buf
,"%x.%x.%x.%x.%x.%x",
&hb
[0], &hb
[1], &hb
[2], &hb
[3], &hb
[4], &hb
[5]))) {
cvtbase(256L, 256, hb
, i
, out
, len
);
* try form 8E1#0:0:AA:0:5E:E6#socket
if (1 < (i
= sscanf(buf
,"%x:%x:%x:%x:%x:%x",
&hb
[0], &hb
[1], &hb
[2], &hb
[3], &hb
[4], &hb
[5]))) {
cvtbase(256L, 256, hb
, i
, out
, len
);
* This is REALLY stretching it but there was a
* comma notation separting shorts -- definitely non standard
if (1 < (i
= sscanf(buf
,"%x,%x,%x",
&hb
[0], &hb
[1], &hb
[2]))) {
hb
[0] = htons(hb
[0]); hb
[1] = htons(hb
[1]);
cvtbase(65536L, 256, hb
, i
, out
, len
);
/* Need to decide if base 10, 16 or 8 */
while (*bp
) switch (*bp
++) {
case '0': case '1': case '2': case '3': case '4': case '5':
case '6': case '7': case '-':
case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
*--bp
= 0; /* Ends Loop */
} else if (base10
== 0 && *buf
== '0') {
for (bp
= buf
; *bp
++; ) clen
++;
if (clen
> 18) clen
= 18;
i
= ((clen
- 1) / 3) + 1;
(void)sscanf(bp
, fmt
, hp
);
(void)sscanf(buf
, fmt
, hp
);
cvtbase((long)ibase
, 256, hb
, i
, out
, len
);
cvtbase(oldbase
,newbase
,input
,inlen
,result
,reslen
)
while (e
> 0 && reslen
> 0) {
/* long division: input=input/newbase */
sum
= sum
*oldbase
+ (long) input
[d
];
input
[d
++] = sum
/ newbase
;
result
[--reslen
] = sum
; /* accumulate remainder */
for (d
=0; d
< reslen
; d
++)