2 * Copyright (C) 2013-2014 Red Hat, Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see
16 * <http://www.gnu.org/licenses/>.
25 #if defined(__linux__) && defined(RTLD_NEXT)
26 # include "internal.h"
27 # include <sys/socket.h>
28 # include <arpa/inet.h>
29 # include <netinet/in.h>
32 static bool host_has_ipv6
;
33 static int (*realsocket
)(int domain
, int type
, int protocol
);
35 static void init_syms(void)
42 realsocket
= dlsym(RTLD_NEXT
, "socket");
45 fprintf(stderr
, "Unable to find 'socket' symbol\n");
49 fd
= realsocket(AF_INET6
, SOCK_STREAM
, 0);
57 int socket(int domain
,
63 if (getenv("LIBVIRT_TEST_IPV4ONLY") && domain
== AF_INET6
) {
68 return realsocket(domain
, type
, protocol
);
71 int bind(int sockfd ATTRIBUTE_UNUSED
,
72 const struct sockaddr
*addr
,
73 socklen_t addrlen ATTRIBUTE_UNUSED
)
75 struct sockaddr_in saddr
;
77 memcpy(&saddr
, addr
, sizeof(saddr
));
79 if (host_has_ipv6
&& !getenv("LIBVIRT_TEST_IPV4ONLY")) {
80 if (saddr
.sin_port
== htons(5900) ||
81 (saddr
.sin_family
== AF_INET
&&
82 saddr
.sin_port
== htons(5904)) ||
83 (saddr
.sin_family
== AF_INET6
&&
84 (saddr
.sin_port
== htons(5905) ||
85 saddr
.sin_port
== htons(5906)))) {
92 if (saddr
.sin_port
== htons(5900) ||
93 saddr
.sin_port
== htons(5904) ||
94 saddr
.sin_port
== htons(5905) ||
95 saddr
.sin_port
== htons(5906)) {
103 #else /* defined(__linux__) && defined(RTLD_NEXT) */
104 /* Nothing to override on other platforms. */