c-multiaddr/include/multiaddr/protoutils.h

56 lines
1.5 KiB
C
Raw Normal View History

2016-11-02 16:27:58 +00:00
#ifndef PROTOUTILS
#define PROTOUTILS
2016-11-09 22:53:11 +00:00
//////////////////////////////////////////////////////////
char ASCII2bits(char ch);
void hex2bin (char *dst, char *src, int len);
2016-11-09 22:53:11 +00:00
char bits2ASCII(char b);
2016-11-02 16:27:58 +00:00
void bin2hex (char *dst, char *src, int len);
2016-11-09 22:53:11 +00:00
//////////////////////////////////////////////////////////
2016-11-02 16:27:58 +00:00
//IPv4 VALIDATOR
#define DELIM "."
/* return 1 if string contain only digits, else return 0 */
int valid_digit(char *ip_str);
2016-11-02 16:27:58 +00:00
/* return 1 if IP string is valid, else return 0 */
int is_valid_ipv4(char *ip_str);
2016-11-02 16:27:58 +00:00
//////////////IPv6 Validator
#define MAX_HEX_NUMBER_COUNT 8
int ishexdigit(char ch);
2016-11-02 16:27:58 +00:00
int is_valid_ipv6(char *str);
2016-11-02 16:27:58 +00:00
uint64_t ip2int(const char * ipconvertint);
2016-11-02 16:27:58 +00:00
char * int2ip(int inputintip);
2016-11-02 16:27:58 +00:00
/**
* Unserialize the bytes into a string
* @param results where to put the resultant string
* @param bytes the bytes to unserialize
* @param bytes_size the length of the bytes array
*/
int bytes_to_string(char** results, const uint8_t* bytes, int bytes_size);
2017-04-17 04:46:07 +00:00
/**
* Convert an address string to a byte representation
* @param protocol the protocol to use
* @param incoming the byte array
* @param incoming_size the size of the byte array
* @param results the results
* @param results_size the size of the results
* @returns the results array
*/
char * address_string_to_bytes(struct Protocol *protocol, const char *incoming, size_t incoming_size, char** results, int *results_size);
2016-11-06 01:57:36 +00:00
2017-02-15 15:42:06 +00:00
int string_to_bytes(uint8_t** finalbytes,size_t* realbbsize, const char * strx, size_t strsize);
2016-11-08 11:02:45 +00:00
2016-11-06 01:57:36 +00:00
#endif