Created
August 21, 2013 10:01
-
-
Save oskaritimperi/6292616 to your computer and use it in GitHub Desktop.
inet_pton() implementation for older windows versions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * Use as you wish | |
| */ | |
| static int my_inet_pton(int family, const char *src, void *dst) | |
| { | |
| int rc; | |
| struct sockaddr_storage addr; | |
| int addr_len; | |
| addr.ss_family = family; | |
| rc = WSAStringToAddressA((char *) src, family, NULL, (struct sockaddr *) &addr, &addr_len); | |
| if (rc != 0) | |
| { | |
| return -1; | |
| } | |
| if (family == AF_INET) | |
| { | |
| memcpy(dst, &((struct sockaddr_in *)&addr)->sin_addr, | |
| sizeof(struct in_addr)); | |
| } | |
| else if (family == AF_INET6) | |
| { | |
| memcpy(dst, &((struct sockaddr_in6 *)&addr)->sin6_addr, | |
| sizeof(struct in6_addr)); | |
| } | |
| return 1; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment