common.cView |
---|
441 | 441 | } |
442 | 442 | |
443 | 443 | |
444 | 444 | * returns 0 on success, -1 otherwise and logs error |
| 445 | + * |
| 446 | + * *host gets modified |
445 | 447 | **/ |
446 | | -int resolve_split_name(struct addrinfo **out, const char* host, const char* serv) |
| 448 | +int resolve_split_name(struct addrinfo **out, char* host, const char* serv) |
447 | 449 | { |
448 | 450 | struct addrinfo hint; |
| 451 | + char *end; |
449 | 452 | int res; |
450 | 453 | |
451 | 454 | memset(&hint, 0, sizeof(hint)); |
452 | 455 | hint.ai_family = PF_UNSPEC; |
453 | 456 | hint.ai_socktype = SOCK_STREAM; |
454 | 457 | |
| 458 | + |
| 459 | + * around IP address */ |
| 460 | + if (host[0] == '[') { |
| 461 | + end = strrchr(host, ']'); |
| 462 | + if (!end) { |
| 463 | + fprintf(stderr, "%s: no closing bracket in IPv6 address?\n", host); |
| 464 | + } |
| 465 | + host++; |
| 466 | + *end = 0; |
| 467 | + } |
| 468 | + |
| 469 | + |
455 | 470 | res = getaddrinfo(host, serv, &hint, out); |
456 | 471 | if (res) |
457 | 472 | log_message(LOG_ERR, "%s `%s:%s'\n", gai_strerror(res), host, serv); |
458 | 473 | return res; |
463 | 478 | fullname: input string -- it gets clobbered |
464 | 479 | */ |
465 | 480 | void resolve_name(struct addrinfo **out, char* fullname) |
466 | 481 | { |
467 | | - char *serv, *host, *end; |
| 482 | + char *serv, *host; |
468 | 483 | int res; |
469 | 484 | |
470 | 485 | |
471 | 486 | char *sep = strrchr(fullname, ':'); |
477 | 492 | *sep = 0; |
478 | 493 | |
479 | 494 | host = fullname; |
480 | 495 | |
481 | | - |
482 | | - * around IP address */ |
483 | | - if (host[0] == '[') { |
484 | | - end = strrchr(host, ']'); |
485 | | - if (!end) { |
486 | | - fprintf(stderr, "%s: no closing bracket in IPv6 address?\n", host); |
487 | | - } |
488 | | - host++; |
489 | | - *end = 0; |
490 | | - } |
491 | | - |
492 | 496 | res = resolve_split_name(out, host, serv); |
493 | 497 | if (res) { |
494 | 498 | fprintf(stderr, "%s `%s'\n", gai_strerror(res), fullname); |
495 | 499 | if (res == EAI_SERVICE) |