… | |
… | |
19 | */ |
19 | */ |
20 | |
20 | |
21 | #ifndef VPE_SOCKINFO_H__ |
21 | #ifndef VPE_SOCKINFO_H__ |
22 | #define VPE_SOCKINFO_H__ |
22 | #define VPE_SOCKINFO_H__ |
23 | |
23 | |
24 | #include <sys/socket.h> |
24 | #include "netcompat.h" |
25 | #include <netinet/in.h> |
|
|
26 | |
25 | |
27 | #include "conf.h" |
26 | #include "conf.h" |
28 | |
27 | |
29 | // encapsulate one or more network addresses. this structure |
28 | // encapsulate one or more network addresses. this structure |
30 | // gets transferred over the wire, so be careful with endianness etc. |
29 | // gets transferred over the wire, so be careful with endianness etc. |
… | |
… | |
33 | u32 host; |
32 | u32 host; |
34 | u16 port; |
33 | u16 port; |
35 | u8 prot; |
34 | u8 prot; |
36 | u8 pad1; |
35 | u8 pad1; |
37 | |
36 | |
38 | void set (const sockaddr_in *sa, u8 prot_ = PROT_UDPv4); |
37 | void set (const sockaddr_in *sa, u8 prot_); |
39 | void set (const conf_node *conf); |
38 | void set (const conf_node *conf, u8 prot_); |
|
|
39 | void set (const char *hostname, u16 port_, u8 prot_); |
|
|
40 | |
|
|
41 | // return the supported protocols |
|
|
42 | u8 supported_protocols (conf_node *conf = 0); |
|
|
43 | bool upgrade_protocol (u8 prot_, conf_node *conf = 0); |
40 | |
44 | |
41 | operator const char *() const; |
45 | operator const char *() const; |
42 | |
46 | |
43 | const sockaddr *sav4 () const; |
47 | const sockaddr *sav4 () const; |
44 | const socklen_t salenv4 () const |
48 | const socklen_t salenv4 () const |
45 | { |
|
|
46 | return sizeof (sockaddr_in); |
49 | { return sizeof (sockaddr_in); } |
47 | } |
|
|
48 | |
50 | |
49 | const char *ntoa () const; |
51 | const char *ntoa () const; |
50 | |
52 | |
51 | sockinfo() |
53 | bool valid () const |
52 | { |
54 | { return prot != 0 && host != 0; } |
53 | prot = 0; |
|
|
54 | } |
|
|
55 | |
55 | |
|
|
56 | sockinfo() { prot = 0; } |
|
|
57 | |
56 | sockinfo(const sockaddr_in &sa, u8 prot_ = PROT_UDPv4) |
58 | sockinfo(const sockaddr_in &sa, u8 prot) |
57 | { |
|
|
58 | set (&sa, prot_); |
59 | { set (&sa, prot); } |
59 | } |
60 | |
|
|
61 | sockinfo(const conf_node *conf, u8 prot) |
|
|
62 | { set (conf, prot); } |
60 | }; |
63 | }; |
61 | |
64 | |
62 | inline bool |
|
|
63 | operator == (const sockinfo &a, const sockinfo &b) |
65 | bool operator == (const sockinfo &a, const sockinfo &b); |
64 | { |
66 | bool operator < (const sockinfo &a, const sockinfo &b); |
65 | return a.host == b.host && a.port == b.port && a.prot == b.prot; |
|
|
66 | } |
|
|
67 | |
67 | |
68 | #endif |
68 | #endif |
69 | |
69 | |