/
bittwiddle.h
67 lines (49 loc) · 1.44 KB
/
bittwiddle.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
64
65
66
67
#ifndef _BITTWIDDLE_H
#define _BITTWIDDLE_H
#include <stdint.h>
#include <closure.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
typedef uint32_t word32;
///////// Packet data
typedef word32* PACKET;
PACKET newPacket(int length);
void dumpPacket(PACKET p, int length);
void setPacketByte(PACKET p, int b, int data);
void setPacketBits(PACKET p, int start, int end, int data);
void setPacketString(PACKET p, int start, char* string, int l, char t);
int getPacketByte(PACKET p, int b);
int getPacketBits(PACKET p, int start, int end);
//// Code for sending packets across a wire
// Anything waiting on a socket?
int isReadable(int sd, int timeOut);
typedef struct {
int sock;
struct sockaddr_in addr;
} Connection;
typedef struct {
VAL buf;
unsigned port;
char* server;
} Recv;
// Open sockets
void* net_UDP_serverSocket(int port);
void* net_UDP_clientSocket(char* server, int port);
void* net_TCP_socket(char* server, int port);
void* net_TCP_listen(int port, int maxcon);
void* net_TCP_accept(void* s_in);
void net_closeSocket(void* s);
int net_sendUDP(void* conn, char* server, int port, VAL stuff);
void* net_recvUDP(void* conn);
int net_sendTCP(void* conn, VAL stuff);
void* net_recvTCP(void* conn);
VAL get_recvPacket(void* recv);
char* get_recvServer(void* recv);
int get_recvPort(void* recv);
int nullPtr(void *ptr);
#endif