| | 267 | | static void server_connect_callback_readpipe(SERVER_REC *server) |
| | 268 | | { |
| | 269 | | RESOLVED_IP_REC iprec; |
| | 270 | | IPADDR *ip; |
| | 271 | | const char *errormsg; |
| | 272 | | char *servername = NULL;
|
| | 273 | | |
| | 274 | | g_source_remove(server->connect_tag); |
| | 275 | | server->connect_tag = -1; |
| | 276 | | |
| | 277 | | net_gethostbyname_return(server->connect_pipe[0], &iprec); |
| | 278 | | |
| | 279 | | g_io_channel_close(server->connect_pipe[0]); |
| | 280 | | g_io_channel_unref(server->connect_pipe[0]); |
| | 281 | | g_io_channel_close(server->connect_pipe[1]); |
| | 282 | | g_io_channel_unref(server->connect_pipe[1]); |
| | 283 | | |
| | 284 | | server->connect_pipe[0] = NULL;
|
| | 285 | | server->connect_pipe[1] = NULL;
|
| | 286 | | |
| | 287 | | |
| | 288 | | if (iprec.error != 0) { |
| | 289 | | |
| | 290 | | ip = NULL;
|
| | 291 | | } else if (server->connrec->family == AF_INET) {
|
| | 292 | | |
| | 293 | | ip = iprec.ip4.family == 0 ? NULL : &iprec.ip4;
|
| | 294 | | servername = iprec.host4; |
| | 295 | | } else if (server->connrec->family == AF_INET6) {
|
| | 296 | | |
| | 297 | | ip = iprec.ip6.family == 0 ? NULL : &iprec.ip6;
|
| | 298 | | servername = iprec.host6; |
| | 299 | | } else { |
| | 300 | | |
| | 301 | | |
| | 302 | | if (iprec.ip4.family == 0 || |
| | 303 | | (iprec.ip6.family != 0 && |
| | 304 | | settings_get_bool("resolve_prefer_ipv6"))) { |
| | 305 | | ip = &iprec.ip6; |
| | 306 | | servername = iprec.host6; |
| | 307 | | } else { |
| | 308 | | ip = &iprec.ip4; |
| | 309 | | servername = iprec.host4; |
| | 310 | | } |
| | 311 | | } |
| | 312 | | |
| | 313 | | if (ip != NULL) {
|
| | 314 | | |
| | 315 | | if (servername) { |
| | 316 | | g_free(server->connrec->address); |
| | 317 | | server->connrec->address = g_strdup(servername); |
| | 318 | | } |
| | 319 | | server_real_connect(server, ip, NULL);
|
| | 320 | | errormsg = NULL;
|
| | 321 | | } else { |
| Never True: iprec.error == 0 | 322 | | if (iprec.error == 0 || net_hosterror_notfound(iprec.error)) { | Problem | | Never True: iprec.error == 0 |
|
| | 323 | | |
| | 324 | | |
| | 325 | | server->dns_error = TRUE;
|
| | 326 | | } |
| | 327 | | |
| | 328 | | if (iprec.error == 0) { |
| | 329 | | |
| | 330 | | errormsg = server->connrec->family == AF_INET ?
|
| | 331 | | "IPv4 address not found for host" : |
| | 332 | | "IPv6 address not found for host"; |
| | 333 | | } else { |
| | 334 | | |
| | 335 | | errormsg = iprec.errorstr != NULL ? iprec.errorstr :
|
| | 336 | | "Host lookup failed"; |
| | 337 | | } |
| | 338 | | |
| | 339 | | server->connection_lost = TRUE;
|
| | 340 | | server_connect_failed(server, errormsg); |
| | 341 | | } |
| | 342 | | |
| | 343 | | g_free(iprec.errorstr); |
| | 344 | | g_free(iprec.host4); |
| | 345 | | g_free(iprec.host6); |
| | 346 | | } |