-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsocket.h
63 lines (53 loc) · 1.36 KB
/
socket.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#ifndef __SOCKET__H
#define __SOCKET__H
#define _GNU_SOURCE
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
#include <unistd.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include "logger.h"
typedef struct
{
struct sockaddr_in server_addr;
int server_sock;
int port;
char *ip;
}socket_t;
typedef struct SOCKET_SERVER
{
socket_t socketValues;
int(*Create)(void*);
int(*Listen)(void*,void(char*));
int(*Close)(void*);
int(*SendToClient)(int,char*,...);
}serverInit_t;
typedef struct SOCKET_CLIENT
{
socket_t socketValues;
int(*Create)(void*);
int(*SendToServer)(void*,char*,...);
}clientInit_t;
enum socketsReturns_t{
SOCKET_SUCCESS = 0,
SOCKET_SERVER_CREATE_ERROR = 9601,
SOCKET_CLIENT_CREATE_ERROR = 9602,
SOCKET_BIND_ERROR = 9603,
SOCKET_CONNECTION_ERROR = 9604
};
serverInit_t* NEW_SERVER_INIT(char* IP,int PORT);
clientInit_t* NEW_CLIENT_INIT(char* IP,int PORT);
/*
serverInit_t* localSocket = NEW_SERVER_INIT("localhost",5002);
localSocket->Create(localSocket);
localSocket->Listen(localSocket);
localSocket->Close(localSocket);
clientInit_t* localSocket2 = NEW_CLIENT_INIT("localhost",5002);
localSocket2->Create(localSocket2);
localSocket2->SendToServer(localSocket2,"Hello World %d",13232);
*/
#endif