| 525 | } |
| 526 | |
| 527 | static void parse_host_and_port(char *hostport, char **host, |
| 528 | char **port) |
| 529 | { |
| 530 | if (*hostport == '[') { |
| 531 | char *end; |
| 532 | |
| 533 | end = strchr(hostport, ']'); |
| 534 | if (!end) |
| 535 | die("Invalid request ('[' without ']')"); |
| 536 | *end = '\0'; |
| 537 | *host = hostport + 1; |
| 538 | if (!end[1]) |
| 539 | *port = NULL; |
| 540 | else if (end[1] == ':') |
| 541 | *port = end + 2; |
| 542 | else |
| 543 | die("Garbage after end of host part"); |
| 544 | } else { |
| 545 | *host = hostport; |
| 546 | *port = strrchr(hostport, ':'); |
| 547 | if (*port) { |
| 548 | **port = '\0'; |
| 549 | ++*port; |
| 550 | } |
| 551 | } |
| 552 | } |
| 553 | |
| 554 | /* |
| 555 | * Sanitize a string from the client so that it's OK to be inserted into a |