Skip to content

Commit

Permalink
win32 convert, unfinished
Browse files Browse the repository at this point in the history
  • Loading branch information
proller committed Apr 10, 2014
1 parent 3d27904 commit 3586b8a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 38 deletions.
2 changes: 1 addition & 1 deletion unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ enet_address_set_host (ENetAddress * address, const char * name)
#endif

if (hostEntry == NULL ||
hostEntry -> h_addrtype != AF_INET6)
hostEntry -> h_addrtype != AF_INET)
{
#ifdef HAS_INET_PTON
if (! inet_pton (AF_INET6, name, & address -> host))
Expand Down
74 changes: 37 additions & 37 deletions win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,15 @@ enet_address_set_host (ENetAddress * address, const char * name)
return 0;
}

address -> host = * (enet_uint32 *) hostEntry -> h_addr_list [0];
address -> host = * hostEntry -> h_addr_list [0];

return 0;
}

int
enet_address_get_host_ip (const ENetAddress * address, char * name, size_t nameLength)
{
char * addr = inet_ntoa (* (struct in_addr *) & address -> host);
char * addr = inet_ntoa (* (struct in6_addr *) & address -> host);
if (addr == NULL)
return -1;
else
Expand All @@ -98,12 +98,12 @@ enet_address_get_host_ip (const ENetAddress * address, char * name, size_t nameL
int
enet_address_get_host (const ENetAddress * address, char * name, size_t nameLength)
{
struct in_addr in;
struct in6_addr in;
struct hostent * hostEntry;

in.s_addr = address -> host;

hostEntry = gethostbyaddr ((char *) & in, sizeof (struct in_addr), AF_INET);
hostEntry = gethostbyaddr ((char *) & in, sizeof (struct in6_addr), AF_INET6);
if (hostEntry == NULL)
return enet_address_get_host_ip (address, name, nameLength);
else
Expand All @@ -120,39 +120,39 @@ enet_address_get_host (const ENetAddress * address, char * name, size_t nameLeng
int
enet_socket_bind (ENetSocket socket, const ENetAddress * address)
{
struct sockaddr_in sin;
struct sockaddr_in6 sin;

memset (& sin, 0, sizeof (struct sockaddr_in));
memset (& sin, 0, sizeof (struct sockaddr_in6));

sin.sin_family = AF_INET;
sin.sin6_family = AF_INET6;

if (address != NULL)
{
sin.sin_port = ENET_HOST_TO_NET_16 (address -> port);
sin.sin_addr.s_addr = address -> host;
sin.sin6_port = ENET_HOST_TO_NET_16 (address -> port);
sin.sin6_addr = address -> host;
}
else
{
sin.sin_port = 0;
sin.sin_addr.s_addr = INADDR_ANY;
sin.sin6_port = 0;
sin.sin6_addr = in6addr_any;
}

return bind (socket,
(struct sockaddr *) & sin,
sizeof (struct sockaddr_in)) == SOCKET_ERROR ? -1 : 0;
sizeof (struct sockaddr_in6)) == SOCKET_ERROR ? -1 : 0;
}

int
enet_socket_get_address (ENetSocket socket, ENetAddress * address)
{
struct sockaddr_in sin;
int sinLength = sizeof (struct sockaddr_in);
struct sockaddr_in6 sin;
int sinLength = sizeof (struct sockaddr_in6);

if (getsockname (socket, (struct sockaddr *) & sin, & sinLength) == -1)
return -1;

address -> host = (enet_uint32) sin.sin_addr.s_addr;
address -> port = ENET_NET_TO_HOST_16 (sin.sin_port);
address -> host = sin.sin6_addr;
address -> port = ENET_NET_TO_HOST_16 (sin.sin6_port);

return 0;
}
Expand All @@ -166,7 +166,7 @@ enet_socket_listen (ENetSocket socket, int backlog)
ENetSocket
enet_socket_create (ENetSocketType type)
{
return socket (PF_INET, type == ENET_SOCKET_TYPE_DATAGRAM ? SOCK_DGRAM : SOCK_STREAM, 0);
return socket (PF_INET6, type == ENET_SOCKET_TYPE_DATAGRAM ? SOCK_DGRAM : SOCK_STREAM, 0);
}

int
Expand Down Expand Up @@ -236,16 +236,16 @@ enet_socket_get_option (ENetSocket socket, ENetSocketOption option, int * value)
int
enet_socket_connect (ENetSocket socket, const ENetAddress * address)
{
struct sockaddr_in sin;
struct sockaddr_in6 sin;
int result;

memset (& sin, 0, sizeof (struct sockaddr_in));
memset (& sin, 0, sizeof (struct sockaddr_in6));

sin.sin_family = AF_INET;
sin.sin_port = ENET_HOST_TO_NET_16 (address -> port);
sin.sin_addr.s_addr = address -> host;
sin.sin6_family = AF_INET6;
sin.sin6_port = ENET_HOST_TO_NET_16 (address -> port);
sin.sin6_addr = address -> host;

result = connect (socket, (struct sockaddr *) & sin, sizeof (struct sockaddr_in));
result = connect (socket, (struct sockaddr *) & sin, sizeof (struct sockaddr_in6));
if (result == SOCKET_ERROR && WSAGetLastError () != WSAEWOULDBLOCK)
return -1;

Expand All @@ -256,8 +256,8 @@ ENetSocket
enet_socket_accept (ENetSocket socket, ENetAddress * address)
{
SOCKET result;
struct sockaddr_in sin;
int sinLength = sizeof (struct sockaddr_in);
struct sockaddr_in6 sin;
int sinLength = sizeof (struct sockaddr_in6);

result = accept (socket,
address != NULL ? (struct sockaddr *) & sin : NULL,
Expand All @@ -268,8 +268,8 @@ enet_socket_accept (ENetSocket socket, ENetAddress * address)

if (address != NULL)
{
address -> host = (enet_uint32) sin.sin_addr.s_addr;
address -> port = ENET_NET_TO_HOST_16 (sin.sin_port);
address -> host = sin.sin6_addr;
address -> port = ENET_NET_TO_HOST_16 (sin.sin6_port);
}

return result;
Expand All @@ -294,16 +294,16 @@ enet_socket_send (ENetSocket socket,
const ENetBuffer * buffers,
size_t bufferCount)
{
struct sockaddr_in sin;
struct sockaddr_in6 sin;
DWORD sentLength;

if (address != NULL)
{
memset (& sin, 0, sizeof (struct sockaddr_in));
memset (& sin, 0, sizeof (struct sockaddr_in6));

sin.sin_family = AF_INET;
sin.sin_port = ENET_HOST_TO_NET_16 (address -> port);
sin.sin_addr.s_addr = address -> host;
sin.sin6_family = AF_INET6;
sin.sin6_port = ENET_HOST_TO_NET_16 (address -> port);
sin.sin6_addr = address -> host;
}

if (WSASendTo (socket,
Expand All @@ -312,7 +312,7 @@ enet_socket_send (ENetSocket socket,
& sentLength,
0,
address != NULL ? (struct sockaddr *) & sin : NULL,
address != NULL ? sizeof (struct sockaddr_in) : 0,
address != NULL ? sizeof (struct sockaddr_in6) : 0,
NULL,
NULL) == SOCKET_ERROR)
{
Expand All @@ -331,10 +331,10 @@ enet_socket_receive (ENetSocket socket,
ENetBuffer * buffers,
size_t bufferCount)
{
INT sinLength = sizeof (struct sockaddr_in);
INT sinLength = sizeof (struct sockaddr_in6);
DWORD flags = 0,
recvLength;
struct sockaddr_in sin;
struct sockaddr_in6 sin;

if (WSARecvFrom (socket,
(LPWSABUF) buffers,
Expand All @@ -361,8 +361,8 @@ enet_socket_receive (ENetSocket socket,

if (address != NULL)
{
address -> host = (enet_uint32) sin.sin_addr.s_addr;
address -> port = ENET_NET_TO_HOST_16 (sin.sin_port);
address -> host = sin.sin6_addr;
address -> port = ENET_NET_TO_HOST_16 (sin.sin6_port);
}

return (int) recvLength;
Expand Down

0 comments on commit 3586b8a

Please sign in to comment.