]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - StdLib/BsdSocketLib/map_v4v6.c
MdeModulePkg CapsuleApp: Index need be decimal for -P GET option
[mirror_edk2.git] / StdLib / BsdSocketLib / map_v4v6.c
... / ...
CommitLineData
1/*\r
2 * ++Copyright++ 1985, 1988, 1993\r
3 * -\r
4 * Copyright (c) 1985, 1988, 1993\r
5 * The Regents of the University of California. All rights reserved.\r
6 *\r
7 * Portions copyright (c) 1999, 2000\r
8 * Intel Corporation.\r
9 * All rights reserved.\r
10 * \r
11 * Redistribution and use in source and binary forms, with or without\r
12 * modification, are permitted provided that the following conditions\r
13 * are met:\r
14 * \r
15 * 1. Redistributions of source code must retain the above copyright\r
16 * notice, this list of conditions and the following disclaimer.\r
17 * \r
18 * 2. Redistributions in binary form must reproduce the above copyright\r
19 * notice, this list of conditions and the following disclaimer in the\r
20 * documentation and/or other materials provided with the distribution.\r
21 * \r
22 * 3. All advertising materials mentioning features or use of this software\r
23 * must display the following acknowledgement:\r
24 * \r
25 * This product includes software developed by the University of\r
26 * California, Berkeley, Intel Corporation, and its contributors.\r
27 * \r
28 * 4. Neither the name of University, Intel Corporation, or their respective\r
29 * contributors may be used to endorse or promote products derived from\r
30 * this software without specific prior written permission.\r
31 * \r
32 * THIS SOFTWARE IS PROVIDED BY THE REGENTS, INTEL CORPORATION AND\r
33 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,\r
34 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
35 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS,\r
36 * INTEL CORPORATION OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
37 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
38 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
39 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
40 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
41 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\r
42 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
43 * -\r
44 * Portions Copyright (c) 1993 by Digital Equipment Corporation.\r
45 * \r
46 * Permission to use, copy, modify, and distribute this software for any\r
47 * purpose with or without fee is hereby granted, provided that the above\r
48 * copyright notice and this permission notice appear in all copies, and that\r
49 * the name of Digital Equipment Corporation not be used in advertising or\r
50 * publicity pertaining to distribution of the document or software without\r
51 * specific, written prior permission.\r
52 * \r
53 * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL\r
54 * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES\r
55 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT\r
56 * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL\r
57 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR\r
58 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS\r
59 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS\r
60 * SOFTWARE.\r
61 * -\r
62 * --Copyright--\r
63 */\r
64\r
65#if defined(LIBC_SCCS) && !defined(lint)\r
66static char sccsid[] = "@(#)gethostnamadr.c 8.1 (Berkeley) 6/4/93";\r
67static char rcsid[] = "$Id: map_v4v6.c,v 1.1.1.1 2003/11/19 01:51:31 kyu3 Exp $";\r
68#endif /* LIBC_SCCS and not lint */\r
69\r
70#include <sys/types.h>\r
71#include <sys/param.h>\r
72#include <sys/socket.h>\r
73#include <netinet/in.h>\r
74#include <arpa/inet.h>\r
75#include <arpa/nameser.h>\r
76\r
77#include <stdio.h>\r
78#include <string.h>\r
79#include <netdb.h>\r
80#include <resolv.h>\r
81#include <ctype.h>\r
82#include <errno.h>\r
83#ifdef _ORG_FREEBSD_\r
84#include <syslog.h>\r
85#endif\r
86#include "Socklib_internals.h"\r
87\r
88typedef union {\r
89 int32_t al;\r
90 char ac;\r
91} align;\r
92\r
93void\r
94_map_v4v6_address(const char *src, char *dst)\r
95{\r
96 u_char *p = (u_char *)dst;\r
97 char tmp[INADDRSZ];\r
98 int i;\r
99\r
100 /* Stash a temporary copy so our caller can update in place. */\r
101 bcopy(src, tmp, INADDRSZ);\r
102 /* Mark this ipv6 addr as a mapped ipv4. */\r
103 for (i = 0; i < 10; i++)\r
104 *p++ = 0x00;\r
105 *p++ = 0xff;\r
106 *p++ = 0xff;\r
107 /* Retrieve the saved copy and we're done. */\r
108 bcopy(tmp, (void*)p, INADDRSZ);\r
109}\r
110\r
111void\r
112_map_v4v6_hostent(struct hostent *hp, char **bpp, int *lenp)\r
113{\r
114 char **ap;\r
115\r
116 if (hp->h_addrtype != AF_INET || hp->h_length != INADDRSZ)\r
117 return;\r
118 hp->h_addrtype = AF_INET6;\r
119 hp->h_length = IN6ADDRSZ;\r
120 for (ap = hp->h_addr_list; *ap; ap++) {\r
121 int i = (int)(sizeof(align) - ((size_t)*bpp % sizeof(align)));\r
122\r
123 if (*lenp < (i + IN6ADDRSZ)) {\r
124 /* Out of memory. Truncate address list here. XXX */\r
125 *ap = NULL;\r
126 return;\r
127 }\r
128 *bpp += i;\r
129 *lenp -= i;\r
130 _map_v4v6_address(*ap, *bpp);\r
131 *ap = *bpp;\r
132 *bpp += IN6ADDRSZ;\r
133 *lenp -= IN6ADDRSZ;\r
134 }\r
135}\r