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

Function separate_address_and_port

common/wireaddr.c:308–342  ·  view source on GitHub ↗

Valid forms: * * [anything]: * anything-without-colons-or-left-brace: * anything-without-colons * string-with-multiple-colons * * Returns false if it wasn't one of these forms. If it returns true, * it only overwrites *port if it was specified by above. */

Source from the content-addressed store, hash-verified

306 * it only overwrites *port if it was specified by <number> above.
307 */
308bool separate_address_and_port(const tal_t *ctx, const char *arg,
309 char **addr, u16 *port)
310{
311 char *portcolon;
312
313 if (strstarts(arg, "[")) {
314 char *end = strchr(arg, ']');
315 if (!end)
316 return false;
317 /* Copy inside [] */
318 *addr = tal_strndup(ctx, arg + 1, end - arg - 1);
319 portcolon = strchr(end+1, ':');
320 } else {
321 portcolon = strchr(arg, ':');
322 if (portcolon) {
323 /* Disregard if there's more than one : or if it's at
324 the end */
325 if (portcolon != strrchr(arg, ':')
326 || portcolon[1] == '\0')
327 portcolon = NULL;
328 }
329 if (portcolon)
330 *addr = tal_strndup(ctx, arg, portcolon - arg);
331 else
332 *addr = tal_strdup(ctx, arg);
333 }
334
335 if (portcolon) {
336 char *endp;
337 *port = strtol(portcolon + 1, &endp, 10);
338 return *port != 0 && *endp == '\0';
339 }
340
341 return true;
342}
343
344bool is_ipaddr(const char *arg)
345{

Callers 5

opt_add_addr_withtypeFunction · 0.85
param_id_maybe_addrFunction · 0.85
parse_wireaddrFunction · 0.85
parse_wireaddr_internalFunction · 0.85
mainFunction · 0.85

Calls

no outgoing calls

Tested by 1

mainFunction · 0.68