]>
git.proxmox.com Git - mirror_edk2.git/blob - StdLib/BsdSocketLib/gethostbynis.c
2 * Copyright (c) 1994, Garrett Wollman
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 #if defined(LIBC_SCCS) && !defined(lint)
27 static char sccsid
[] = "@(#)$Id: gethostbynis.c,v 1.1.1.1 2003/11/19 01:51:27 kyu3 Exp $";
28 static char rcsid
[] = "$Id: gethostbynis.c,v 1.1.1.1 2003/11/19 01:51:27 kyu3 Exp $";
29 #endif /* LIBC_SCCS and not lint */
31 #include <sys/param.h>
32 #include <sys/socket.h>
33 #include <netinet/in.h>
34 #include <arpa/inet.h>
43 #include <rpcsvc/yp_prot.h>
44 #include <rpcsvc/ypclnt.h>
51 static char *host_aliases
[MAXALIASES
];
52 static char hostaddr
[MAXADDRS
];
53 static char *host_addrs
[2];
56 static struct hostent
*
57 _gethostbynis(const char *name
, char *map
, int af
)
60 register char *cp
, **q
;
63 static struct hostent h
;
64 static char *domain
= (char *)NULL
;
65 static char ypbuf
[YPMAXRECORD
+ 2];
76 if (domain
== (char *)NULL
)
77 if (yp_get_default_domain (&domain
))
78 return ((struct hostent
*)NULL
);
80 if (yp_match(domain
, map
, name
, strlen(name
), &result
, &resultlen
))
81 return ((struct hostent
*)NULL
);
83 /* avoid potential memory leak */
84 bcopy((char *)result
, (char *)&ypbuf
, resultlen
);
85 ypbuf
[resultlen
] = '\0';
87 result
= (char *)&ypbuf
;
89 if ((cp
= index(result
, '\n')))
92 cp
= strpbrk(result
, " \t");
94 h
.h_addr_list
= host_addrs
;
96 *((u_long
*)h
.h_addr
) = inet_addr(result
);
97 h
.h_length
= sizeof(u_long
);
98 h
.h_addrtype
= AF_INET
;
99 while (*cp
== ' ' || *cp
== '\t')
102 q
= h
.h_aliases
= host_aliases
;
103 cp
= strpbrk(cp
, " \t");
107 if (*cp
== ' ' || *cp
== '\t') {
111 if (q
< &host_aliases
[MAXALIASES
- 1])
113 cp
= strpbrk(cp
, " \t");
125 _gethostbynisname(const char *name
, int af
)
127 return _gethostbynis(name
, "hosts.byname", af
);
131 _gethostbynisaddr(const char *addr
, int len
, int af
)
133 return _gethostbynis(inet_ntoa(*(struct in_addr
*)addr
),"hosts.byaddr", af
);