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