-
Notifications
You must be signed in to change notification settings - Fork 389
/
sock.h
75 lines (60 loc) · 1.53 KB
/
sock.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
68
69
70
71
72
73
74
75
#ifndef SOCK_H
#define SOCK_H
#include <stddef.h>
#include <stdint.h>
#include "ip.h"
#define PF_UNSPEC 0
#define PF_LOCAL 1
#define PF_INET 2
#define PF_INET6 10
#define AF_UNSPEC PF_UNSPEC
#define AF_LOCAL PF_LOCAL
#define AF_INET PF_INET
#define AF_INET6 PF_INET6
#define SOCK_STREAM 1
#define SOCK_DGRAM 2
#define IPPROTO_TCP 0
#define IPPROTO_UDP 0
#define INADDR_ANY ((ip_addr_t)0)
#define SOCKADDR_STR_LEN IP_ENDPOINT_STR_LEN
struct sock {
int used;
int family;
int type;
int desc;
};
struct sockaddr {
unsigned short sa_family;
char sa_data[14];
};
struct sockaddr_in {
unsigned short sin_family;
uint16_t sin_port;
ip_addr_t sin_addr;
};
#define IFNAMSIZ 16
extern int
sockaddr_pton(const char *p, struct sockaddr *n, size_t size);
extern char *
sockaddr_ntop(const struct sockaddr *n, char *p, size_t size);
extern int
sock_open(int domain, int type, int protocol);
extern int
sock_close(int id);
extern ssize_t
sock_recvfrom(int id, void *buf, size_t n, struct sockaddr *addr, int *addrlen);
extern ssize_t
sock_sendto(int id, const void *buf, size_t n, const struct sockaddr *addr, int addrlen);
extern int
sock_bind(int id, const struct sockaddr *addr, int addrlen);
extern int
sock_listen(int id, int backlog);
extern int
sock_accept(int id, struct sockaddr *addr, int *addrlen);
extern int
sock_connect(int id, const struct sockaddr *addr, int addrlen);
extern ssize_t
sock_recv(int id, void *buf, size_t n);
extern ssize_t
sock_send(int id, const void *buf, size_t n);
#endif