… | |
… | |
31 | host = sa->sin_addr.s_addr; |
31 | host = sa->sin_addr.s_addr; |
32 | port = prot_ == PROT_IPv4 ? 0 : sa->sin_port; |
32 | port = prot_ == PROT_IPv4 ? 0 : sa->sin_port; |
33 | prot = prot_; |
33 | prot = prot_; |
34 | } |
34 | } |
35 | |
35 | |
36 | void |
36 | void sockinfo::set (const char *hostname, u16 port_, u8 prot_) |
37 | sockinfo::set (const conf_node *conf, u8 prot_) |
|
|
38 | { |
37 | { |
39 | prot = prot_; |
38 | prot = prot_; |
40 | host = 0; |
39 | host = 0; |
41 | port = prot == PROT_UDPv4 ? htons (conf->udp_port) |
40 | port = htons (port_); |
42 | : prot == PROT_TCPv4 ? htons (conf->tcp_port) |
|
|
43 | : 0; |
|
|
44 | |
41 | |
45 | if (prot & (PROT_UDPv4 | PROT_TCPv4 | PROT_IPv4) |
42 | if (prot & (PROT_UDPv4 | PROT_TCPv4 | PROT_IPv4) |
46 | && conf->hostname) |
43 | && hostname) |
47 | { |
44 | { |
48 | struct hostent *he = gethostbyname (conf->hostname); |
45 | struct hostent *he = gethostbyname (hostname); |
49 | |
46 | |
50 | if (he |
47 | if (he |
51 | && he->h_addrtype == AF_INET && he->h_length == 4 && he->h_addr_list[0]) |
48 | && he->h_addrtype == AF_INET && he->h_length == 4 && he->h_addr_list[0]) |
52 | { |
49 | { |
53 | //sa->sin_family = he->h_addrtype; |
50 | //sa->sin_family = he->h_addrtype; |
54 | memcpy (&host, he->h_addr_list[0], 4); |
51 | memcpy (&host, he->h_addr_list[0], 4); |
55 | } |
52 | } |
56 | else |
53 | else |
57 | slog (L_NOTICE, _("unable to resolve host '%s'"), conf->hostname); |
54 | slog (L_NOTICE, _("unable to resolve host '%s'"), hostname); |
58 | } |
55 | } |
59 | } |
56 | } |
60 | |
57 | |
|
|
58 | void |
|
|
59 | sockinfo::set (const conf_node *conf, u8 prot_) |
|
|
60 | { |
|
|
61 | set (conf->hostname, |
|
|
62 | prot_ == PROT_UDPv4 ? conf->udp_port |
|
|
63 | : prot_ == PROT_TCPv4 ? conf->tcp_port |
|
|
64 | : 0, |
|
|
65 | prot_); |
|
|
66 | } |
61 | |
67 | |
62 | const sockaddr * |
68 | const sockaddr * |
63 | sockinfo::sav4() const |
69 | sockinfo::sav4() const |
64 | { |
70 | { |
65 | static sockaddr_in sa; |
71 | static sockaddr_in sa; |
… | |
… | |
69 | sa.sin_addr.s_addr = host; |
75 | sa.sin_addr.s_addr = host; |
70 | |
76 | |
71 | return (const sockaddr *)&sa; |
77 | return (const sockaddr *)&sa; |
72 | } |
78 | } |
73 | |
79 | |
74 | static char hostport[10 + 15 + 1 + 5 + 1]; // protype / IPv4 : port |
80 | static char hostport[10 + 15 + 1 + 5 + 1]; // proto / IPv4 : port |
75 | |
81 | |
76 | const char * |
82 | const char * |
77 | sockinfo::ntoa () const |
83 | sockinfo::ntoa () const |
78 | { |
84 | { |
79 | in_addr ia = { host }; |
85 | in_addr ia = { host }; |