Parsing of IP adresses is now easier
This commit is contained in:
parent
e914307a4d
commit
7fb89918f8
2 changed files with 12 additions and 12 deletions
|
@ -56,13 +56,13 @@ int multiaddress_encapsulate(struct MultiAddress * result, char * string);
|
||||||
|
|
||||||
int multiaddress_decapsulate(struct MultiAddress * result, char * srci);
|
int multiaddress_decapsulate(struct MultiAddress * result, char * srci);
|
||||||
|
|
||||||
int multiaddress_is_ip(struct MultiAddress* in);
|
int multiaddress_is_ip(const struct MultiAddress* in);
|
||||||
|
|
||||||
int multiaddress_is_ip4(struct MultiAddress* in);
|
int multiaddress_is_ip4(const struct MultiAddress* in);
|
||||||
|
|
||||||
int multiaddress_is_ip6(struct MultiAddress* in);
|
int multiaddress_is_ip6(const struct MultiAddress* in);
|
||||||
|
|
||||||
int multiaddress_get_ip_family(struct MultiAddress* in);
|
int multiaddress_get_ip_family(const struct MultiAddress* in);
|
||||||
|
|
||||||
/***
|
/***
|
||||||
* Pulls the textual representation of the IP address from a multihash
|
* Pulls the textual representation of the IP address from a multihash
|
||||||
|
@ -70,7 +70,7 @@ int multiaddress_get_ip_family(struct MultiAddress* in);
|
||||||
* @param ip where to put the ip address
|
* @param ip where to put the ip address
|
||||||
* @returns true(1) on success, otherwise 0
|
* @returns true(1) on success, otherwise 0
|
||||||
*/
|
*/
|
||||||
int multiaddress_get_ip_address(struct MultiAddress* in, char** ip);
|
int multiaddress_get_ip_address(const struct MultiAddress* in, char** ip);
|
||||||
|
|
||||||
/***
|
/***
|
||||||
* Pulls the IP port from a multiaddress
|
* Pulls the IP port from a multiaddress
|
||||||
|
@ -78,6 +78,6 @@ int multiaddress_get_ip_address(struct MultiAddress* in, char** ip);
|
||||||
* @param port where to put the port
|
* @param port where to put the port
|
||||||
* @returns the port, or a negative number for an error
|
* @returns the port, or a negative number for an error
|
||||||
*/
|
*/
|
||||||
int multiaddress_get_ip_port(struct MultiAddress* in);
|
int multiaddress_get_ip_port(const struct MultiAddress* in);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
12
multiaddr.c
12
multiaddr.c
|
@ -83,23 +83,23 @@ struct MultiAddress* multiaddress_new_from_string(const char* straddress)//Const
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
int multiaddress_is_ip(struct MultiAddress* in) {
|
int multiaddress_is_ip(const struct MultiAddress* in) {
|
||||||
int byte = in->bytes[0];
|
int byte = in->bytes[0];
|
||||||
|
|
||||||
if (byte == 4 || byte == 41)
|
if (byte == 4 || byte == 41)
|
||||||
return 1;
|
return 1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
int multiaddress_is_ip4(struct MultiAddress* in) {
|
int multiaddress_is_ip4(const struct MultiAddress* in) {
|
||||||
return in->bytes[0] == 4;
|
return in->bytes[0] == 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
int multiaddress_is_ip6(struct MultiAddress* in) {
|
int multiaddress_is_ip6(const struct MultiAddress* in) {
|
||||||
return in->bytes[0] == 41;
|
return in->bytes[0] == 41;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int multiaddress_get_ip_family(struct MultiAddress* in) {
|
int multiaddress_get_ip_family(const struct MultiAddress* in) {
|
||||||
if (in->bytes[0] == 4)
|
if (in->bytes[0] == 4)
|
||||||
return AF_INET;
|
return AF_INET;
|
||||||
if (in->bytes[0] == 41)
|
if (in->bytes[0] == 41)
|
||||||
|
@ -113,7 +113,7 @@ int multiaddress_get_ip_family(struct MultiAddress* in) {
|
||||||
* @param ip where to put the ip address
|
* @param ip where to put the ip address
|
||||||
* @returns true(1) on success, otherwise 0
|
* @returns true(1) on success, otherwise 0
|
||||||
*/
|
*/
|
||||||
int multiaddress_get_ip_address(struct MultiAddress* in, char** ip) {
|
int multiaddress_get_ip_address(const struct MultiAddress* in, char** ip) {
|
||||||
// the incoming address is not what was expected
|
// the incoming address is not what was expected
|
||||||
if (strncmp(in->string, "/ip4/", 5) != 0 && strncmp(in->string, "/ip6/", 5) != 0)
|
if (strncmp(in->string, "/ip4/", 5) != 0 && strncmp(in->string, "/ip6/", 5) != 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -138,7 +138,7 @@ int multiaddress_get_ip_address(struct MultiAddress* in, char** ip) {
|
||||||
* @param port where to put the port
|
* @param port where to put the port
|
||||||
* @returns the port, or a negative number for an error
|
* @returns the port, or a negative number for an error
|
||||||
*/
|
*/
|
||||||
int multiaddress_get_ip_port(struct MultiAddress* in) {
|
int multiaddress_get_ip_port(const struct MultiAddress* in) {
|
||||||
char* ptr = strstr(in->string, "/tcp/");
|
char* ptr = strstr(in->string, "/tcp/");
|
||||||
if (ptr == NULL)
|
if (ptr == NULL)
|
||||||
ptr = strstr(in->string, "/udp/");
|
ptr = strstr(in->string, "/udp/");
|
||||||
|
|
Loading…
Reference in a new issue