You are using a struct sockaddr
when calling inet_pton
but the calling signature requires that this is either an struct in_addr
for AF_INET (or struct in6_addr
for IPv6). And then you'd have to use that in building a struct sockaddr
for the later function.
As it currently stands, you are writing some of the bytes for the address into fields before the field containing the actual IP address, so you end up with just the last 2 octets of the IP in your sockaddr field.