1 | module net |
2 | |
3 | const ( |
4 | socket_max_port = u16(0xFFFF) |
5 | ) |
6 | |
7 | // validate_port checks whether a port is valid |
8 | // and returns the port or an error |
9 | pub fn validate_port(port int) !u16 { |
10 | if port <= net.socket_max_port { |
11 | return u16(port) |
12 | } else { |
13 | return err_port_out_of_range |
14 | } |
15 | } |
16 | |
17 | // split address splits an address into its host name and its port |
18 | pub fn split_address(addr string) !(string, u16) { |
19 | port := addr.all_after_last(':').int() |
20 | address := addr.all_before_last(':') |
21 | |
22 | // TODO(emily): Maybe do some more checking here |
23 | // to validate ipv6 address sanity? |
24 | |
25 | p := validate_port(port)! |
26 | return address, p |
27 | } |