when I try to connect to my server, my client fails during the function WSAStringToAddress with the error 10022, I think the problem is that I try to get the IPv6 address from a console argument. The format of the console argument is ::1 for my localhost address.
Here is the function that fails:
WSAStringToAddress((LPWSTR)argv[1], AF_INET6, NULL, (SOCKADDR *)&server, &len)
And here code for the server and len variables:
struct sockaddr_in6 server;
int len = sizeof(server);
memset( &server, 0, sizeof (server));
server.sin6_family = AF_INET6;
server.sin6_port = htons(PORT);
Yeah I hope someone sees the mistake I made.
Error 10022 is
WSAEINVAL, which means you passed an invalid parameter. The problem in this case is that when compiling a Unicode program,WSAStringToAddresstakes a wide-character string, and you’re passing it a narrow string cast to a wide string. The compiler error you were getting before you inserted the cast should have raised a red flag.You have a few options:
mainfunction to bewmaininstead, which takes wide-character argument stringsWSAStringToAddressAinstead ofWSAStringToAddressMultiByteToWideCharIn this particular case, I’d recommend explicitly using the
WSAStringToAddressAfunction, since using the wide-character version doesn’t afford any extra advantage for this function.