mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 07:04:22 +01:00
In future it will have TOR support, so the name will be awkward. We collect the to/fromwire functions in common/wireaddr.c, and the parsing functions in lightningd/netaddress.c. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
31 lines
697 B
C
31 lines
697 B
C
#include <common/wireaddr.h>
|
|
#include <wire/wire.h>
|
|
|
|
/* Returns false if we didn't parse it, and *cursor == NULL if malformed. */
|
|
bool fromwire_wireaddr(const u8 **cursor, size_t *max, struct wireaddr *addr)
|
|
{
|
|
addr->type = fromwire_u8(cursor, max);
|
|
|
|
switch (addr->type) {
|
|
case ADDR_TYPE_IPV4:
|
|
addr->addrlen = 4;
|
|
break;
|
|
case ADDR_TYPE_IPV6:
|
|
addr->addrlen = 16;
|
|
break;
|
|
default:
|
|
return false;
|
|
}
|
|
fromwire(cursor, max, addr->addr, addr->addrlen);
|
|
addr->port = fromwire_u16(cursor, max);
|
|
|
|
return *cursor != NULL;
|
|
}
|
|
|
|
void towire_wireaddr(u8 **pptr, const struct wireaddr *addr)
|
|
{
|
|
towire_u8(pptr, addr->type);
|
|
towire(pptr, addr->addr, addr->addrlen);
|
|
towire_u16(pptr, addr->port);
|
|
}
|