source: trunk/libs/newlib/src/newlib/libc/sys/linux/net/inet_neta.c @ 444

Last change on this file since 444 was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 2.2 KB
Line 
1/*
2 * Copyright (c) 1996 by Internet Software Consortium.
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
9 * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
10 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
11 * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
12 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
13 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
14 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
15 * SOFTWARE.
16 */
17
18#if defined(LIBC_SCCS) && !defined(lint)
19static const char orig_rcsid[] = "From Id: inet_neta.c,v 8.2 1996/08/08 06:54:44 vixie Exp";
20#endif
21#include <sys/cdefs.h>
22#include <sys/types.h>
23
24#include <sys/types.h>
25#include <sys/socket.h>
26#include <netinet/in.h>
27#include <arpa/inet.h>
28
29#include <errno.h>
30#include <stdio.h>
31#include <string.h>
32
33#ifdef SPRINTF_CHAR
34# define SPRINTF(x) strlen(sprintf/**/x)
35#else
36# define SPRINTF(x) ((size_t)sprintf x)
37#endif
38
39/*
40 * char *
41 * inet_neta(src, dst, size)
42 *      format a in_addr_t network number into presentation format.
43 * return:
44 *      pointer to dst, or NULL if an error occurred (check errno).
45 * note:
46 *      format of ``src'' is as for inet_network().
47 * author:
48 *      Paul Vixie (ISC), July 1996
49 */
50char *
51inet_neta(src, dst, size)
52        in_addr_t src;
53        char *dst;
54        size_t size;
55{
56        char *odst = dst;
57        char *tp;
58
59        while (src & 0xffffffff) {
60                u_char b = (src & 0xff000000) >> 24;
61
62                src <<= 8;
63                if (b) {
64                        if (size < sizeof "255.")
65                                goto emsgsize;
66                        tp = dst;
67                        dst += SPRINTF((dst, "%u", b));
68                        if (src != 0L) {
69                                *dst++ = '.';
70                                *dst = '\0';
71                        }
72                        size -= (size_t)(dst - tp);
73                }
74        }
75        if (dst == odst) {
76                if (size < sizeof "0.0.0.0")
77                        goto emsgsize;
78                strcpy(dst, "0.0.0.0");
79        }
80        return (odst);
81
82 emsgsize:
83        errno = EMSGSIZE;
84        return (NULL);
85}
86
87/*
88 * Weak aliases for applications that use certain private entry points,
89 * and fail to include <arpa/inet.h>.
90 */
91#undef inet_neta
92__weak_reference(__inet_neta, inet_neta);
Note: See TracBrowser for help on using the repository browser.