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

utils.c File Reference

#include "common.h"
#include <stdlib.h>
#include <string.h>
#include <assert.h>

Functions

int validate_hexstring (char *s)
 check hex string for validity
uint8_t gethalfbyte (uint8_t c)
 Get half byte from hex string representation.
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...".
unsigned hex2bytes (char *s, uint8_t **dest)
 convert string representation of hex value into array of bytes
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.

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.

uint8_t gethalfbyte uint8_t  c  ) 
 

Get half byte from hex string representation.

Parameters:
c character value
Returns:
integer value

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

int validate_hexstring char *  s  ) 
 

check hex string for validity

Parameters:
*s hex string in format "0x..."
Returns:
1 on success, 0 otherwise


Project hosted by: SourceForge.net Logo