Forked from jmjatlanta/c-multiaddr
multiaddr for IPFS in C.

Agorise b1f7d607ee Update LICENSE 4 years ago
include 3b178a142d Added helper method to compare ipfs address without IP address 5 years ago
.cproject e914307a4d Added some utility methods to make parsing easier 6 years ago
.gitignore ee1cf1359c Small changes to allow compile 6 years ago
.project fa1084b45c added Eclipse project files 6 years ago
LICENSE b1f7d607ee Update LICENSE 4 years ago
Makefile e90434ba61 strtok_r only by declaration 6 years ago 10302dd4b1 Update 6 years ago edb7475318 Update 6 years ago
base58.c f0961a247f Multiaddress stability fixes 6 years ago
multiaddr.c 3b178a142d Added helper method to compare ipfs address without IP address 5 years ago
proto-dat ebc0e05b8b Add files via upload 6 years ago
protocols.c d09c4a0d76 added string tokenizer for c99 6 years ago
protoutils.c 4c457c1dd3 Better error reporting 5 years ago
test_multiaddr.h c434fbd160 Fixed warnings 5 years ago
testing.c 58a6240af9 Fixed bug on odd byte ip addresses 5 years ago
varhexutils.c c434fbd160 Fixed warnings 5 years ago
varint.c 68ca649688 Directory structure changes 6 years ago


multiaddr for IPFS in C.

Multiaddr provides easy networking protocols nesting, easy encapsulation of extra protocols, easy tunneling, etc.


All you need to include is multiaddr.h

Maddr struct:

  • char * string; // String that contains addresses such as /ip4/
  • uint8_t * bytes; // uint8_t * that contains the enecoded address
  • size_t bsize; //size_t that contains the real bytes size (Use it whenever using the bytes so you don't input trash!)

New Multi Address From String(multiaddress_new_from_string)

struct MultiAddress* a = multiaddress_new_from_string("/ip4/");

Obtaining the byte buffer(.bytes, .bsize[0]):

printf("TEST BYTES: %s\n",Var_To_Hex(a->bsize, a->bytes)); Var_To_Hex = Byte Buffer to Hex String Hex_To_Var = Hex String to Byte Buffer

Encapsulation & Decapsulation(m_encapsulate, m_decapsulate)

Remember, Decapsulation happens from right to left, never in reverse, if you have /ip4/udp/ipfs/ if you decapsulate "udp" you will also take out ipfs!

  • Now the string is: /ip4/
  • multiaddress_encapsulate(a,"/udp/3333/"); //Adds udp/3333/
  • Now the string is: /ip4/
  • multiaddress_decapsulate(a,"udp"); //Removes udp protocol and its address
  • Now the string is: /ip4/
  • multiaddress_encapsulate(a,"/tcp/8080");
  • Now the string is: /ip4/

Constructing a multiaddress from bytes:

  • struct MultiAddress* beta;
  • beta = multiaddress_new_from_bytes(a->bytes,a->bsize); //This will already construct back to the string too!
  • printf("B STRING: %s\n",beta->string); //So after encapsulation and decapsulation atm this string would
  • contain: /ip4/