c-multiaddr/include/multiaddr/multiaddr.h

58 lines
1.6 KiB
C
Raw Normal View History

2016-11-06 01:57:36 +00:00
#ifndef MULTIADDR
#define MULTIADDR
#include <string.h>
2016-11-06 01:57:36 +00:00
#include "varhexutils.h"
#include "varint.h"
#include "protocols.h"
#include "protoutils.h"
/**
* Normally, addresses have been represented using string addresses, like:
tcp4://127.0.0.1:1234
udp4://10.20.30.40:5060
ws://1.2.3.4:5678
tcp6://[1fff:0:a88:85a3::ac1f]:8001
This isn't optimal. Instead, addresses should be formatted so:
Binary format:
(varint proto><n byte addr>)+
<1 byte ipv4 code><4 byte ipv4 addr><1 byte udp code><2 byte udp port>
<1 byte ipv6 code><16 byte ipv6 addr><1 byte tcp code><2 byte tcp port>
String format:
(/<addr str code>/<addr str rep>)+
/ip4/<ipv4 str addr>/udp/<udp int port>
/ip6/<ipv6 str addr>/tcp/<tcp int port>
*/
2017-02-13 18:30:22 +00:00
struct MultiAddress
2016-11-06 01:57:36 +00:00
{
// A MultiAddress represented as a string
char* string;
// A MultiAddress represented as an array of bytes
2017-02-17 04:13:58 +00:00
//<varint proto><n byte addr><1 byte protocol code><4 byte ipv4 address or 16 byte ipv6 address><1 byte tcp/udp code><2 byte port>
uint8_t* bytes;
size_t bsize;
2016-11-06 01:57:36 +00:00
};
int strpos(char *haystack, char *needle);
struct MultiAddress* multiaddress_new_from_bytes(const uint8_t* byteaddress, int size); //Construct new address from bytes
struct MultiAddress* multiaddress_new_from_string(const char* straddress); //Construct new address from string
void multiaddress_free(struct MultiAddress* in);
2017-02-20 20:58:19 +00:00
struct MultiAddress* multiaddress_copy(const struct MultiAddress* source);
2017-02-13 19:28:06 +00:00
int multiaddress_encapsulate(struct MultiAddress * result, char * string);
int multiaddress_decapsulate(struct MultiAddress * result, char * srci);
2016-11-08 11:02:45 +00:00
2016-12-05 11:56:09 +00:00
#endif