On Mon, Sep 14, 2020 at 3:23 PM Thomas Huth wrote: > > On 13/09/2020 00.44, Yonggang Luo wrote: > > Fixes following tests on msys2/mingw > > 'test-crypto-tlscredsx509': ['crypto-tls-x509-helpers.c', 'pkix_asn1_tab.c', > > tasn1, crypto], > > 'test-crypto-tlssession': ['crypto-tls-x509-helpers.c', 'pkix_asn1_tab.c', 'crypto-tls-psk-helpers.c', > > tasn1, crypto], > > 'test-io-channel-tls': ['io-channel-helpers.c', 'crypto-tls-x509-helpers.c', 'pkix_asn1_tab.c', > > tasn1, io, crypto]} > > These tests are failure with: > > ERROR test-crypto-tlscredsx509 - missing test plan > > ERROR test-crypto-tlssession - missing test plan > > ERROR test-io-channel-tls - missing test plan > > > > Because on win32 those test case are all disabled in the header > > > > Add qemu_socket_pair for cross platform support, convert file system > > handling functions to glib > > Add qemu_link function instead posix only link function. > > Use send ad recv from qemu that convert Windows Socks error > > to errno properly. > > > > Signed-off-by: Yonggang Luo > > --- > [...] > > +static int __stream_socketpair(struct addrinfo* addr_info, int sock[2]){ > > + SOCKET listener, client, server; > > + int opt = 1; > > + > > + listener = server = client = INVALID_SOCKET; > > + listener = socket(addr_info->ai_family, addr_info->ai_socktype, addr_info->ai_protocol); > > + if (INVALID_SOCKET == listener) > > + goto fail; > > + > > + setsockopt(listener, SOL_SOCKET, SO_REUSEADDR,(const char*)&opt, sizeof(opt)); > > + > > + if(SOCKET_ERROR == bind(listener, addr_info->ai_addr, addr_info->ai_addrlen)) > > + goto fail; > > + > > + if (SOCKET_ERROR == getsockname(listener, addr_info->ai_addr, (int*)&addr_info->ai_addrlen)) > > + goto fail; > > + > > + if(SOCKET_ERROR == listen(listener, 5)) > > + goto fail; > > + > > + client = socket(addr_info->ai_family, addr_info->ai_socktype, addr_info->ai_protocol); > > + > > + if (INVALID_SOCKET == client) > > + goto fail; > > + > > + if (SOCKET_ERROR == connect(client,addr_info->ai_addr,addr_info->ai_addrlen)) > > + goto fail; > > + > > + server = accept(listener, 0, 0); > > + > > + if (INVALID_SOCKET == server) > > + goto fail; > > + > > + closesocket(listener); > > + > > + sock[0] = client; > > + sock[1] = server; > > + > > + return 0; > > +fail: > > + if(INVALID_SOCKET!=listener) > > + closesocket(listener); > > + if (INVALID_SOCKET!=client) > > + closesocket(client); > > + return -1; > > +} > > + > > +static int __dgram_socketpair(struct addrinfo* addr_info, int sock[2]) > > +{ > > + SOCKET client, server; > > + struct addrinfo addr, *result = NULL; > > + const char* address; > > + int opt = 1; > > + > > + server = client = INVALID_SOCKET; > > + > > + server = socket(addr_info->ai_family, addr_info->ai_socktype, addr_info->ai_protocol); > > + if (INVALID_SOCKET == server) > > + goto fail; > > + > > + setsockopt(server, SOL_SOCKET,SO_REUSEADDR, (const char*)&opt, sizeof(opt)); > > + > > + if(SOCKET_ERROR == bind(server, addr_info->ai_addr, addr_info->ai_addrlen)) > > + goto fail; > > + > > + if (SOCKET_ERROR == getsockname(server, addr_info->ai_addr, (int*)&addr_info->ai_addrlen)) > > + goto fail; > > + > > + client = socket(addr_info->ai_family, addr_info->ai_socktype, addr_info->ai_protocol); > > + if (INVALID_SOCKET == client) > > + goto fail; > > + > > + memset(&addr,0,sizeof(addr)); > > + addr.ai_family = addr_info->ai_family; > > + addr.ai_socktype = addr_info->ai_socktype; > > + addr.ai_protocol = addr_info->ai_protocol; > > + > > + if (AF_INET6==addr.ai_family) > > + address = "0:0:0:0:0:0:0:1"; > > + else > > + address = "127.0.0.1"; > > + > > + if (getaddrinfo(address, "0", &addr, &result)) > > + goto fail; > > + > > + setsockopt(client,SOL_SOCKET,SO_REUSEADDR,(const char*)&opt, sizeof(opt)); > > + if(SOCKET_ERROR == bind(client, result->ai_addr, result->ai_addrlen)) > > + goto fail; > > + > > + if (SOCKET_ERROR == getsockname(client, result->ai_addr, (int*)&result->ai_addrlen)) > > + goto fail; > > + > > + if (SOCKET_ERROR == connect(server, result->ai_addr, result->ai_addrlen)) > > + goto fail; > > + > > + if (SOCKET_ERROR == connect(client, addr_info->ai_addr, addr_info->ai_addrlen)) > > + goto fail; > > + > > + freeaddrinfo(result); > > + sock[0] = client; > > + sock[1] = server; > > + return 0; > > + > > +fail: > > + if (INVALID_SOCKET!=client) > > + closesocket(client); > > + if (INVALID_SOCKET!=server) > > + closesocket(server); > > + if (result) > > + freeaddrinfo(result); > > + return -1; > > +} > > + > > +int qemu_socketpair(int family, int type, int protocol,int recv[2]){ > > + const char* address; > > + struct addrinfo addr_info,*p_addrinfo; > > + int result = -1; > > + > > + if (family == AF_UNIX) > > + { > > + family = AF_INET; > > + } > > + > > + memset(&addr_info, 0, sizeof(addr_info)); > > + addr_info.ai_family = family; > > + addr_info.ai_socktype = type; > > + addr_info.ai_protocol = protocol; > > + if (AF_INET6==family) > > + address = "0:0:0:0:0:0:0:1"; > > + else > > + address = "127.0.0.1"; > > + > > + if (0 == getaddrinfo(address, "0", &addr_info, &p_addrinfo)){ > > + if (SOCK_STREAM == type) > > + result = __stream_socketpair(p_addrinfo, recv); > > + else if(SOCK_DGRAM == type) > > + result = __dgram_socketpair(p_addrinfo, recv); > > + freeaddrinfo(p_addrinfo); > > + } > > + return result; > > +} > > Where do you've got this code from? It seems like this has been taken > from a 3rd party source? E.g.: > > https://blog.csdn.net/wufuhuai/article/details/79761889 > > What's the license of this new code? ... please clarify such details in The original code have no license information, neither copyleft nor copyright, what's your suggestion or rewrite it? > > the commit description. > > Thanks, > Thomas > -- 此致 礼 罗勇刚 Yours sincerely, Yonggang Luo