[compiler-rt] r299862 - [msan] Make test to fall-back to IPv6 if IPv4 is not available.
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 10 10:59:07 PDT 2017
Author: vitalybuka
Date: Mon Apr 10 12:59:07 2017
New Revision: 299862
URL: http://llvm.org/viewvc/llvm-project?rev=299862&view=rev
Log:
[msan] Make test to fall-back to IPv6 if IPv4 is not available.
Reviewers: eugenis
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D31896
Modified:
compiler-rt/trunk/test/msan/Linux/sendmsg.cc
Modified: compiler-rt/trunk/test/msan/Linux/sendmsg.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/msan/Linux/sendmsg.cc?rev=299862&r1=299861&r2=299862&view=diff
==============================================================================
--- compiler-rt/trunk/test/msan/Linux/sendmsg.cc (original)
+++ compiler-rt/trunk/test/msan/Linux/sendmsg.cc Mon Apr 10 12:59:07 2017
@@ -33,17 +33,31 @@ int main() {
char buf[kBufSize] = {0};
pthread_t client_thread;
struct sockaddr_in serveraddr;
-
- sockfd = socket(AF_INET, SOCK_DGRAM, 0);
+ struct sockaddr_in6 serveraddr6;
memset(&serveraddr, 0, sizeof(serveraddr));
serveraddr.sin_family = AF_INET;
serveraddr.sin_addr.s_addr = htonl(INADDR_ANY);
serveraddr.sin_port = 0;
-
- bind(sockfd, (struct sockaddr *)&serveraddr, sizeof(serveraddr));
+ struct sockaddr *addr = (struct sockaddr *)&serveraddr;
socklen_t addrlen = sizeof(serveraddr);
- getsockname(sockfd, (struct sockaddr *)&serveraddr, &addrlen);
+
+ sockfd = socket(addr->sa_family, SOCK_DGRAM, 0);
+ if (sockfd <= 0) {
+ // Try to fall-back to IPv6
+ memset(&serveraddr6, 0, sizeof(serveraddr6));
+ serveraddr6.sin6_family = AF_INET6;
+ serveraddr6.sin6_addr = in6addr_any;
+ serveraddr6.sin6_port = 0;
+ addr = (struct sockaddr *)&serveraddr6;
+ addrlen = sizeof(serveraddr6);
+
+ sockfd = socket(addr->sa_family, SOCK_DGRAM, 0);
+ }
+ assert(sockfd > 0);
+
+ bind(sockfd, addr, addrlen);
+ getsockname(sockfd, addr, &addrlen);
#if defined(POISON)
__msan_poison(buf + 7, 1);
@@ -52,7 +66,7 @@ int main() {
#if defined(SENDMSG)
struct iovec iov[2] = {{buf, 5}, {buf + 5, 5}};
struct msghdr msg;
- msg.msg_name = &serveraddr;
+ msg.msg_name = addr;
msg.msg_namelen = addrlen;
msg.msg_iov = iov;
msg.msg_iovlen = 2;
@@ -62,14 +76,13 @@ int main() {
#endif
#if defined(SEND)
- ret = connect(sockfd, (struct sockaddr *)&serveraddr, addrlen);
+ ret = connect(sockfd, addr, addrlen);
assert(ret == 0);
ret = send(sockfd, buf, kBufSize, 0);
// SEND: Uninitialized bytes in __interceptor_send at offset 7 inside [{{.*}}, 10)
assert(ret > 0);
#elif defined(SENDTO)
- ret =
- sendto(sockfd, buf, kBufSize, 0, (struct sockaddr *)&serveraddr, addrlen);
+ ret = sendto(sockfd, buf, kBufSize, 0, addr, addrlen);
// SENDTO: Uninitialized bytes in __interceptor_sendto at offset 7 inside [{{.*}}, 10)
assert(ret > 0);
#elif defined(SENDMSG)
More information about the llvm-commits
mailing list