Changeset 9b035a0a in rtems


Ignore:
Timestamp:
Jun 7, 2017, 5:11:23 AM (2 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
e744c36
Parents:
3bc19384
git-author:
Sebastian Huber <sebastian.huber@…> (06/07/17 05:11:23)
git-committer:
Sebastian Huber <sebastian.huber@…> (06/07/17 11:02:21)
Message:

network: Update <arpa/inet.h>

Update #2833.

Location:
cpukit/libnetworking
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • cpukit/libnetworking/include/arpa/inet.h

    r3bc19384 r9b035a0a  
    113113#endif
    114114
     115/* XXX all new diversions!! argh!! */
     116#if __BSD_VISIBLE
     117#define inet_addr               __inet_addr
     118#define inet_aton               __inet_aton
     119#define inet_lnaof              __inet_lnaof
     120#define inet_makeaddr           __inet_makeaddr
     121#define inet_neta               __inet_neta
     122#define inet_netof              __inet_netof
     123#define inet_network            __inet_network
     124#define inet_net_ntop           __inet_net_ntop
     125#define inet_net_pton           __inet_net_pton
     126#define inet_cidr_ntop          __inet_cidr_ntop
     127#define inet_cidr_pton          __inet_cidr_pton
     128#define inet_ntoa               __inet_ntoa
     129#define inet_ntoa_r             __inet_ntoa_r
     130#define inet_pton               __inet_pton
     131#define inet_ntop               __inet_ntop
     132#define inet_nsap_addr          __inet_nsap_addr
     133#define inet_nsap_ntoa          __inet_nsap_ntoa
     134#endif /* __BSD_VISIBLE */
     135
    115136__BEGIN_DECLS
    116137#ifndef _BYTEORDER_PROTOTYPED
  • cpukit/libnetworking/libc/inet_addr.c

    r3bc19384 r9b035a0a  
    11/*
    2  * ++Copyright++ 1983, 1990, 1993
    3  * -
    42 * Copyright (c) 1983, 1990, 1993
    53 *    The Regents of the University of California.  All rights reserved.
     
    1311 *    notice, this list of conditions and the following disclaimer in the
    1412 *    documentation and/or other materials provided with the distribution.
    15  * 3. All advertising materials mentioning features or use of this software
    16  *    must display the following acknowledgement:
    17  *      This product includes software developed by the University of
    18  *      California, Berkeley and its contributors.
    19  * 4. Neither the name of the University nor the names of its contributors
     13 * 3. Neither the name of the University nor the names of its contributors
    2014 *    may be used to endorse or promote products derived from this software
    2115 *    without specific prior written permission.
     
    3226 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    3327 * SUCH DAMAGE.
    34  * -
     28 */
     29
     30/*
    3531 * Portions Copyright (c) 1993 by Digital Equipment Corporation.
    3632 *
     
    5046 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
    5147 * SOFTWARE.
    52  * -
    53  * --Copyright--
    54  */
    55 
    56 #if HAVE_CONFIG_H
    57 #include "config.h"
    58 #endif
     48 */
     49
     50/*
     51 * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
     52 * Portions Copyright (c) 1996-1999 by Internet Software Consortium.
     53 *
     54 * Permission to use, copy, modify, and distribute this software for any
     55 * purpose with or without fee is hereby granted, provided that the above
     56 * copyright notice and this permission notice appear in all copies.
     57 *
     58 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
     59 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
     60 * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR
     61 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
     62 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
     63 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
     64 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
     65 */
     66
     67#if defined(LIBC_SCCS) && !defined(lint)
     68static const char sccsid[] = "@(#)inet_addr.c   8.1 (Berkeley) 6/17/93";
     69static const char rcsid[] = "$Id: inet_addr.c,v 1.5 2005/04/27 04:56:19 sra Exp $";
     70#endif /* LIBC_SCCS and not lint */
     71#include <sys/cdefs.h>
     72__FBSDID("$FreeBSD: head/lib/libc/inet/inet_addr.c 314436 2017-02-28 23:42:47Z imp $");
     73
     74#include "port_before.h"
    5975
    6076#include <sys/param.h>
     77
    6178#include <netinet/in.h>
    6279#include <arpa/inet.h>
     80
    6381#include <ctype.h>
    6482
    65 /*
    66  * ASCII internet address interpretation routine.
     83#include "port_after.h"
     84
     85/*%
     86 * Ascii internet address interpretation routine.
    6787 * The value returned is in network order.
    6888 */
    69 in_addr_t
    70 inet_addr(
    71         const char *cp)
    72 {
     89in_addr_t               /* XXX should be struct in_addr :( */
     90inet_addr(const char *cp) {
    7391        struct in_addr val;
    7492
     
    7896}
    7997
    80 /* 
    81  * Check whether "cp" is a valid ASCII representation
     98/*%
     99 * Check whether "cp" is a valid ascii representation
    82100 * of an Internet address and convert to a binary address.
    83101 * Returns 1 if the address is valid, 0 if not.
     
    86104 */
    87105int
    88 inet_aton(
    89         const char *cp,
    90         struct in_addr *addr)
    91 {
    92         in_addr_t val;
    93         register int base, n;
    94         register char c;
    95         uint32_t parts[4];
    96         register uint32_t *pp = parts;
     106inet_aton(const char *cp, struct in_addr *addr) {
     107        u_long val;
     108        int base, n;
     109        char c;
     110        u_int8_t parts[4];
     111        u_int8_t *pp = parts;
     112        int digit;
    97113
    98114        c = *cp;
     
    105121                if (!isdigit((unsigned char)c))
    106122                        return (0);
    107                 val = 0; base = 10;
     123                val = 0; base = 10; digit = 0;
    108124                if (c == '0') {
    109125                        c = *++cp;
    110126                        if (c == 'x' || c == 'X')
    111127                                base = 16, c = *++cp;
    112                         else
     128                        else {
    113129                                base = 8;
     130                                digit = 1 ;
     131                        }
    114132                }
    115133                for (;;) {
    116                         if (isascii((unsigned char)c) && isdigit((unsigned char)c)) {
     134                        if (isascii(c) && isdigit((unsigned char)c)) {
     135                                if (base == 8 && (c == '8' || c == '9'))
     136                                        return (0);
    117137                                val = (val * base) + (c - '0');
    118138                                c = *++cp;
    119                         } else if (base == 16 && isascii((unsigned char)c) && isxdigit((unsigned char)c)) {
     139                                digit = 1;
     140                        } else if (base == 16 && isascii(c) &&
     141                                   isxdigit((unsigned char)c)) {
    120142                                val = (val << 4) |
    121143                                        (c + 10 - (islower((unsigned char)c) ? 'a' : 'A'));
    122144                                c = *++cp;
     145                                digit = 1;
    123146                        } else
    124147                                break;
     
    131154                         *      a.b     (with b treated as 24 bits)
    132155                         */
    133                         if (pp >= parts + 3)
     156                        if (pp >= parts + 3 || val > 0xffU)
    134157                                return (0);
    135158                        *pp++ = val;
     
    141164         * Check for trailing characters.
    142165         */
    143         if (c != '\0' && (!isascii((unsigned char)c) || !isspace((unsigned char)c)))
     166        if (c != '\0' && (!isascii(c) || !isspace((unsigned char)c)))
     167                return (0);
     168        /*
     169         * Did we get a valid digit?
     170         */
     171        if (!digit)
    144172                return (0);
    145173        /*
     
    149177        n = pp - parts + 1;
    150178        switch (n) {
    151 
    152         case 0:
    153                 return (0);             /* initial nondigit */
    154 
    155         case 1:                         /* a -- 32 bits */
    156                 break;
    157 
    158         case 2:                         /* a.b -- 8.24 bits */
    159                 if (val > 0xffffff)
     179        case 1:                         /*%< a -- 32 bits */
     180                break;
     181
     182        case 2:                         /*%< a.b -- 8.24 bits */
     183                if (val > 0xffffffU)
    160184                        return (0);
    161185                val |= parts[0] << 24;
    162186                break;
    163187
    164         case 3:                         /* a.b.c -- 8.8.16 bits */
    165                 if (val > 0xffff)
     188        case 3:                         /*%< a.b.c -- 8.8.16 bits */
     189                if (val > 0xffffU)
    166190                        return (0);
    167191                val |= (parts[0] << 24) | (parts[1] << 16);
    168192                break;
    169193
    170         case 4:                         /* a.b.c.d -- 8.8.8.8 bits */
    171                 if (val > 0xff)
     194        case 4:                         /*%< a.b.c.d -- 8.8.8.8 bits */
     195                if (val > 0xffU)
    172196                        return (0);
    173197                val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8);
     
    178202        return (1);
    179203}
     204
     205/*
     206 * Weak aliases for applications that use certain private entry points,
     207 * and fail to include <arpa/inet.h>.
     208 */
     209#undef inet_addr
     210__weak_reference(__inet_addr, inet_addr);
     211#undef inet_aton
     212__weak_reference(__inet_aton, inet_aton);
     213
     214/*! \file */
  • cpukit/libnetworking/libc/inet_ntoa.c

    r3bc19384 r9b035a0a  
    1 /*
     1/*-
    22 * Copyright (c) 1983, 1993
    33 *      The Regents of the University of California.  All rights reserved.
     
    1111 *    notice, this list of conditions and the following disclaimer in the
    1212 *    documentation and/or other materials provided with the distribution.
    13  * 3. All advertising materials mentioning features or use of this software
    14  *    must display the following acknowledgement:
    15  *      This product includes software developed by the University of
    16  *      California, Berkeley and its contributors.
    17  * 4. Neither the name of the University nor the names of its contributors
     13 * 3. Neither the name of the University nor the names of its contributors
    1814 *    may be used to endorse or promote products derived from this software
    1915 *    without specific prior written permission.
     
    3228 */
    3329
    34 #if HAVE_CONFIG_H
    35 #include "config.h"
    36 #endif
     30#if defined(LIBC_SCCS) && !defined(lint)
     31static const char sccsid[] = "@(#)inet_ntoa.c   8.1 (Berkeley) 6/4/93";
     32static const char rcsid[] = "$Id: inet_ntoa.c,v 1.2 2005/04/27 04:56:21 sra Exp $";
     33#endif /* LIBC_SCCS and not lint */
     34#include <sys/cdefs.h>
     35__FBSDID("$FreeBSD: head/lib/libc/inet/inet_ntoa.c 314436 2017-02-28 23:42:47Z imp $");
     36
     37#include "port_before.h"
    3738
    3839#include <sys/types.h>
     
    4041#include <netinet/in.h>
    4142#include <arpa/inet.h>
     43
    4244#include <stdio.h>
    43 #include <sys/libkern.h> /* for strcpy */
     45#include <string.h>
    4446
    45 /*
     47#include "port_after.h"
     48
     49/*%
    4650 * Convert network-format internet address
    4751 * to base 256 d.d.d.d representation.
    4852 */
    49 char *
    50 inet_ntoa(
    51         struct in_addr in)
    52 {
     53/*const*/ char *
     54inet_ntoa(struct in_addr in) {
    5355        static char ret[18];
    5456
     
    5759        return (ret);
    5860}
     61
     62char *
     63inet_ntoa_r(struct in_addr in, char *buf, socklen_t size)
     64{
     65
     66        (void) inet_ntop(AF_INET, &in, buf, size);
     67        return (buf);
     68}
     69
     70/*
     71 * Weak aliases for applications that use certain private entry points,
     72 * and fail to include <arpa/inet.h>.
     73 */
     74#undef inet_ntoa
     75__weak_reference(__inet_ntoa, inet_ntoa);
     76__weak_reference(__inet_ntoa_r, inet_ntoa_r);
     77
     78/*! \file */
  • cpukit/libnetworking/libc/inet_ntop.c

    r3bc19384 r9b035a0a  
    1 /* Copyright (c) 1996 by Internet Software Consortium.
     1/*
     2 * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
     3 * Copyright (c) 1996-1999 by Internet Software Consortium.
    24 *
    35 * Permission to use, copy, modify, and distribute this software for any
     
    57 * copyright notice and this permission notice appear in all copies.
    68 *
    7  * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
    8  * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
    9  * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
    10  * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
    11  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
    12  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
    13  * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
    14  * SOFTWARE.
    15  */
    16 
    17 #if HAVE_CONFIG_H
    18 #include "config.h"
    19 #endif
     9 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
     10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
     11 * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR
     12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
     13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
     14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
     15 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
     16 */
     17
     18#if defined(LIBC_SCCS) && !defined(lint)
     19static const char rcsid[] = "$Id: inet_ntop.c,v 1.5 2005/11/03 22:59:52 marka Exp $";
     20#endif /* LIBC_SCCS and not lint */
     21#include <sys/cdefs.h>
     22__FBSDID("$FreeBSD: head/lib/libc/inet/inet_ntop.c 298226 2016-04-18 21:05:15Z avos $");
     23
     24#include "port_before.h"
    2025
    2126#include <sys/param.h>
    22 #include <sys/types.h>
    2327#include <sys/socket.h>
     28
    2429#include <netinet/in.h>
    2530#include <arpa/inet.h>
    2631#include <arpa/nameser.h>
     32
    2733#include <errno.h>
    2834#include <stdio.h>
    2935#include <string.h>
    3036
    31 #define SPRINTF(x) ((size_t)sprintf x)
    32 
    33 /*
     37#include "port_after.h"
     38
     39/*%
    3440 * WARNING: Don't even consider trying to compile this on a system where
    3541 * sizeof(int) < 4.  sizeof(int) > 4 is fine; all the world's not a VAX.
     
    3945static const char *inet_ntop6(const u_char *src, char *dst, socklen_t size);
    4046
    41 /* char *
     47/* const char *
    4248 * inet_ntop(af, src, dst, size)
    4349 *      convert a network format address to presentation format.
     
    4854 */
    4955const char *
    50 inet_ntop(
    51         int af,
    52         const void *src,
    53         char *dst,
    54         socklen_t size)
     56inet_ntop(int af, const void * __restrict src, char * __restrict dst,
     57    socklen_t size)
    5558{
    5659        switch (af) {
     
    6871/* const char *
    6972 * inet_ntop4(src, dst, size)
    70  *      format an IPv4 address, more or less like inet_ntoa()
     73 *      format an IPv4 address
    7174 * return:
    7275 *      `dst' (as a const)
     
    7881 */
    7982static const char *
    80 inet_ntop4(
    81         const u_char *src,
    82         char *dst,
    83         socklen_t size)
     83inet_ntop4(const u_char *src, char *dst, socklen_t size)
    8484{
    8585        static const char fmt[] = "%u.%u.%u.%u";
    8686        char tmp[sizeof "255.255.255.255"];
    87 
    88         if (SPRINTF((tmp, fmt, src[0], src[1], src[2], src[3])) > size) {
     87        int l;
     88
     89        l = snprintf(tmp, sizeof(tmp), fmt, src[0], src[1], src[2], src[3]);
     90        if (l <= 0 || (socklen_t) l >= size) {
    8991                errno = ENOSPC;
    9092                return (NULL);
    9193        }
    92         strcpy(dst, tmp);
     94        strlcpy(dst, tmp, size);
    9395        return (dst);
    9496}
     
    101103 */
    102104static const char *
    103 inet_ntop6(
    104         const u_char *src,
    105         char *dst,
    106         socklen_t size)
     105inet_ntop6(const u_char *src, char *dst, socklen_t size)
    107106{
    108107        /*
     
    127126                words[i / 2] |= (src[i] << ((1 - (i % 2)) << 3));
    128127        best.base = -1;
    129         best.len  = 0;
     128        best.len = 0;
    130129        cur.base = -1;
    131         cur.len  = 0;
     130        cur.len = 0;
    132131        for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) {
    133132                if (words[i] == 0) {
     
    167166                        *tp++ = ':';
    168167                /* Is this address an encapsulated IPv4? */
    169                 if (i == 6 && best.base == 0 &&
    170                     (best.len == 6 || (best.len == 5 && words[5] == 0xffff))) {
    171                         if (!inet_ntop4(src+12, tp, sizeof tmp - (tp - tmp)))
     168                if (i == 6 && best.base == 0 && (best.len == 6 ||
     169                    (best.len == 7 && words[7] != 0x0001) ||
     170                    (best.len == 5 && words[5] == 0xffff))) {
     171                        if (!inet_ntop4(src+12, tp, sizeof tmp - (tp - tmp))) {
     172                                errno = ENOSPC;
    172173                                return (NULL);
     174                        }
    173175                        tp += strlen(tp);
    174176                        break;
    175177                }
    176                 tp += SPRINTF((tp, "%x", words[i]));
     178                tp += sprintf(tp, "%x", words[i]);
    177179        }
    178180        /* Was it a trailing run of 0x00's? */
    179         if (best.base != -1 && (best.base + best.len) ==
     181        if (best.base != -1 && (best.base + best.len) == 
    180182            (NS_IN6ADDRSZ / NS_INT16SZ))
    181183                *tp++ = ':';
     
    185187         * Check for overflow, copy, and we're done.
    186188         */
    187         if ((size_t)(tp - tmp) > size) {
     189        if ((socklen_t)(tp - tmp) > size) {
    188190                errno = ENOSPC;
    189191                return (NULL);
     
    192194        return (dst);
    193195}
     196
     197/*
     198 * Weak aliases for applications that use certain private entry points,
     199 * and fail to include <arpa/inet.h>.
     200 */
     201#undef inet_ntop
     202__weak_reference(__inet_ntop, inet_ntop);
     203
     204/*! \file */
Note: See TracChangeset for help on using the changeset viewer.