Main Page | Data Structures | File List | Data Fields | Globals | Related Pages

utils.h File Reference

#include "common.h"

Go to the source code of this file.

Defines

#define STRINGIFY(x)   # x
#define TOSTRING(x)   STRINGIFY(x)
#define hton64(x)   ((uint64_t)((htonl(((uint32_t)((x)>>32)&0xFFFFFFFF))))|((uint64_t)(htonl((uint32_t)((x)&0xFFFFFFFF)))<<32))
#define ntoh64(x)   ((uint64_t)((ntohl(((uint32_t)((x)>>32)&0xFFFFFFFF))))|((uint64_t)(ntohl((uint32_t)((x)&0xFFFFFFFF)))<<32))
#define Attribute_GetType(x)   ((x)>>1)
#define Attribute_GetHF(x)   ((x)&1)
#define Attribute_GetTypeHF(x, y)   (((x)<<1)|((y)&1))
#define hextobin(x)   ((x)>'9'?((x)>'Z'?(((x)-0x27)&0x0F):(((x)-0x07)&0x0F)):((x)&0x0F))
#define ishex(x)   ((((x)>='0')&&((x)<='9'))||(((x)>='A')&&((x)<='Z'))||(((x)>='a')&&((x)<='z')))

Functions

unsigned hex2bytes (char *s, uint8_t **dest)
 convert string representation of hex value into array of bytes
const char * bin2str (const uint8_t *data, uint32_t len)
 Create printable representation of byte string. If data in set are ASCII characters, then representation is given string, else the format is "0x...".
void hexalize (uint8_t **data, unsigned *len)
 If data passed to function are in format "0x..." then convert such valu to correspondig byte array, else leave text string.
BIGNUM * HexToBignum (const uint8_t *hex, uint32_t len)
 Convert a hex representation to BIGNUM.
uint8_t * Clone (const uint8_t *data, uint32_t len)
 Clone a buffer.
void PrintBuffer (unsigned char *buf, unsigned long len)
 Print a binary buffer in hex string format.
void PrintBignum (const BIGNUM *a)
uint32_t StringToIP (char *str_ip)
 Convert IP address from string to binary format e.g. 1.2.34 --> 0x04030201.
char * IPToString (uint32_t ip)
 Convert an IP addr from binary format to string e.g. 0x04030201 --> 1.2.3.4.


Define Documentation

#define Attribute_GetHF  )     ((x)&1)
 

#define Attribute_GetType  )     ((x)>>1)
 

#define Attribute_GetTypeHF x,
 )     (((x)<<1)|((y)&1))
 

#define hextobin  )     ((x)>'9'?((x)>'Z'?(((x)-0x27)&0x0F):(((x)-0x07)&0x0F)):((x)&0x0F))
 

#define hton64  )     ((uint64_t)((htonl(((uint32_t)((x)>>32)&0xFFFFFFFF))))|((uint64_t)(htonl((uint32_t)((x)&0xFFFFFFFF)))<<32))
 

#define ishex  )     ((((x)>='0')&&((x)<='9'))||(((x)>='A')&&((x)<='Z'))||(((x)>='a')&&((x)<='z')))
 

#define ntoh64  )     ((uint64_t)((ntohl(((uint32_t)((x)>>32)&0xFFFFFFFF))))|((uint64_t)(ntohl((uint32_t)((x)&0xFFFFFFFF)))<<32))
 

#define STRINGIFY  )     # x
 

#define TOSTRING  )     STRINGIFY(x)
 


Function Documentation

const char* bin2str const uint8_t *  data,
uint32_t  len
 

Create printable representation of byte string. If data in set are ASCII characters, then representation is given string, else the format is "0x...".

Parameters:
data byte string
len length of data
Returns:
pointer to static buffer which contains printable representation of data

uint8_t* Clone const uint8_t *  data,
uint32_t  len
 

Clone a buffer.

Parameters:
*data data to clone
len data length
Returns:
pointer to new allocated memory with copy of data.

unsigned hex2bytes char *  s,
uint8_t **  dest
 

convert string representation of hex value into array of bytes

Parameters:
*s string representation
**dest result array of bytes
Returns:
length of dest

void hexalize uint8_t **  data,
unsigned *  len
 

If data passed to function are in format "0x..." then convert such valu to correspondig byte array, else leave text string.

Parameters:
**data data to convert/result
*len len of result data

BIGNUM* HexToBignum const uint8_t *  hex,
uint32_t  len
 

Convert a hex representation to BIGNUM.

Parameters:
*hex hex representation
len length of hex
Returns:
BIGNUM value of hex

char* IPToString uint32_t  ip  ) 
 

Convert an IP addr from binary format to string e.g. 0x04030201 --> 1.2.3.4.

Parameters:
ip 32-bit value of IP address
Returns:
string representation of IP address

void PrintBignum const BIGNUM *  a  ) 
 

void PrintBuffer unsigned char *  buf,
unsigned long  len
 

Print a binary buffer in hex string format.

Parameters:
*buf buffer
len buffer length

uint32_t StringToIP char *  str_ip  ) 
 

Convert IP address from string to binary format e.g. 1.2.34 --> 0x04030201.

Parameters:
*str_ip string with IP address
Returns:
32-bit value of IP address


Project hosted by: SourceForge.net Logo