OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [newlib-1.17.0/] [newlib/] [libc/] [sys/] [linux/] [net/] [nsap_addr.c] - Diff between revs 148 and 158

Only display areas with differences | Details | Blame | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.