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