Skip to content
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

Parse sin6_scope_id from IPv6 hostname #28

Merged
merged 1 commit into from
May 7, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions include/enet.h
Original file line number Diff line number Diff line change
Expand Up @@ -5031,7 +5031,7 @@ extern "C" {
((uint8_t *)&out->s_addr)[3] = in->s6_addr[15];
}

int enet_in6addr_lookup_host(const char *name, bool nodns, struct in6_addr *out) {
int enet_in6addr_lookup_host(const char *name, bool nodns, ENetAddress *out) {
struct addrinfo hints, *resultList = NULL, *result = NULL;

memset(&hints, 0, sizeof(hints));
Expand All @@ -5053,15 +5053,17 @@ extern "C" {
for (result = resultList; result != NULL; result = result->ai_next) {
if (result->ai_addr != NULL) {
if (result->ai_family == AF_INET || (result->ai_family == AF_UNSPEC && result->ai_addrlen == sizeof(struct sockaddr_in))) {
enet_inaddr_map4to6(((struct sockaddr_in*)result->ai_addr)->sin_addr, out);
enet_inaddr_map4to6(((struct sockaddr_in*)result->ai_addr)->sin_addr, &out->host);
out->sin6_scope_id = 0;

if (resultList != NULL) {
freeaddrinfo(resultList);
}

return 0;
} else if (result->ai_family == AF_INET6 || (result->ai_family == AF_UNSPEC && result->ai_addrlen == sizeof(struct sockaddr_in6))) {
memcpy(out, &((struct sockaddr_in6*)result->ai_addr)->sin6_addr, sizeof(struct in6_addr));
memcpy(&out->host, &((struct sockaddr_in6*)result->ai_addr)->sin6_addr, sizeof(struct in6_addr));
out->sin6_scope_id = (enet_uint16) ((struct sockaddr_in6*)result->ai_addr)->sin6_scope_id;

if (resultList != NULL) {
freeaddrinfo(resultList);
Expand All @@ -5080,11 +5082,11 @@ extern "C" {
}

int enet_address_set_host_ip_new(ENetAddress *address, const char *name) {
return enet_in6addr_lookup_host(name, true, &address->host);
return enet_in6addr_lookup_host(name, true, address);
}

int enet_address_set_host_new(ENetAddress *address, const char *name) {
return enet_in6addr_lookup_host(name, false, &address->host);
return enet_in6addr_lookup_host(name, false, address);
}

int enet_address_get_host_ip_new(const ENetAddress *address, char *name, size_t nameLength) {
Expand Down