]>
git.saurik.com Git - apple/libc.git/blob - net/nsap_addr.c
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
25 #if defined(LIBC_SCCS) && !defined(lint)
26 static char rcsid
[] = "$Id: nsap_addr.c,v 1.4 2002/05/17 21:00:31 bbraun Exp $";
27 #endif /* LIBC_SCCS and not lint */
29 #include <sys/param.h>
30 #include <sys/socket.h>
31 #include <netinet/in.h>
32 #include <arpa/nameser.h>
37 #if !defined(isxdigit) /* XXX - could be a function */
42 return ((c
>= '0') && (c
<= '9')) || ((c
>= 'A') && (c
<= 'F'));
50 return (c
- (((c
>= '0') && (c
<= '9')) ? '0' : '7'));
54 inet_nsap_addr(ascii
, binary
, maxlen
)
59 register u_char c
, nib
;
62 while ((c
= *ascii
++) != '\0' && len
< maxlen
) {
63 if (c
== '.' || c
== '+' || c
== '/')
74 *binary
++ = (nib
<< 4) | xtob(c
);
89 inet_nsap_ntoa(binlen
, binary
, ascii
)
91 register const u_char
*binary
;
96 static char *tmpbuf
= NULL
;
99 if( tmpbuf
== NULL
) {
100 tmpbuf
= malloc(255*3);
115 for (i
= 0; i
< binlen
; i
++) {
117 *ascii
++ = nib
+ (nib
< 10 ? '0' : '7');
118 nib
= *binary
++ & 0x0f;
119 *ascii
++ = nib
+ (nib
< 10 ? '0' : '7');
120 if (((i
% 2) == 0 && (i
+ 1) < binlen
))