summaryrefslogtreecommitdiff
path: root/network.h
blob: 2279264323082fa787ddbcd198d0a90951c556ff (plain)
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
#ifndef NETWORK_H
#define NETWORK_H

#include <arpa/inet.h>
#include <errno.h>
#include <netdb.h>
#include <netinet/in.h>
#include <stdint.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/un.h>

typedef struct packet packet;
typedef struct cmd cmd;
typedef struct cmd_header cmd_header;

struct cmd_header {
	uint32_t size;		/* Size of command, in bytes, including command header. */
	uint16_t magic;		/* Magic Number. Must always be 0x1488. */
	uint16_t id;		/* Command ID. */
};

struct cmd {
	cmd_header header;	/* Command Header. */
	uint8_t data[];		/* Command data. */
};

struct packet {
	uint32_t size;		/* Size of packet, in bytes. */
	cmd cmd;		/* Command. */
};

extern const char *addr_to_str(struct sockaddr *sa, socklen_t len);
extern struct sockaddr *get_sock_addr(int socket);
extern int create_socket(struct sockaddr *sa, size_t sock_len);

#endif