-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Resolve winsock deprecation #16
Comments
For reference: http://man7.org/linux/man-pages/man3/gethostbyname.3.html OutpostUniverse/NetHelper@acb916a http://man7.org/linux/man-pages/man3/inet_addr.3p.html Edit: |
I was looking at this code. Both deprecated calls are in Both of these uses are supported by the new I propose the following as a candidate replacement function: sockaddr OPUNetTransportLayer::StringToAddress(const char* addressString) {
// Skip any leading spaces
while (addressString[0] == ' ' || addressString[0] == '\t')
addressString++;
// Break string into hostname and port components
const char* portNumString = strchr(addressString, ':');
// Advance past ":"
portNumString += portNumString != nullptr ? 1 : 0;
// Convert address to struct form
addrinfo hints = {0, AF_INET, SOCK_DGRAM, IPPROTO_UDP };
addrinfo* addressLinkedList;
auto errorCode = getaddrinfo(addressString, portNumString, &hints, &addressLinkedList);
if (errorCode) {
throw std::runtime_error(gai_strerror(errorCode));
}
if (addressLinkedList->ai_addr == nullptr) {
throw std::runtime_error("No candidate addresses");
}
// Simplification: Just return the first address in the list
auto address = *addressLinkedList->ai_addr;
freeaddrinfo(addressLinkedList);
return address;
} There are a couple of caveats though. One is the simplification used by this function, where it just returns the first found address. Another is that it copies the full struct to the output, whereas the old method passed in a struct, which then had specific fields initialized. Fields that were not set by the old method could be pre-initialized so they'd have known output values. This was used in one place to form a broadcast address used to search for games. Additionally, the type of address was changed to the more generic I'd like to see if there are a few step-wise refactorings I can do, so this isn't just one big huge mess when it lands. Edit: It seems |
…rCallPoint Move Variable declarations closer to point of call within functions where appropriate
Looks similar to deprecated functions in NetHelper/miniupnp we fixed earlier.
Warning C4996 'gethostbyname': Use getaddrinfo() or GetAddrInfoW() instead or define _WINSOCK_DEPRECATED_NO_WARNINGS to disable deprecated API warnings NetFixClient \netfixclient\opunettransportlayer.cpp 916
Warning C4996 'inet_addr': Use inet_pton() or InetPton() instead or define _WINSOCK_DEPRECATED_NO_WARNINGS to disable deprecated API warnings NetFixClient \netfixclient\opunettransportlayer.cpp 910
The text was updated successfully, but these errors were encountered: