source: rtems/cpukit/libnetworking/libc/gethostbynis.c @ 0e16fa45

5
Last change on this file since 0e16fa45 was cb68253, checked in by Sebastian Huber <sebastian.huber@…>, on 09/07/18 at 04:19:02

network: Use kernel/user space header files

Add and use <machine/rtems-bsd-kernel-space.h> and
<machine/rtems-bsd-user-space.h> similar to the libbsd to avoid command
line defines and defines scattered throught the code base.

Simplify cpukit/libnetworking/Makefile.am.

Update #3375.

  • Property mode set to 100644
File size: 3.5 KB
Line 
1#include <machine/rtems-bsd-user-space.h>
2
3/*-
4 * Copyright (c) 1994, Garrett Wollman
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in the
13 *    documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 */
27
28#if HAVE_CONFIG_H
29#include "config.h"
30#endif
31
32#include <sys/param.h>
33#include <sys/socket.h>
34#include <netinet/in.h>
35#include <arpa/inet.h>
36#include <netdb.h>
37#include <rtems/rtems_netdb.h>
38#include <stdio.h>
39#include <stdlib.h>
40#include <ctype.h>
41#include <errno.h>
42#include <string.h>
43#ifdef YP
44#include <rpc/rpc.h>
45#include <rpcsvc/yp_prot.h>
46#include <rpcsvc/ypclnt.h>
47#endif
48
49#define MAXALIASES      35
50#define MAXADDRS        35
51
52#ifdef YP
53static char *host_aliases[MAXALIASES];
54static char hostaddr[MAXADDRS];
55static char *host_addrs[2];
56#endif /* YP */
57
58static struct hostent *
59_gethostbynis(
60        const char *name,
61        char *map,
62        int af)
63{
64#ifdef YP
65        register char *cp, **q;
66        char *result;
67        int resultlen;
68        static struct hostent h;
69        static char *domain = (char *)NULL;
70        static char ypbuf[YPMAXRECORD + 2];
71
72        switch(af) {
73        case AF_INET:
74                break;
75        default:
76        case AF_INET6:
77                errno = EAFNOSUPPORT;
78                return NULL;
79        }
80
81        if (domain == (char *)NULL)
82                if (yp_get_default_domain (&domain))
83                        return ((struct hostent *)NULL);
84
85        if (yp_match(domain, map, name, strlen(name), &result, &resultlen))
86                return ((struct hostent *)NULL);
87
88        /* avoid potential memory leak */
89        bcopy((char *)result, (char *)&ypbuf, resultlen);
90        ypbuf[resultlen] = '\0';
91        free(result);
92        result = (char *)&ypbuf;
93
94        if ((cp = index(result, '\n')))
95                *cp = '\0';
96
97        cp = strpbrk(result, " \t");
98        *cp++ = '\0';
99        h.h_addr_list = host_addrs;
100        h.h_addr = hostaddr;
101        *((u_long *)h.h_addr) = inet_addr(result);
102        h.h_length = sizeof(u_long);
103        h.h_addrtype = AF_INET;
104        while (*cp == ' ' || *cp == '\t')
105                cp++;
106        h.h_name = cp;
107        q = h.h_aliases = host_aliases;
108        cp = strpbrk(cp, " \t");
109        if (cp != NULL)
110                *cp++ = '\0';
111        while (cp && *cp) {
112                if (*cp == ' ' || *cp == '\t') {
113                        cp++;
114                        continue;
115                }
116                if (q < &host_aliases[MAXALIASES - 1])
117                        *q++ = cp;
118                cp = strpbrk(cp, " \t");
119                if (cp != NULL)
120                        *cp++ = '\0';
121        }
122        *q = NULL;
123        return (&h);
124#else
125        return (NULL);
126#endif /* YP */
127}
128
129struct hostent *
130_gethostbynisname(
131        const char *name,
132        int af)
133{
134        return _gethostbynis(name, "hosts.byname", af);
135}
136
137struct hostent *
138_gethostbynisaddr(
139        const char *addr,
140        int len,
141        int af)
142{
143        return _gethostbynis(inet_ntoa(*(struct in_addr *)addr),"hosts.byaddr", af);
144}
Note: See TracBrowser for help on using the repository browser.