Forked from jmjatlanta/c-multiaddr multiaddr for IPFS in C.
Find a file
2017-07-17 15:11:08 -05:00
include/multiaddr Fixed memory leak and most compiler warnings 2017-07-17 15:11:08 -05:00
.cproject Added some utility methods to make parsing easier 2017-03-09 18:20:56 -05:00
.gitignore Small changes to allow compile 2016-12-05 06:56:09 -05:00
.project added Eclipse project files 2016-11-17 16:35:50 -05:00
base58.c Multiaddress stability fixes 2017-04-16 23:46:07 -05:00
LICENSE Update LICENSE 2017-01-31 17:11:29 +01:00
Makefile strtok_r only by declaration 2017-03-21 13:36:06 -05:00
multiaddr.c Fixed memory leak and most compiler warnings 2017-07-17 15:11:08 -05:00
proto-dat Add files via upload 2016-11-06 03:57:36 +02:00
protocols.c added string tokenizer for c99 2017-03-21 13:04:44 -05:00
protoutils.c Fixed memory leak and most compiler warnings 2017-07-17 15:11:08 -05:00
README.md Update README.md 2017-02-21 21:04:06 +02:00
STATUS.md Update STATUS.md 2016-11-10 13:38:23 +02:00
test_multiaddr.h Fixed memory leak and most compiler warnings 2017-07-17 15:11:08 -05:00
testing.c Fixed bug on odd byte ip addresses 2017-07-13 18:29:02 -05:00
varhexutils.c Fixed memory leak and most compiler warnings 2017-07-17 15:11:08 -05:00
varint.c Directory structure changes 2016-11-14 08:03:48 -05:00

c-multiaddr

multiaddr for IPFS in C.

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

Usage:

All you need to include is multiaddr.h

Maddr struct:

  • char * string; // String that contains addresses such as /ip4/192.168.1.1/
  • 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/127.0.0.1/tcp/8080/");

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/192.168.1.1/
  • multiaddress_encapsulate(a,"/udp/3333/"); //Adds udp/3333/
  • Now the string is: /ip4/192.168.1.1/udp/3333/
  • multiaddress_decapsulate(a,"udp"); //Removes udp protocol and its address
  • Now the string is: /ip4/192.168.1.1/
  • multiaddress_encapsulate(a,"/tcp/8080");
  • Now the string is: /ip4/192.168.1.1/tcp/8080/

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/192.168.1.1/tcp/8080/