|
1 #pragma once |
|
2 #include "../main.h" |
|
3 |
|
4 struct sockaddr; |
|
5 |
|
6 enum WithPort { IP_WITH_PORT, IP_NO_PORT }; |
|
7 |
|
8 struct IPAddress |
|
9 { |
|
10 unsigned long host; |
|
11 unsigned short port; |
|
12 static bool sink; |
|
13 |
|
14 IPAddress(); |
|
15 IPAddress (unsigned long host, unsigned short port); |
|
16 IPAddress (const IPAddress& other); |
|
17 |
|
18 METHOD compare (const IPAddress& other) const -> bool; |
|
19 METHOD octet (int n) const -> unsigned char; |
|
20 METHOD set_octet (int n, unsigned char oct) -> void; |
|
21 METHOD to_string (WithPort withport = IP_NO_PORT) const -> String; |
|
22 METHOD to_sockaddr_in() const -> sockaddr_in; |
|
23 METHOD operator< (const IPAddress& other) const -> bool; |
|
24 inline METHOD operator== (const IPAddress& other) const -> bool; |
|
25 inline METHOD operator!= (const IPAddress& other) const -> bool; |
|
26 inline METHOD operator[] (int n) const -> unsigned char; |
|
27 |
|
28 static METHOD from_string (String input, bool* ok = &sink) -> IPAddress; |
|
29 static METHOD resolve (String node, bool* ok = &sink) -> IPAddress; |
|
30 }; |
|
31 |
|
32 extern const IPAddress localhost; |
|
33 |
|
34 inline METHOD |
|
35 IPAddress::operator[] (int n) const -> unsigned char |
|
36 { |
|
37 return octet (n); |
|
38 } |
|
39 |
|
40 inline METHOD |
|
41 IPAddress::operator== (const IPAddress& other) const -> bool |
|
42 { |
|
43 return compare (other); |
|
44 } |
|
45 |
|
46 inline METHOD |
|
47 IPAddress::operator!= (const IPAddress& other) const -> bool |
|
48 { |
|
49 return not operator== (other); |
|
50 } |