Skip to content

Commit

Permalink
Fix UDP and TCP port byte order in saved options.
Browse files Browse the repository at this point in the history
The UDP and TCP port are stored in network byte order in the
ares_channeldata, but are passed in to ares_init_options() in host byte
order.  Thus we must return them from ares_save_options() in host byte
order too, or a duplicated channel will convert them again, leading to a
nonfunctional channel and a mysterious connection refused error from
ares_gethostbyname().  This breaks ares_dup(), thus the curl easy API
when c-ares is used by curl, and thus all the curl easy API's users.
  • Loading branch information
nickalcock authored and bagder committed May 21, 2012
1 parent 7ec5e8e commit 9bd38a4
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ares_init.c
Expand Up @@ -355,8 +355,8 @@ int ares_save_options(ares_channel channel, struct ares_options *options,
options->timeout = channel->timeout;
options->tries = channel->tries;
options->ndots = channel->ndots;
options->udp_port = (unsigned short)channel->udp_port;
options->tcp_port = (unsigned short)channel->tcp_port;
options->udp_port = (unsigned short)ntohs(channel->udp_port);
options->tcp_port = (unsigned short)ntohs(channel->tcp_port);
options->sock_state_cb = channel->sock_state_cb;
options->sock_state_cb_data = channel->sock_state_cb_data;

Expand Down

0 comments on commit 9bd38a4

Please sign in to comment.