MCPcopy Create free account
hub / github.com/ElementsProject/lightning / is_dnsaddr

Function is_dnsaddr

common/wireaddr.c:401–445  ·  view source on GitHub ↗

The rules to check for DNS FQDNs, see `man 7 hostname` * * - not longer than 255 * - labels are separated with . dot * - labels do not start or end with - hyphen * - labels must be longer than zero * - allow ASCII letters a-z, A-Z, digits 0-9 and - hyphen * - additionally we allow for an '_' underscore in the first hostname label * - other characters must be punycoded rfc3492 * * See `ma

Source from the content-addressed store, hash-verified

399 * See `man 7 hostname` and https://www.rfc-editor.org/rfc/rfc1035
400 */
401bool is_dnsaddr(const char *arg)
402{
403 size_t i, arglen;
404 int lastdot;
405 int numlabels;
406
407 if (is_ipaddr(arg) || is_toraddr(arg) || is_wildcardaddr(arg))
408 return false;
409
410 /* now that its not IP or TOR, check its a DNS name */
411 arglen = strlen(arg);
412 if (arglen > 255)
413 return false;
414 lastdot = -1;
415 numlabels = 0;
416 for (i = 0; i < arglen; i++) {
417 if (arg[i] == '.') {
418 numlabels++;
419 /* segment must be longer than zero */
420 if (i - lastdot == 1)
421 return false;
422 /* last segment can not end with hypen */
423 if (i != 0 && arg[i-1] == '-')
424 return false;
425 lastdot = i;
426 continue;
427 }
428 /* segment cannot start with hyphen */
429 if (i == lastdot + 1 && arg[i] == '-')
430 return false;
431 if (arg[i] >= 'a' && arg[i] <= 'z')
432 continue;
433 if (arg[i] >= 'A' && arg[i] <= 'Z')
434 continue;
435 if (arg[i] >= '0' && arg[i] <= '9')
436 continue;
437 if (arg[i] == '-')
438 continue;
439 /* allow for _ underscores in the first hostname part */
440 if (arg[i] == '_' && numlabels == 0)
441 continue;
442 return false;
443 }
444 return true;
445}
446
447struct wireaddr *
448wireaddr_from_hostname(const tal_t *ctx,

Callers 3

fromwire_wireaddrFunction · 0.85
parse_wireaddrFunction · 0.85
mainFunction · 0.85

Calls 3

is_ipaddrFunction · 0.85
is_toraddrFunction · 0.85
is_wildcardaddrFunction · 0.85

Tested by 1

mainFunction · 0.68