Skip to content

Commit

Permalink
clean
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoRossignoli committed Feb 16, 2018
1 parent b2770e8 commit 8566f4e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 80 deletions.
83 changes: 5 additions & 78 deletions src/Native/Unix/System.Native/pal_networking.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,6 @@ enum
#endif
};

enum
{
HOST_ENTRY_HANDLE_ADDRINFO = 1,
HOST_ENTRY_HANDLE_HOSTENT = 2,
};

enum
{
INET6_ADDRSTRLEN_MANAGED = 65 // Managed code has a longer max IPv6 string length
Expand Down Expand Up @@ -237,8 +231,7 @@ int32_t SystemNative_GetHostEntryForName(const uint8_t* address, struct HostEntr
entry->CanonicalName = NULL;
entry->Aliases = NULL;
entry->AddressListHandle = (void*)info;
entry->IPAddressCount = 0;
entry->HandleType = HOST_ENTRY_HANDLE_ADDRINFO;
entry->IPAddressCount = 0;

// Find the canonical name for this host (if any) and count the number of IP end points.
for (struct addrinfo* ai = info; ai != NULL; ai = ai->ai_next)
Expand Down Expand Up @@ -298,87 +291,21 @@ static int32_t GetNextIPAddressFromAddrInfo(struct addrinfo** info, struct IPAdd
return GetAddrInfoErrorFlags_EAI_NOMORE;
}

static int32_t GetNextIPAddressFromHostEnt(struct hostent** hostEntry, struct IPAddress* address)
{
assert(hostEntry != NULL);
assert(address != NULL);

struct hostent* entry = *hostEntry;
if (*entry->h_addr_list == NULL)
{
return GetAddrInfoErrorFlags_EAI_NOMORE;
}

switch (entry->h_addrtype)
{
case AF_INET:
{
struct in_addr* inAddr = (struct in_addr*)entry->h_addr_list[0];

ConvertInAddrToByteArray(address->Address, NUM_BYTES_IN_IPV4_ADDRESS, inAddr);
address->IsIPv6 = 0;
break;
}

case AF_INET6:
{
struct in6_addr* in6Addr = (struct in6_addr*)entry->h_addr_list[0];

ConvertIn6AddrToByteArray(address->Address, NUM_BYTES_IN_IPV6_ADDRESS, in6Addr);
address->IsIPv6 = 1;
address->ScopeId = 0;
break;
}

default:
return GetAddrInfoErrorFlags_EAI_NOMORE;
}

entry->h_addr_list = &entry->h_addr_list[1];
return GetAddrInfoErrorFlags_EAI_SUCCESS;
}

int32_t SystemNative_GetNextIPAddress(const struct HostEntry* hostEntry, void** addressListHandle, struct IPAddress* endPoint)
{
if (hostEntry == NULL || addressListHandle == NULL || endPoint == NULL)
{
return GetAddrInfoErrorFlags_EAI_BADARG;
}

switch (hostEntry->HandleType)
{
case HOST_ENTRY_HANDLE_ADDRINFO:
return GetNextIPAddressFromAddrInfo((struct addrinfo**)addressListHandle, endPoint);

case HOST_ENTRY_HANDLE_HOSTENT:
return GetNextIPAddressFromHostEnt((struct hostent**)addressListHandle, endPoint);

default:
return GetAddrInfoErrorFlags_EAI_BADARG;
}

return GetNextIPAddressFromAddrInfo((struct addrinfo**)addressListHandle, endPoint);
}

void SystemNative_FreeHostEntry(struct HostEntry* entry)
{
if (entry != NULL)
{
switch (entry->HandleType)
{
case HOST_ENTRY_HANDLE_ADDRINFO:
{
struct addrinfo* ai = (struct addrinfo*)entry->AddressListHandle;
freeaddrinfo(ai);
break;
}

case HOST_ENTRY_HANDLE_HOSTENT:
{
break;
}

default:
break;
}
{
freeaddrinfo(entry->AddressListHandle);
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/Native/Unix/System.Native/pal_networking.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,8 @@ struct HostEntry
{
uint8_t* CanonicalName; // Canonical name of the host
uint8_t** Aliases; // List of aliases for the host
void* AddressListHandle; // Handle for host socket addresses
struct addrinfo* AddressListHandle; // Handle for host socket addresses
int32_t IPAddressCount; // Number of IP end points in the list
int32_t HandleType; // Indicates the type of the handle. Opaque to managed code.
};

struct IPPacketInformation
Expand Down

0 comments on commit 8566f4e

Please sign in to comment.