#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>
+#include <string.h>
#include <unistd.h>
#include <netdb.h>
#include <errno.h>
#ifndef socklen_t
#define socklen_t int
#endif
-#ifdef NETWORK
+
static int Socket=-1;
-#endif
#include "main.h"
#include "unix-netplay.h"
int FCEUD_NetworkConnect(void)
{
-#ifdef NETWORK
struct sockaddr_in sockn;
int TSocket;
if(bind(TSocket, (struct sockaddr *)&sockn, sizeof(sockn))<0)
{
close(TSocket);
- puts("Error binding to socket.");
+ puts("Error binding to socket.");
return(0);
}
if(listen(TSocket, 1)<0)
}
{
socklen_t len=sizeof(sockn);
-
+
printf("Accepting connection on port %d...\n",Port);
if((Socket=accept(TSocket,(struct sockaddr *)&sockn,&len))<0 )
{
return(0);
}
memcpy(&sockn.sin_addr,Host->h_addr,Host->h_length);
- }
+ }
printf("Attempting to connect to %s...\n",netplayhost);
if( connect(TSocket, (struct sockaddr *)&sockn, sizeof(sockn)) <0 )
{
}
Socket=TSocket;
}
-#endif
- return(1);
+ return(1);
}
/* 0 on failure, 1 on success, -1 if it would block and blocking is not
int FCEUD_NetworkRecvData(uint8 *data, uint32 len, int block)
{
-#ifdef NETWORK
if(block)
{
int t;
}
return(1);
}
-#else
- return 1;
-#endif
}
/* 0 on failure, 1 on success. This function should always block. */
int FCEUD_NetworkSendData(uint8 *Value, uint32 len)
{
-#ifdef NETWORK
return(send(Socket,Value,len,0)==len);
-#else
- return 0;
-#endif
}
void FCEUD_NetworkClose(void)
{
-#ifdef NETWORK
if(Socket>0)
close(Socket);
Socket=-1;
-#endif
}