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