first commit

This commit is contained in:
Jose Caban
2025-06-07 01:59:34 -04:00
commit 388ac241f0
3558 changed files with 9116289 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
#include "include/networking.h"
#include "include/defs.h"
//C89 stuff
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//Networking Stuff
#ifdef _WIN32
#include <winsock.h>
#else
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#endif
int createTCPSocket(char *ipaddr, unsigned short server_port)
{
int sock; /* Socket descriptor */
struct sockaddr_in ServAddr; /* Address Structure */
#ifdef _WIN32
WSADATA wsaData; /* Winsock struct. */
if (WSAStartup(MAKEWORD(2, 0), &wsaData) != 0)/* Winsock 2.0 DLL. */
DieWithError("WSAStartup() failed");
#endif
if((sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
DieWithError("socket() failed");
memset(&ServAddr, 0, sizeof(ServAddr));
ServAddr.sin_family = AF_INET;
ServAddr.sin_addr.s_addr = inet_addr(ipaddr);
ServAddr.sin_port = htons(server_port);
if (connect(sock, (struct sockaddr *) &ServAddr, sizeof(ServAddr)) < 0) {
return -1;
} else {
return sock;
}
}