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

Function is_dnsaddr

common/wireaddr.c:386–422  ·  view source on GitHub ↗

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 */

Source from the content-addressed store, hash-verified

384 * - lowercase a-z and digits 0-9 and - hyphen
385 */
386bool 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
424struct wireaddr *
425wireaddr_from_hostname(const tal_t *ctx,

Callers 2

opt_add_addr_withtypeFunction · 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