Commit 737f42f2 authored by Libretro-Admin's avatar Libretro-Admin
Browse files

More updates for MSVC 2010 + reduce complexity of net_compat.c

libretro-common
parent c8509922
......@@ -24,60 +24,63 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "net_udp.h"
net_driver_t net_drivers[] = {
{
.name = "Loopback",
.initialized = false,
.Init = Loop_Init,
.Listen = Loop_Listen,
.SearchForHosts = Loop_SearchForHosts,
.Connect = Loop_Connect,
.CheckNewConnections = Loop_CheckNewConnections,
.QGetMessage = Loop_GetMessage,
.QSendMessage = Loop_SendMessage,
.SendUnreliableMessage = Loop_SendUnreliableMessage,
.CanSendMessage = Loop_CanSendMessage,
.CanSendUnreliableMessage = Loop_CanSendUnreliableMessage,
.Close = Loop_Close,
.Shutdown = Loop_Shutdown
}, {
.name = "Datagram",
.initialized = false,
.Init = Datagram_Init,
.Listen = Datagram_Listen,
.SearchForHosts = Datagram_SearchForHosts,
.Connect = Datagram_Connect,
.CheckNewConnections = Datagram_CheckNewConnections,
.QGetMessage = Datagram_GetMessage,
.QSendMessage = Datagram_SendMessage,
.SendUnreliableMessage = Datagram_SendUnreliableMessage,
.CanSendMessage = Datagram_CanSendMessage,
.CanSendUnreliableMessage = Datagram_CanSendUnreliableMessage,
.Close = Datagram_Close,
.Shutdown = Datagram_Shutdown
}
{
"Loopback", /* name */
false, /* initialized */
Loop_Init, /* Init */
Loop_Listen, /* Listen */
Loop_SearchForHosts, /* SearchForHosts */
Loop_Connect, /* Connect */
Loop_CheckNewConnections, /* CheckNewConnections */
Loop_GetMessage, /* QGetMessage */
Loop_SendMessage, /* QSendMessage */
Loop_SendUnreliableMessage, /* SendUnreliableMessage */
Loop_CanSendMessage, /* CanSendMessage */
Loop_CanSendUnreliableMessage, /* CanSendUnreliableMessage */
Loop_Close, /* Close */
Loop_Shutdown, /* Shutdown */
0 /* controlSock */
},
{
"Datagram", /* name */
false, /* initialized */
Datagram_Init, /* Init */
Datagram_Listen, /* Listen */
Datagram_SearchForHosts, /* SearchForHosts */
Datagram_Connect, /* Connect */
Datagram_CheckNewConnections, /* CheckNewConnections */
Datagram_GetMessage, /* QGetMessage */
Datagram_SendMessage, /* QSendMessage */
Datagram_SendUnreliableMessage, /* SendUnreliableMessage */
Datagram_CanSendMessage, /* CanSendMessage */
Datagram_CanSendUnreliableMessage, /* CanSendUnreliableMessage */
Datagram_Close, /* Close */
Datagram_Shutdown, /* Shutdown */
0 /* controlSock */
}
};
int net_numdrivers = 2;
net_landriver_t net_landrivers[] = {
{
.name = "UDP",
.initialized = false,
.controlSock = 0,
.Init = UDP_Init,
.Shutdown = UDP_Shutdown,
.Listen = UDP_Listen,
.OpenSocket = UDP_OpenSocket,
.CloseSocket = UDP_CloseSocket,
.CheckNewConnections = UDP_CheckNewConnections,
.Read = UDP_Read,
.Write = UDP_Write,
.Broadcast = UDP_Broadcast,
.GetSocketAddr = UDP_GetSocketAddr,
.GetNameFromAddr = UDP_GetNameFromAddr,
.GetAddrFromName = UDP_GetAddrFromName,
.GetDefaultMTU = UDP_GetDefaultMTU
}
{
"UDP", /* name */
false, /* initialized */
0, /* controlSock */
UDP_Init, /* Init */
UDP_Shutdown, /* Shutdown */
UDP_Listen, /* Listen */
UDP_OpenSocket, /* OpenSocket */
UDP_CloseSocket, /* CloseSocket */
UDP_CheckNewConnections, /* CheckNewConnections */
UDP_Read, /* Read */
UDP_Write, /* Write */
UDP_Broadcast, /* Broadcast */
UDP_GetSocketAddr, /* GetSocketAddr */
UDP_GetNameFromAddr, /* GetNameFromAddr */
UDP_GetAddrFromName, /* GetAddrFromName */
UDP_GetDefaultMTU /* GetDefaultMTU */
}
};
int net_numlandrivers = 1;
......@@ -25,9 +25,9 @@ extern int m_state;
#include <windows.h>
#else
#include <sys/types.h>
#endif
#include <net/net_compat.h>
#include <net/net_socket.h>
#endif
#include "cmd.h"
#include "console.h"
......@@ -69,55 +69,59 @@ StrAddr(netadr_t *addr)
}
#endif
static netadr_t banAddr = { .ip.l = INADDR_ANY };
static netadr_t banMask = { .ip.l = INADDR_NONE };
static netadr_t banAddr = { INADDR_ANY, 0, 0 };
static netadr_t banMask = { INADDR_NONE, 0, 0 };
static void
NET_Ban_f(void)
{
char addrStr[32];
char maskStr[32];
void (*print)(const char *fmt, ...) __attribute__((format(printf,1,2)));
if (cmd_source == src_command) {
if (!sv.active) {
Cmd_ForwardToServer();
return;
}
print = Con_Printf;
} else {
if (pr_global_struct->deathmatch)
return;
print = SV_ClientPrintf;
}
switch (Cmd_Argc()) {
case 1:
if (banAddr.ip.l != INADDR_ANY) {
strcpy(addrStr, NET_AdrToString(&banAddr));
strcpy(maskStr, NET_AdrToString(&banMask));
print("Banning %s [%s]\n", addrStr, maskStr);
} else
print("Banning not active\n");
break;
case 2:
if (strcasecmp(Cmd_Argv(1), "off") == 0)
banAddr.ip.l = INADDR_ANY;
else
banAddr.ip.l = inet_addr(Cmd_Argv(1));
banMask.ip.l = INADDR_NONE;
break;
case 3:
banAddr.ip.l = inet_addr(Cmd_Argv(1));
banMask.ip.l = inet_addr(Cmd_Argv(2));
break;
default:
print("BAN ip_address [mask]\n");
break;
}
char addrStr[32];
char maskStr[32];
void (*print)(const char *fmt, ...);
if (cmd_source == src_command) {
if (!sv.active) {
Cmd_ForwardToServer();
return;
}
print = Con_Printf;
}
else
{
if (pr_global_struct->deathmatch)
return;
print = SV_ClientPrintf;
}
switch (Cmd_Argc())
{
case 1:
if (banAddr.ip.l != INADDR_ANY)
{
strcpy(addrStr, NET_AdrToString(&banAddr));
strcpy(maskStr, NET_AdrToString(&banMask));
print("Banning %s [%s]\n", addrStr, maskStr);
} else
print("Banning not active\n");
break;
case 2:
if (strcasecmp(Cmd_Argv(1), "off") == 0)
banAddr.ip.l = INADDR_ANY;
else
banAddr.ip.l = inet_addr(Cmd_Argv(1));
banMask.ip.l = INADDR_NONE;
break;
case 3:
banAddr.ip.l = inet_addr(Cmd_Argv(1));
banMask.ip.l = inet_addr(Cmd_Argv(2));
break;
default:
print("BAN ip_address [mask]\n");
break;
}
}
static int
......@@ -420,12 +424,13 @@ NET_Stats_f(void)
}
struct test_poll_state {
qboolean inProgress;
int pollCount;
int socket;
net_landriver_t *driver;
PollProcedure *procedure;
struct test_poll_state
{
qboolean inProgress;
int pollCount;
int socket;
net_landriver_t *driver;
PollProcedure *procedure;
};
......@@ -493,18 +498,20 @@ Test_f(void)
netadr_t sendaddr;
net_landriver_t *driver = NULL;
static struct test_poll_state state = {
.inProgress = false,
.pollCount = 0,
.socket = 0,
.driver = NULL,
.procedure = NULL
static struct test_poll_state state =
{
false,
0,
0,
NULL,
NULL
};
static PollProcedure poll_procedure = {
.next = NULL,
.nextTime = 0.0,
.procedure = Test_Poll,
.arg = &state
static PollProcedure poll_procedure =
{
NULL,
0.0,
Test_Poll,
&state
};
if (state.inProgress)
......@@ -623,72 +630,73 @@ Test2_Poll(struct test_poll_state *state)
static void
Test2_f(void)
{
const char *host;
int i, n;
netadr_t sendaddr;
static struct test_poll_state state = {
.inProgress = false,
.pollCount = 0,
.socket = 0,
.driver = NULL,
.procedure = NULL
};
static PollProcedure poll_procedure = {
.next = NULL,
.nextTime = 0.0,
.procedure = Test2_Poll,
.arg = &state
};
if (state.inProgress)
return;
host = Cmd_Argv(1);
if (host && hostCacheCount) {
for (n = 0; n < hostCacheCount; n++)
if (strcasecmp(host, hostcache[n].name) == 0) {
if (hostcache[n].driver != dgrm_driver)
continue;
state.driver = hostcache[n].ldriver;
sendaddr = hostcache[n].addr;
break;
}
if (state.driver)
goto JustDoIt;
}
for (i = 0; i < net_numlandrivers; i++) {
if (!net_landrivers[i].initialized)
continue;
// see if we can resolve the host name
if (net_landrivers[i].GetAddrFromName(host, &sendaddr) != -1) {
state.driver = &net_landrivers[i];
break;
}
}
if (!state.driver)
return;
JustDoIt:
state.socket = state.driver->OpenSocket(0);
if (state.socket == -1)
return;
state.inProgress = true;
state.procedure = &poll_procedure;
SZ_Clear(&net_message);
// save space for the header, filled in later
MSG_WriteLong(&net_message, 0);
MSG_WriteByte(&net_message, CCREQ_RULE_INFO);
MSG_WriteString(&net_message, "");
MSG_WriteControlHeader(&net_message);
state.driver->Write(state.socket, net_message.data, net_message.cursize,
&sendaddr);
SZ_Clear(&net_message);
SchedulePollProcedure(&poll_procedure, 0.05);
const char *host;
int i, n;
netadr_t sendaddr;
static struct test_poll_state state = {
false,
0,
0,
NULL,
NULL
};
static PollProcedure poll_procedure =
{
NULL,
0.0,
Test2_Poll,
&state
};
if (state.inProgress)
return;
host = Cmd_Argv(1);
if (host && hostCacheCount) {
for (n = 0; n < hostCacheCount; n++)
if (strcasecmp(host, hostcache[n].name) == 0) {
if (hostcache[n].driver != dgrm_driver)
continue;
state.driver = hostcache[n].ldriver;
sendaddr = hostcache[n].addr;
break;
}
if (state.driver)
goto JustDoIt;
}
for (i = 0; i < net_numlandrivers; i++) {
if (!net_landrivers[i].initialized)
continue;
// see if we can resolve the host name
if (net_landrivers[i].GetAddrFromName(host, &sendaddr) != -1) {
state.driver = &net_landrivers[i];
break;
}
}
if (!state.driver)
return;
JustDoIt:
state.socket = state.driver->OpenSocket(0);
if (state.socket == -1)
return;
state.inProgress = true;
state.procedure = &poll_procedure;
SZ_Clear(&net_message);
// save space for the header, filled in later
MSG_WriteLong(&net_message, 0);
MSG_WriteByte(&net_message, CCREQ_RULE_INFO);
MSG_WriteString(&net_message, "");
MSG_WriteControlHeader(&net_message);
state.driver->Write(state.socket, net_message.data, net_message.cursize,
&sendaddr);
SZ_Clear(&net_message);
SchedulePollProcedure(&poll_procedure, 0.05);
}
......
......@@ -149,12 +149,16 @@ int retro_epoll_fd;
#define SOC_ALIGN 0x1000
#define SOC_BUFFERSIZE 0x100000
static u32* _net_compat_net_memory;
#elif defined(_WIN32)
#endif
#if defined(_WIN32)
int inet_aton(const char *cp, struct in_addr *inp)
{
uint32_t addr = 0;
#ifndef _XBOX
if (cp == 0 || inp == 0)
return -1;
#endif
addr = inet_addr(cp);
if (addr == INADDR_NONE || addr == INADDR_ANY)
......@@ -387,13 +391,6 @@ uint16_t inet_htons(uint16_t hostshort)
#endif
}
#ifdef _XBOX
static int inet_aton(const char *cp, struct in_addr *addr)
{
addr->s_addr = inet_addr(cp);
return (addr->s_addr == INADDR_NONE) ? 0 : 1;
}
#endif
int inet_ptrton(int af, const char *src, void *dst)
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment