]>
git.saurik.com Git - apple/libc.git/blob - net/nsap_addr.c
fd3cc99e8ba796ee1620dc01ec2f17dd21d5d839
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
22 #if defined(LIBC_SCCS) && !defined(lint)
23 static char rcsid
[] = "$Id: nsap_addr.c,v 1.4 2002/05/17 21:00:31 bbraun Exp $";
24 #endif /* LIBC_SCCS and not lint */
26 #include <sys/param.h>
27 #include <sys/socket.h>
28 #include <netinet/in.h>
29 #include <arpa/nameser.h>
34 #if !defined(isxdigit) /* XXX - could be a function */
39 return ((c
>= '0') && (c
<= '9')) || ((c
>= 'A') && (c
<= 'F'));
47 return (c
- (((c
>= '0') && (c
<= '9')) ? '0' : '7'));
51 inet_nsap_addr(ascii
, binary
, maxlen
)
56 register u_char c
, nib
;
59 while ((c
= *ascii
++) != '\0' && len
< maxlen
) {
60 if (c
== '.' || c
== '+' || c
== '/')
71 *binary
++ = (nib
<< 4) | xtob(c
);
86 inet_nsap_ntoa(binlen
, binary
, ascii
)
88 register const u_char
*binary
;
93 static char *tmpbuf
= NULL
;
96 if( tmpbuf
== NULL
) {
97 tmpbuf
= malloc(255*3);
112 for (i
= 0; i
< binlen
; i
++) {
114 *ascii
++ = nib
+ (nib
< 10 ? '0' : '7');
115 nib
= *binary
++ & 0x0f;
116 *ascii
++ = nib
+ (nib
< 10 ? '0' : '7');
117 if (((i
% 2) == 0 && (i
+ 1) < binlen
))