v / vlib / net
Raw file | 77 loc (67 sloc) | 1.19 KB | Latest commit hash de136f6ba
1module net
2
3#include <sys/socket.h>
4#include <netinet/in.h>
5
6const max_unix_path = 104
7
8pub struct C.addrinfo {
9mut:
10 ai_family int
11 ai_socktype int
12 ai_flags int
13 ai_protocol int
14 ai_addrlen int
15 ai_addr voidptr
16 ai_canonname voidptr
17 ai_next voidptr
18}
19
20pub struct C.sockaddr_in6 {
21mut:
22 // 1 + 1 + 2 + 4 + 16 + 4 = 28;
23 sin6_len u8 // 1
24 sin6_family u8 // 1
25 sin6_port u16 // 2
26 sin6_flowinfo u32 // 4
27 sin6_addr [16]u8 // 16
28 sin6_scope_id u32 // 4
29}
30
31pub struct C.sockaddr_in {
32mut:
33 sin_len u8
34 sin_family u8
35 sin_port u16
36 sin_addr u32
37 sin_zero [8]char
38}
39
40pub struct C.sockaddr_un {
41mut:
42 sun_len u8
43 sun_family u8
44 sun_path [max_unix_path]char
45}
46
47[_pack: '1']
48pub struct Ip6 {
49 port u16
50 flow_info u32
51 addr [16]u8
52 scope_id u32
53}
54
55[_pack: '1']
56pub struct Ip {
57 port u16
58 addr [4]u8
59 // Pad to size so that socket functions
60 // dont complain to us (see in.h and bind())
61 // TODO(emily): I would really like to use
62 // some constant calculations here
63 // so that this doesnt have to be hardcoded
64 sin_pad [8]u8
65}
66
67pub struct Unix {
68 path [max_unix_path]char
69}
70
71[_pack: '1']
72pub struct Addr {
73pub:
74 len u8
75 f u8
76 addr AddrData
77}