… | |
… | |
42 | #include <cstdio> |
42 | #include <cstdio> |
43 | |
43 | |
44 | // all ipv4-based protocols |
44 | // all ipv4-based protocols |
45 | #define PROTv4 (PROT_UDPv4 | PROT_TCPv4 | PROT_ICMPv4 | PROT_IPv4 | PROT_DNSv4) |
45 | #define PROTv4 (PROT_UDPv4 | PROT_TCPv4 | PROT_ICMPv4 | PROT_IPv4 | PROT_DNSv4) |
46 | |
46 | |
|
|
47 | void |
47 | void sockinfo::set (const sockaddr_in *sa, u8 prot_) |
48 | sockinfo::set (const sockaddr_in *sa, u8 prot_) |
48 | { |
49 | { |
49 | host = sa->sin_addr.s_addr; |
50 | host = sa->sin_addr.s_addr; |
50 | port = prot_ & (PROT_IPv4 | PROT_ICMPv4) ? 0 : sa->sin_port; |
51 | port = prot_ & (PROT_IPv4 | PROT_ICMPv4) ? 0 : sa->sin_port; |
51 | prot = prot_; |
52 | prot = prot_; |
52 | } |
53 | } |
53 | |
54 | |
|
|
55 | void |
54 | void sockinfo::set (const char *hostname, u16 port_, u8 prot_) |
56 | sockinfo::set (const char *hostname, u16 port_, u8 prot_) |
55 | { |
57 | { |
56 | prot = prot_; |
58 | prot = prot_; |
57 | host = 0; |
59 | host = 0; |
58 | port = htons (port_); |
60 | port = htons (port_); |
59 | |
61 | |