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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rtems/] [c/] [src/] [libnetworking/] [libc/] [inet_neta.c] - Blame information for rev 1767

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 158 chris
/*
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)
19
static const char orig_rcsid[] = "From Id: inet_neta.c,v 8.2 1996/08/08 06:54:44 vixie Exp";
20 208 chris
static const char rcsid[] = "$Id: inet_neta.c,v 1.2 2001-09-27 12:01:53 chris Exp $";
21 158 chris
#endif
22
 
23
#include <sys/types.h>
24
#include <sys/socket.h>
25
#include <netinet/in.h>
26
#include <arpa/inet.h>
27
 
28
#include <errno.h>
29
#include <stdio.h>
30
#include <string.h>
31
 
32
#ifdef SPRINTF_CHAR
33
# define SPRINTF(x) strlen(sprintf/**/x)
34
#else
35
# define SPRINTF(x) ((size_t)sprintf x)
36
#endif
37
 
38
/*
39
 * char *
40
 * inet_neta(src, dst, size)
41
 *      format a u_long network number into presentation format.
42
 * return:
43
 *      pointer to dst, or NULL if an error occurred (check errno).
44
 * note:
45
 *      format of ``src'' is as for inet_network().
46
 * author:
47
 *      Paul Vixie (ISC), July 1996
48
 */
49
char *
50
inet_neta(src, dst, size)
51
        u_long src;
52
        char *dst;
53
        size_t size;
54
{
55
        char *odst = dst;
56
        char *tp;
57
 
58
        while (src & 0xffffffff) {
59
                u_char b = (src & 0xff000000) >> 24;
60
 
61
                src <<= 8;
62
                if (b) {
63
                        if (size < sizeof "255.")
64
                                goto emsgsize;
65
                        tp = dst;
66
                        dst += SPRINTF((dst, "%u", b));
67
                        if (src != 0L) {
68
                                *dst++ = '.';
69
                                *dst = '\0';
70
                        }
71
                        size -= (size_t)(dst - tp);
72
                }
73
        }
74
        if (dst == odst) {
75
                if (size < sizeof "0.0.0.0")
76
                        goto emsgsize;
77
                strcpy(dst, "0.0.0.0");
78
        }
79
        return (odst);
80
 
81
 emsgsize:
82
        errno = EMSGSIZE;
83
        return (NULL);
84
}

powered by: WebSVN 2.1.0

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