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

Function separate_address_and_port

common/wireaddr.c:303–337  ·  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

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

Callers 4

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