Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals  

conversion.c File Reference

#include "conversion.h"

Go to the source code of this file.

Functions

int my_fake_syslog (const char *file, const char *fmt,...)
 This is a handler to a fake loggin service. More...

void conversion_logging_service (int dbg, char *logfile, int(*logger)(const char *file, const char *fmt,...))
 Assign a logging service to the conversion module. More...

char int_to_char (unsigned char c)
 Convert an integer (between 0 and 15 included) into the corresponding hexa character (from 0 to F). More...

unsigned char char_to_int (char c)
 Convert a given hexa character (from '0' to 'F') into the corresponding integer value (from 0 to 15 included). More...

unsigned char * haddr_to_hexa (char *haddr, int *length)
 Convert a hardware address in standard ':' notation into its RAW representation. More...

unsigned long int get_network_ip (char *ip)
 Convert IP address in standard numbers-and-dots notation into binary data (4 bytes in network byte order). More...

char * get_doted_ip (unsigned long int ip)
 Convert IP address in binary representation (4 bytes in network byte order) into standard numbers-and-dots notation. More...

int raw_ips_to_string (unsigned char *buffin, char *buffout, int lenin, int lenout)
 Convert a list of RAW IP addresses (4 bytes in network IP order) into a string representation (standard numbers-and-dots notation separated by characters ':'). More...

int uint32_to_network_byte_order (char *buffer_in, char *buffer_out, int len_out)
 Convert a list of UINT32 into a succession of 4 bytes integers in network byte order. More...

int ip_to_network_byte_order (char *buffer_in, char *buffer_out, int len_out)
 Convert a list of IP addresses into a succession of 4 bytes integers in network byte order. More...

int hexa_to_binary (char *buffer_in, char *buffer_out, int len_out)
 Convert hexa representation into bytes. More...

int ascii_to_binary (char *buffer_in, char *buffer_out, int len_in, int len_out)
 Convert ASCII representation into bytes. More...

int uint16_to_network_byte_order (char *buffer_in, char *buffer_out, int len_out)
 Convert a list of UINT16 into a succession of 2 bytes integers in network byte order. More...


Variables

int debug = 0
 Debug flag.

char default_log_file [] = "\0"
 Default value for the log file (an empty string).

char * log_file = default_log_file
 Pointer to a given zero terminated string of characters that represents the path to the log file.

int(* my_syslog )(const char *file, const char *fmt,...)=my_fake_syslog
 Logging service. by default it is assigned to the fake logging service that does nothing.


Detailed Description

This file contains various functions for converting data from one format to another.

Definition in file conversion.c.


Function Documentation

int ascii_to_binary char *    buffer_in,
char *    buffer_out,
int    len_in,
int    len_out
 

Convert ASCII representation into bytes.

Author:
Denis BEURIVE
Parameters:
buffer_in  Zero terminated string of characters that represents a succession of bytes in ASCII.
buffer_out  Pointer to a buffer that will receive the binary representation.
len_in  Size, in bytes, of the buffer buffer_in.
  • If you set the value of len_in to 0, then the function will consider the exact size of the zero terminated string pointed by buffer_in. In other words, len_in will be set to strlen(buffer_in).
  • If you set the value of len_in to any positive value, then the function will consider the exact number of characters specified by len_in. This feature can be used to add the terminal zero.
len_out  Size, in bytes, of the buffer buffer_out.
Returns:
Upon successful completion, the function returns a positive (>= 0) value. Otherwize, the function returns the value -1. If success, the returned value represents the number of bytes.
Remarks:
If an error occured, look at the log file.

Definition at line 523 of file conversion.c.

References debug, log_file, and my_syslog().

Referenced by add_option_to_profile(), and context2profile().

unsigned char char_to_int char    c
 

Convert a given hexa character (from '0' to 'F') into the corresponding integer value (from 0 to 15 included).

Author:
Denis BEURIVE
Parameters:
c  Hexa character to convert (from '0' to 'F'). Note the c could be [0-9a-fA-F].
Returns:
The function returns the corresponding integer value.

Definition at line 106 of file conversion.c.

Referenced by haddr_to_hexa(), and hexa_to_binary().

void conversion_logging_service int    dbg,
char *    logfile,
int(*    logger)(const char *file, const char *fmt,...)
 

Assign a logging service to the conversion module.

Author:
Denis BEURIVE
Parameters:
dbg  Verbosity level.
logfile  Pointer to a zero terminated string of characters that represents the path to the log file.
logger  Pointer to a guven logging service.
Remarks:
  • If 'logger' is set to NULL, then the logging service is not activated.
  • If 'logfile' is set to NULL, then the logging service is not activated.
  • If 'logfile' points to an empty string, then the logging service is not activated.

Definition at line 48 of file conversion.c.

References debug, log_file, and my_syslog.

Referenced by main().

char * get_doted_ip unsigned long int    ip
 

Convert IP address in binary representation (4 bytes in network byte order) into standard numbers-and-dots notation.

Author:
Denis BEURIVE
Parameters:
ip  Binary representation of the IP address to convert (4 bytes in network byte order).
Returns:
The function returns a zero terminated string that represents the IP address in standard numbers-and-dots notation.
Warning:
The string is returned in a statically allocated buffer, which subsequent calls will overwrite. Do not try to free it!

Definition at line 214 of file conversion.c.

Referenced by create_socket(), packet_dump(), and raw_ips_to_string().

unsigned long int get_network_ip char *    ip
 

Convert IP address in standard numbers-and-dots notation into binary data (4 bytes in network byte order).

Author:
Denis BEURIVE
Parameters:
ip  Pointer to a zero terminated string of characters that represents the IP address to convert.
Returns:
The function returns the binary representation of the IP address (in network byte order).

Definition at line 196 of file conversion.c.

Referenced by ip_to_network_byte_order().

unsigned char* haddr_to_hexa char *    haddr,
int *    length
 

Convert a hardware address in standard ':' notation into its RAW representation.

Author:
Denis BEURIVE
Parameters:
haddr  Pointer to a zero terminated string of characters that represents the hardware address in standard ':' notation.
length  Pointer to an integer that will be used to store the size (in bytes) of the RAW representation.
Returns:
Upon successful completion, the function returns a pointer to the RAW representation. The value pointed by 'lenght' is the number of bytes of the representation. Otherwize, the function returns the value NULL.
Warning:
  • The buffer (which contains the RAW representation) is returned in a statically allocated buffer, which subsequent calls will overwrite. Do not try to free it!
  • The maximum lenth for the RAW representation is 16 bytes.

Definition at line 155 of file conversion.c.

References char_to_int(), debug, log_file, and my_syslog().

int hexa_to_binary char *    buffer_in,
char *    buffer_out,
int    len_out
 

Convert hexa representation into bytes.

Author:
Denis BEURIVE
Parameters:
buffer_in  Zero terminated string of characters that represents a succession of bytes in hexa.
buffer_out  Pointer to a buffer that will receive the binary representation.
len_out  Size, in bytes, of the buffer buffer_out.
Returns:
Upon successful completion, the function returns a positive (>= 0) value. Otherwize, the function returns the value -1. If success, the returned value represents the number of bytes.
Remarks:
If an error occured, look at the log file.

Definition at line 455 of file conversion.c.

References char_to_int(), log_file, and my_syslog().

Referenced by add_option_to_profile(), and context2profile().

char int_to_char unsigned char    c
 

Convert an integer (between 0 and 15 included) into the corresponding hexa character (from 0 to F).

Author:
Denis BEURIVE
Parameters:
c  Integer value to convert (between 0 and 15 included).
Returns:
The function returns the corresponding hexa character.

Definition at line 74 of file conversion.c.

Referenced by packet_dump(), packets_get_chaddr(), and packets_get_chaddr_no_separator().

int ip_to_network_byte_order char *    buffer_in,
char *    buffer_out,
int    len_out
 

Convert a list of IP addresses into a succession of 4 bytes integers in network byte order.

Author:
Denis BEURIVE
Parameters:
buffer_in  Zero terminated string of characters that represents the list of IP addresses (the separator is the ':').
buffer_out  pointer to a buffer that will receive the 4 bytes integers in network byte order.
len_out  Size, in bytes, of the buffer buffer_out.
Returns:
Upon successful completion, the function returns a positive (>= 0) value. Otherwize, the function returns the value -1. If success, the returned value represents the number of IP addresses.
Remarks:
If an error occured, look at the log file.

Definition at line 370 of file conversion.c.

References debug, get_network_ip(), log_file, and my_syslog().

Referenced by add_option_to_profile(), and context2profile().

int my_fake_syslog const char *    file,
const char *    fmt,
...   
[static]
 

This is a handler to a fake loggin service.

Author:
Denis BEURIVE

Definition at line 29 of file conversion.c.

int raw_ips_to_string unsigned char *    buffin,
char *    buffout,
int    lenin,
int    lenout
 

Convert a list of RAW IP addresses (4 bytes in network IP order) into a string representation (standard numbers-and-dots notation separated by characters ':').

Author:
Denis BEURIVE
Parameters:
buffin  Input buffer that contains the list of RAW IP addresses.
buffout  Output buffer that will receive the string representation.
lenin  Size (in bytes) in the input buffer.
lenout  Size (in bytes) in the output buffer.
Returns:
Upon successful completion, the function returns the value 0. Otherwize, the function returns the value 1.

Definition at line 236 of file conversion.c.

References get_doted_ip().

int uint16_to_network_byte_order char *    buffer_in,
char *    buffer_out,
int    len_out
 

Convert a list of UINT16 into a succession of 2 bytes integers in network byte order.

Author:
Denis BEURIVE
Parameters:
buffer_in  Zero terminated string of characters that represents the list of UINT16 (the separator is the ':').
buffer_out  pointer to a buffer that will receive the 2 bytes integers in network byte order.
len_out  Size, in bytes, of the buffer buffer_out.
Returns:
Upon successful completion, the function returns a positive (>= 0) value. Otherwize, the function returns the value -1. If success, the returned value represents the number of UINT16.
Remarks:
If an error occured, look at the log file.

Definition at line 575 of file conversion.c.

References debug, log_file, and my_syslog().

Referenced by add_option_to_profile(), and context2profile().

int uint32_to_network_byte_order char *    buffer_in,
char *    buffer_out,
int    len_out
 

Convert a list of UINT32 into a succession of 4 bytes integers in network byte order.

Author:
Denis BEURIVE
Parameters:
buffer_in  Zero terminated string of characters that represents the list of UINT32 (the separator is the ':').
buffer_out  pointer to a buffer that will receive the 4 bytes integers in network byte order.
len_out  Size, in bytes, of the buffer buffer_out.
Returns:
Upon successful completion, the function returns a positive (>= 0) value. Otherwize, the function returns the value -1. If success, the returned value represents the number of UINT32.
Remarks:
If an error occured, look at the log file.

Definition at line 274 of file conversion.c.

References debug, log_file, and my_syslog().

Referenced by add_option_to_profile(), and context2profile().


Generated on Mon Jun 19 12:31:06 2006 for MyDhcp_V2 by doxygen1.2.15