In the original code, this fixes the issue:
int inetPtonReturnValue { inet_pton(AF_INET, IPAddress.c_str(), &structSockAddr.sa_data[2]) };
The first 2 bytes of sa_data are for the port.