Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 8566f4e

Browse files
clean
1 parent b2770e8 commit 8566f4e

File tree

2 files changed

+6
-80
lines changed

2 files changed

+6
-80
lines changed

src/Native/Unix/System.Native/pal_networking.c

Lines changed: 5 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,6 @@ enum
121121
#endif
122122
};
123123

124-
enum
125-
{
126-
HOST_ENTRY_HANDLE_ADDRINFO = 1,
127-
HOST_ENTRY_HANDLE_HOSTENT = 2,
128-
};
129-
130124
enum
131125
{
132126
INET6_ADDRSTRLEN_MANAGED = 65 // Managed code has a longer max IPv6 string length
@@ -237,8 +231,7 @@ int32_t SystemNative_GetHostEntryForName(const uint8_t* address, struct HostEntr
237231
entry->CanonicalName = NULL;
238232
entry->Aliases = NULL;
239233
entry->AddressListHandle = (void*)info;
240-
entry->IPAddressCount = 0;
241-
entry->HandleType = HOST_ENTRY_HANDLE_ADDRINFO;
234+
entry->IPAddressCount = 0;
242235

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

301-
static int32_t GetNextIPAddressFromHostEnt(struct hostent** hostEntry, struct IPAddress* address)
302-
{
303-
assert(hostEntry != NULL);
304-
assert(address != NULL);
305-
306-
struct hostent* entry = *hostEntry;
307-
if (*entry->h_addr_list == NULL)
308-
{
309-
return GetAddrInfoErrorFlags_EAI_NOMORE;
310-
}
311-
312-
switch (entry->h_addrtype)
313-
{
314-
case AF_INET:
315-
{
316-
struct in_addr* inAddr = (struct in_addr*)entry->h_addr_list[0];
317-
318-
ConvertInAddrToByteArray(address->Address, NUM_BYTES_IN_IPV4_ADDRESS, inAddr);
319-
address->IsIPv6 = 0;
320-
break;
321-
}
322-
323-
case AF_INET6:
324-
{
325-
struct in6_addr* in6Addr = (struct in6_addr*)entry->h_addr_list[0];
326-
327-
ConvertIn6AddrToByteArray(address->Address, NUM_BYTES_IN_IPV6_ADDRESS, in6Addr);
328-
address->IsIPv6 = 1;
329-
address->ScopeId = 0;
330-
break;
331-
}
332-
333-
default:
334-
return GetAddrInfoErrorFlags_EAI_NOMORE;
335-
}
336-
337-
entry->h_addr_list = &entry->h_addr_list[1];
338-
return GetAddrInfoErrorFlags_EAI_SUCCESS;
339-
}
340-
341294
int32_t SystemNative_GetNextIPAddress(const struct HostEntry* hostEntry, void** addressListHandle, struct IPAddress* endPoint)
342295
{
343296
if (hostEntry == NULL || addressListHandle == NULL || endPoint == NULL)
344297
{
345298
return GetAddrInfoErrorFlags_EAI_BADARG;
346299
}
347-
348-
switch (hostEntry->HandleType)
349-
{
350-
case HOST_ENTRY_HANDLE_ADDRINFO:
351-
return GetNextIPAddressFromAddrInfo((struct addrinfo**)addressListHandle, endPoint);
352-
353-
case HOST_ENTRY_HANDLE_HOSTENT:
354-
return GetNextIPAddressFromHostEnt((struct hostent**)addressListHandle, endPoint);
355-
356-
default:
357-
return GetAddrInfoErrorFlags_EAI_BADARG;
358-
}
300+
301+
return GetNextIPAddressFromAddrInfo((struct addrinfo**)addressListHandle, endPoint);
359302
}
360303

361304
void SystemNative_FreeHostEntry(struct HostEntry* entry)
362305
{
363306
if (entry != NULL)
364-
{
365-
switch (entry->HandleType)
366-
{
367-
case HOST_ENTRY_HANDLE_ADDRINFO:
368-
{
369-
struct addrinfo* ai = (struct addrinfo*)entry->AddressListHandle;
370-
freeaddrinfo(ai);
371-
break;
372-
}
373-
374-
case HOST_ENTRY_HANDLE_HOSTENT:
375-
{
376-
break;
377-
}
378-
379-
default:
380-
break;
381-
}
307+
{
308+
freeaddrinfo(entry->AddressListHandle);
382309
}
383310
}
384311

src/Native/Unix/System.Native/pal_networking.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,8 @@ struct HostEntry
239239
{
240240
uint8_t* CanonicalName; // Canonical name of the host
241241
uint8_t** Aliases; // List of aliases for the host
242-
void* AddressListHandle; // Handle for host socket addresses
242+
struct addrinfo* AddressListHandle; // Handle for host socket addresses
243243
int32_t IPAddressCount; // Number of IP end points in the list
244-
int32_t HandleType; // Indicates the type of the handle. Opaque to managed code.
245244
};
246245

247246
struct IPPacketInformation

0 commit comments

Comments
 (0)