minor fix to host resolution
This commit is contained in:
parent
7c2f816852
commit
739f951fba
|
|
@ -22,6 +22,9 @@
|
|||
|
||||
#include "raylib.h"
|
||||
|
||||
char buffer[ADDRESS_IPV6_ADDRSTRLEN];
|
||||
uint16_t port = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
// Setup
|
||||
|
|
@ -36,7 +39,7 @@ int main()
|
|||
// Networking
|
||||
InitNetwork();
|
||||
|
||||
AddressInformation* addr = NULL;
|
||||
AddressInformation* addr = AllocAddressList(1);
|
||||
int count = ResolveHost(
|
||||
NULL,
|
||||
"5210",
|
||||
|
|
@ -49,9 +52,13 @@ int main()
|
|||
// ADDRESS_INFO_FQDN // e.g. ADDRESS_INFO_CANONNAME | ADDRESS_INFO_NUMERICSERV
|
||||
,
|
||||
addr
|
||||
);
|
||||
ResolveIP("8.8.8.8", NULL, NAME_INFO_DEFAULT, NULL, NULL);
|
||||
ResolveIP("2001:4860:4860::8888", "80", NAME_INFO_NUMERICSERV, NULL, NULL);
|
||||
);
|
||||
|
||||
if (count > 0)
|
||||
{
|
||||
GetAddressHostAndPort(addr[0], buffer, &port);
|
||||
TraceLog(LOG_INFO, "Resolved to ip %s::%d\n", buffer, port);
|
||||
}
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose())
|
||||
|
|
|
|||
|
|
@ -1533,9 +1533,11 @@ RLAPI void CloseNetwork(void);
|
|||
// Address API
|
||||
RLAPI void ResolveIP(const char *ip, const char *service, int flags, char *outhost, char *outserv);
|
||||
RLAPI int ResolveHost(const char *address, const char *service, int addressType, int flags, AddressInformation* outAddr);
|
||||
RLAPI int GetAddressFamily();
|
||||
RLAPI int GetAddressFamily(AddressInformation address);
|
||||
RLAPI int GetAddressSocketType(AddressInformation address);
|
||||
RLAPI int GetAddressProtocol(AddressInformation address);
|
||||
RLAPI char* GetAddressCanonName(AddressInformation address);
|
||||
RLAPI char *GetAddressHostAndPort(AddressInformation address, char *outhost, int *outport);
|
||||
RLAPI void PrintAddressInfo(AddressInformation address);
|
||||
RLAPI AddressInformation AllocAddress();
|
||||
RLAPI void FreeAddress(AddressInformation* addressInfo);
|
||||
|
|
|
|||
41
src/rnet.c
41
src/rnet.c
|
|
@ -708,7 +708,7 @@ int ResolveHost(const char *address, const char *service, int addressType, int f
|
|||
|
||||
// If not address list was allocated, allocate it dynamically with the known address size
|
||||
if (outAddr == NULL) {
|
||||
outAddr = AllocAddressList(size);
|
||||
outAddr = (AddressInformation *) malloc(size * sizeof(AddressInformation));
|
||||
}
|
||||
|
||||
// Dynamically allocate an array of address information structs
|
||||
|
|
@ -1562,6 +1562,12 @@ AddressInformation *AllocAddressList(int size)
|
|||
return addr;
|
||||
}
|
||||
|
||||
// Opaque datatype accessor addrinfo->ai_family
|
||||
int GetAddressFamily(AddressInformation address)
|
||||
{
|
||||
return address->addr.ai_family;
|
||||
}
|
||||
|
||||
// Opaque datatype accessor addrinfo->ai_socktype
|
||||
int GetAddressSocketType(AddressInformation address)
|
||||
{
|
||||
|
|
@ -1574,10 +1580,37 @@ int GetAddressProtocol(AddressInformation address)
|
|||
return address->addr.ai_protocol;
|
||||
}
|
||||
|
||||
// Opaque datatype accessor addrinfo->ai_family
|
||||
int GetAddressFamily(AddressInformation address)
|
||||
// Opaque datatype accessor addrinfo->ai_canonname
|
||||
char *GetAddressCanonName(AddressInformation address)
|
||||
{
|
||||
return address->addr.ai_family;
|
||||
return address->addr.ai_canonname;
|
||||
}
|
||||
|
||||
// Opaque datatype accessor addrinfo->ai_addr
|
||||
char *GetAddressHostAndPort(AddressInformation address, char *outhost, int *outport)
|
||||
{
|
||||
char * ip[INET6_ADDRSTRLEN];
|
||||
char * result = NULL;
|
||||
struct sockaddr_storage *storage = (struct sockaddr_storage *) address->addr.ai_addr;
|
||||
switch (storage->ss_family) {
|
||||
case AF_INET: {
|
||||
struct sockaddr_in *s = ((struct sockaddr_in *) address->addr.ai_addr);
|
||||
result = inet_ntop(AF_INET, &s->sin_addr, ip, INET_ADDRSTRLEN);
|
||||
*outport = ntohs(s->sin_port);
|
||||
} break;
|
||||
case AF_INET6: {
|
||||
struct sockaddr_in6 *s = ((struct sockaddr_in6 *) address->addr.ai_addr);
|
||||
result = inet_ntop(AF_INET6, &s->sin6_addr, ip, INET6_ADDRSTRLEN);
|
||||
*outport = ntohs(s->sin6_port);
|
||||
} break;
|
||||
}
|
||||
if (result == NULL) {
|
||||
TraceLog(LOG_WARNING, "Socket Error: %s", SocketErrorCodeToString(SocketGetLastError()));
|
||||
SocketSetLastError(0);
|
||||
} else {
|
||||
strcpy(outhost, result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user