Rules: * * - not longer than 255 * - segments are separated with . dot * - segments do not start or end with - hyphen * - segments must be longer thant zero * - lowercase a-z and digits 0-9 and - hyphen */
| 384 | * - lowercase a-z and digits 0-9 and - hyphen |
| 385 | */ |
| 386 | bool is_dnsaddr(const char *arg) |
| 387 | { |
| 388 | size_t i, arglen; |
| 389 | int lastdot; |
| 390 | |
| 391 | if (is_ipaddr(arg) || is_toraddr(arg) || is_wildcardaddr(arg)) |
| 392 | return false; |
| 393 | |
| 394 | /* now that its not IP or TOR, check its a DNS name */ |
| 395 | arglen = strlen(arg); |
| 396 | if (arglen > 255) |
| 397 | return false; |
| 398 | lastdot = -1; |
| 399 | for (i = 0; i < arglen; i++) { |
| 400 | if (arg[i] == '.') { |
| 401 | /* segment must be longer than zero */ |
| 402 | if (i - lastdot == 1) |
| 403 | return false; |
| 404 | /* last segment can not end with hypen */ |
| 405 | if (i != 0 && arg[i-1] == '-') |
| 406 | return false; |
| 407 | lastdot = i; |
| 408 | continue; |
| 409 | } |
| 410 | /* segment cannot start with hyphen */ |
| 411 | if (i == lastdot + 1 && arg[i] == '-') |
| 412 | return false; |
| 413 | if (arg[i] >= 'a' && arg[i] <= 'z') |
| 414 | continue; |
| 415 | if (arg[i] >= '0' && arg[i] <= '9') |
| 416 | continue; |
| 417 | if (arg[i] == '-') |
| 418 | continue; |
| 419 | return false; |
| 420 | } |
| 421 | return true; |
| 422 | } |
| 423 | |
| 424 | struct wireaddr * |
| 425 | wireaddr_from_hostname(const tal_t *ctx, |