lokinet/llarp/exit_info.c

35 lines
1.1 KiB
C
Raw Normal View History

2018-04-05 14:43:16 +00:00
#include <arpa/inet.h>
2018-04-04 16:10:27 +00:00
#include <llarp/bencode.h>
2018-04-05 14:43:16 +00:00
#include <llarp/exit_info.h>
2018-04-05 14:23:14 +00:00
#include <llarp/string.h>
2018-04-04 16:10:27 +00:00
bool llarp_xi_bencode(struct llarp_xi *xi, llarp_buffer_t *buff) {
char addr_buff[128] = {0};
2018-04-05 14:43:16 +00:00
const char *addr;
if (!bencode_start_dict(buff)) return false;
2018-04-04 16:10:27 +00:00
/** address */
addr = inet_ntop(AF_INET6, &xi->address, addr_buff, sizeof(addr_buff));
2018-04-05 14:43:16 +00:00
if (!addr) return false;
if (!bencode_write_bytestring(buff, "a", 1)) return false;
if (!bencode_write_bytestring(buff, addr, strnlen(addr, sizeof(addr_buff))))
return false;
2018-04-04 16:10:27 +00:00
/** netmask */
addr = inet_ntop(AF_INET6, &xi->netmask, addr_buff, sizeof(addr_buff));
2018-04-05 14:43:16 +00:00
if (!addr) return false;
if (!bencode_write_bytestring(buff, "b", 1)) return false;
if (!bencode_write_bytestring(buff, addr, strnlen(addr, sizeof(addr_buff))))
return false;
2018-04-04 16:10:27 +00:00
/** public key */
2018-04-05 14:43:16 +00:00
if (!bencode_write_bytestring(buff, "k", 1)) return false;
if (!bencode_write_bytestring(buff, xi->pubkey, sizeof(llarp_pubkey_t)))
return false;
2018-04-04 16:10:27 +00:00
/** version */
2018-04-05 14:43:16 +00:00
if (!bencode_write_version_entry(buff)) return false;
2018-04-04 16:10:27 +00:00
return bencode_end(buff);
}