Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals  

packets.h File Reference

#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <errno.h>
#include <stdarg.h>
#include "packets_data.h"
#include "conversion.h"

Go to the source code of this file.

Defines

#define DHCP_P_STR_HADDR_SIZE   48
 Maximum number of characters used to represent a hardware address in standard ':' notation (HH:HH:HH:HH:HH:HH). Maximum size is 16*2 + 15 + 1 = 48
  • The binary representation is 16 bytes long (maximum). 1 byte is represented by 2 hexa characters. So, we have 16*2 hexa characters.
  • Each couple of 2 hexa characters is separated by a ':' character. So we need 15 characters ':'.
  • We add 1 byte for the terminal zero.
.


#define DHCP_P_STR_HADDR_SIZE_EXACT   33
 Maximum number of characters used to represent a hardware address in hexa (without ':' separators). Maximum size is 16*2 + 1 = 33
  • The binary representation is 16 bytes long (maximum). 1 byte is represented by 2 hexa characters. So, we have 16*2 hexa characters.
  • We add 1 byte for the terminal zero.
.


#define DHCP_P_STR_SNAME_SIZE   65
 Maximum number of characters used to represent the field 'sname' of a DHCP packet. The size of the field 'sname' of a DHCP packet is 64 bytes. We add one byte for the terminal zero.

#define DHCP_P_STR_FILE_SIZE   129
 Maximum number of characters used to represent the field 'file' of a DHCP packet. The size of the field 'file' of a DHCP packet is 128 bytes. We add one byte for the terminal zero.

#define OPTIONS_OPTION_VALUE_SIZE   256
 Size, in bytes, for the option's value.


Functions

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

void packets_clear (struct dhcp_packet *p)
 Clear the content of a packet and intialize it for read/write option. More...

void packets_set_op (struct dhcp_packet *p, int op)
 Set the packet's opcode. More...

void packets_set_htype (struct dhcp_packet *p, int htype)
 Set the type of hardware address (field 'htype'). More...

void packets_set_hlen (struct dhcp_packet *p, int hlen)
 Set the length of the binary representation of the hardware address (field 'hlen'). More...

void packets_set_hops (struct dhcp_packet *p, int hops)
 Set the number of hops (field 'hops'). More...

void packets_set_xid (struct dhcp_packet *p, unsigned long int xid)
 Set the transaction ID (field 'xid'). More...

void packets_set_secs (struct dhcp_packet *p, unsigned short int secs)
 Set the number of seconds (field 'secs'). More...

void packets_set_flags (struct dhcp_packet *p, unsigned short int flags)
 Set the packet's flags (field (flags'). More...

int packets_set_ciaddr (struct dhcp_packet *p, char *ciaddr)
 Set the client's IP address (field 'ciaddr'). More...

void packets_set_bin_ciaddr (struct dhcp_packet *p, unsigned long int ciaddr)
 Set the client's IP address (field 'ciaddr'). The field 'ciaddr' is given as an unsigned long integer in network byte order. More...

int packets_set_yiaddr (struct dhcp_packet *p, char *yiaddr)
 Set the field 'Your IP address' (field 'yiaddr'). More...

int packets_set_siaddr (struct dhcp_packet *p, char *siaddr)
 Set the server IP address (field 'siaddr). More...

int packets_set_giaddr (struct dhcp_packet *p, char *giaddr)
 Set the gateway IP address (field 'giaddr'). More...

void packets_set_bin_giaddr (struct dhcp_packet *p, unsigned long int giaddr)
 Set the gateway IP address (field 'giaddr'). The IP address is given as 4 bytes entity in network byte order. More...

void packets_set_chaddr (struct dhcp_packet *p, char *chaddr)
 Set the client hardware address (field 'chaddr'). More...

void packets_set_sname (struct dhcp_packet *p, char *sname)
 Set the server name (field 'sname'). More...

void packets_set_file (struct dhcp_packet *p, char *file)
 Set the boot file (field 'file'). More...

unsigned char packets_get_op (struct dhcp_packet *p)
 Get the packet's opcode. More...

unsigned char packets_get_htype (struct dhcp_packet *p)
 Get the type of hardware address (field 'htype'). More...

unsigned char packets_get_hlen (struct dhcp_packet *p)
 Get the length of the binary representation of the hardware address (field 'hlen'). More...

unsigned char packets_get_hops (struct dhcp_packet *p)
 Get the number of hops (field 'hops'). More...

unsigned long int packets_get_xid (struct dhcp_packet *p)
 Get the transaction ID (field 'xid'. More...

unsigned short int packets_get_secs (struct dhcp_packet *p)
 Get the number of seconds (field 'secs'). More...

unsigned short int packets_get_flags (struct dhcp_packet *p)
 Get the packet's flags (field (flags'). More...

char * packets_get_ciaddr (struct dhcp_packet *p)
 Get the client's IP address (field 'ciaddr'). More...

unsigned long int packets_get_bin_ciaddr (struct dhcp_packet *p)
 Get the client's IP address (field 'ciaddr') as a 4 bytes integer in network byte order. More...

char * packets_get_yiaddr (struct dhcp_packet *p)
 Get the field 'yiaddr' ("Your IP address"). More...

char * packets_get_siaddr (struct dhcp_packet *p)
 Get the server IP address (field 'siaddr). More...

char * packets_get_giaddr (struct dhcp_packet *p)
 Get the gateway IP address (field 'giaddr'). More...

unsigned long int packets_get_bin_giaddr (struct dhcp_packet *p)
 Get the gateway IP address (field 'giaddr'). IP address is returned as a 4 bytes integer in network byte order. More...

char * packets_get_chaddr (struct dhcp_packet *p)
 Get the client hardware address (field 'chaddr'). More...

char * packets_get_chaddr_no_separator (struct dhcp_packet *p)
 Return a literal representation of the client hardware address. This function is identical to the function packets_get_chaddr(), except that the returned string does not contain ':'. More...

char * packets_get_bin_chaddr (struct dhcp_packet *p)
 Get the client hardware address (field 'chaddr'). The hardware address is returned as RAW buffer. More...

char * packets_get_sname (struct dhcp_packet *p)
 Get the server name (field 'sname'). More...

char * packets_get_file (struct dhcp_packet *p)
 Get the path to the boot file (field 'file'). More...

char * packets_get_node_id (struct dhcp_packet *p)
 Return a zero terminated string of characters the represents the DSLAM's node ID from the option 82. More...

unsigned char packets_get_shelf (struct dhcp_packet *p)
 Return the DSLAM's shelf from the option 82. More...

unsigned char packets_get_numero_slot (struct dhcp_packet *p)
 Return the DSLAM's slot number from the option 82. More...

unsigned char packets_get_numero_port (struct dhcp_packet *p)
 Return the DSLAM's port number from the option 82. More...

unsigned short int packets_get_vci (struct dhcp_packet *p)
 Return the DSLAM's VCI from the option 82. More...

unsigned short int packets_get_vlan_id (struct dhcp_packet *p)
 Return the DSLAM's VLAN ID from the option 82. More...

void packets_init_option_writer (struct dhcp_packet *p)
 Initialize the packet's data before writing options. More...

void packets_options_clear (struct dhcp_packet *p)
 Clear the option's part of a given packet. More...

int packets_set_option (struct dhcp_packet *p, unsigned char option, char *value, int len)
 Set a given DHCP option. More...

void packets_close_option (struct dhcp_packet *p)
 Terminate the option's part cleanly. More...

void packets_init_option_reader (struct dhcp_packet *p)
 Initialize the packet's data before reading options. More...

int packets_parse_options (struct dhcp_packet *p)
 Read options from a given packet. More...

int packets_get_option (struct dhcp_packet *p, int option, int *len, unsigned char **value)
 Get a specific option. More...

int packets_get_message_type (struct dhcp_packet *p)
 Get the type of packet (value of option 53 (DHCP Message Type). More...

char * packets_get_subnet_mask (struct dhcp_packet *p)
 Get the subnet mask associated with a given packet. More...

void packet_init_dump_service ()
 Initialize the dump service for DHCP packets. More...

int packet_dump (struct dhcp_packet *p, char *file, char *csv, struct sockaddr_in *from, struct sockaddr_in *to)
 Dump the DHCP packet in a file (in human readable format). More...

int check_packet_size (int size)
 Check the size of a packet. More...

void packet_set_taille (struct dhcp_packet *p, int taille)
 Set the total size of a packet. More...

char * packets_type_to_char (int type)
 Returns a string that describes the type of DHCP packet. More...


Detailed Description

Header file for the low level DHCP packet manipulation module (packet.c).

Definition in file packets.h.


Function Documentation

int check_packet_size int    size
 

Check the size of a packet.

Author:
Denis BEURIVE
Parameters:
size  Size of the packet.
Returns:
If the size of the packet is valid, the function returns 1. Otherwize, it returns 0.

Definition at line 2310 of file packets.c.

Referenced by main().

int packet_dump struct dhcp_packet   p,
char *    file,
char *    csv,
struct sockaddr_in *    from,
struct sockaddr_in *    to
 

Dump the DHCP packet in a file (in human readable format).

Author:
Denis BEURIVE
Parameters:
p  Pointer to the packet.
file  Path to the output file.
csv  Path to the CSV file.
from  Internet address of the sender. If NULL, then a character '-' is printed.
to  Internet address of the addressee. If NULL, then a character '-' is printed.
Returns:
Upon successful completion, the function returns the value 0. Otherwise, it returns the value 1.
Warning:
If the function could not allocate memory, it calls the function "exit()" with status value 1. You must call packet_init_dump_service() before you can use this function.

Definition at line 1749 of file packets.c.

References BUFFER_SIZE, dhcp_packet::ctrl, dater(), debug, descriptions, DSLAM_ALCATEL, DSLAM_UTSTARCOM, dump_sync_fd, file, get_doted_ip(), get_remote_address(), int_to_char(), lock_file(), log_file, my_syslog(), myhostname, order, packets_get_chaddr(), packets_get_ciaddr(), packets_get_file(), packets_get_flags(), packets_get_giaddr(), packets_get_hlen(), packets_get_hops(), packets_get_htype(), packets_get_message_type(), packets_get_op(), packets_get_secs(), packets_get_siaddr(), packets_get_sname(), packets_get_xid(), packets_get_yiaddr(), packets_parse_options(), packets_type_to_char(), and unlock_file().

Referenced by main(), packets_send_ack(), packets_send_nack(), packets_send_offer(), and reply_to_inform().

void packet_init_dump_service  
 

Initialize the dump service for DHCP packets.

Remarks:
The function MUSR be called before any call to packet_dump().

Definition at line 120 of file packets.c.

References myhostname.

Referenced by main().

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

Assign a logging service to the packet 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 given 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 69 of file packets.c.

References debug, file, log_file, and my_syslog.

Referenced by main().

void packet_set_taille struct dhcp_packet   p,
int    taille
 

Set the total size of a packet.

Author:
Denis BEURIVE
Parameters:
p  Pointer to the packet.
taille  Total size of the packet.
Warning:
You MUST call this function just after you receive the packet from the network (after the call to recvfrom().

Definition at line 2332 of file packets.c.

References dhcp_packet::ctrl.

Referenced by main().

void packets_clear struct dhcp_packet   p
 

Clear the content of a packet and intialize it for read/write option.

Author:
Denis BEURIVE
Parameters:
p  Pointer to the packet to clear.

Definition at line 490 of file packets.c.

References PACKET_SIZE, packets_init_option_reader(), and packets_init_option_writer().

Referenced by main(), packets_send_ack(), packets_send_nack(), packets_send_offer(), and reply_to_inform().

void packets_close_option struct dhcp_packet   p
 

Terminate the option's part cleanly.

Author:
Denis BEURIVE
Parameters:
p  Pointer to the packet.
Warning:
You MUST call this function when you don't need to write any more option. The proper way to operate is:
You must call packets_init_option_writer() before! The proper way to operate is:

Definition at line 988 of file packets.c.

References dhcp_packet::ctrl.

Referenced by packets_send_ack(), packets_send_nack(), packets_send_offer(), and reply_to_inform().

char* packets_get_bin_chaddr struct dhcp_packet   p
 

Get the client hardware address (field 'chaddr'). The hardware address is returned as RAW buffer.

Author:
Denis BEURIVE
Parameters:
p  Pointer to the packet.
Warning:
The RAW buffer is returned in a statically allocated buffer that points to the packet's data pointed by 'p'! Do NOT modify it!.

Definition at line 893 of file packets.c.

References dhcp_packet::chaddr.

Referenced by packets_send_ack(), packets_send_nack(), packets_send_offer(), and reply_to_inform().

unsigned long int packets_get_bin_ciaddr struct dhcp_packet   p
 

Get the client's IP address (field 'ciaddr') as a 4 bytes integer in network byte order.

Author:
Denis BEURIVE
Parameters:
p  Pointer to the packet.
Returns:
The function returns a 4 bytes long integer in network byte order that represents thet IP address (field 'ciaddr').

Definition at line 678 of file packets.c.

References dhcp_packet::ciaddr.

Referenced by packets_send_ack(), packets_send_nack(), and reply_to_inform().

unsigned long int packets_get_bin_giaddr struct dhcp_packet   p
 

Get the gateway IP address (field 'giaddr'). IP address is returned as a 4 bytes integer in network byte order.

Author:
Denis BEURIVE
Parameters:
p  Pointer to the packet.
Returns:
The function returns the IP address that represents the field 'giaddr'.

Definition at line 808 of file packets.c.

References dhcp_packet::giaddr.

Referenced by packets_send_ack(), packets_send_nack(), packets_send_offer(), and reply_to_inform().

char* packets_get_chaddr struct dhcp_packet   p
 

Get the client hardware address (field 'chaddr').

Author:
Denis BEURIVE
Parameters:
p  Pointer to the packet.
Returns:
The function returns a zero terminated string of characters that represents the hardware address of the client in standard ':' 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 829 of file packets.c.

References chaddr, dhcp_packet::chaddr, DHCP_P_STR_HADDR_SIZE, int_to_char(), and packets_get_hlen().

Referenced by main(), and packet_dump().

char* packets_get_chaddr_no_separator struct dhcp_packet   p
 

Return a literal representation of the client hardware address. This function is identical to the function packets_get_chaddr(), except that the returned string does not contain ':'.

Author:
Denis BEURIVE
Parameters:
p  Pointer to the packet.
Returns:
The function returns a zero terminated string of characters that represents the hardware address of the client.
Warning:
The string is returned in a statically allocated buffer, which subsequent calls will overwrite. Do not try to free it!

Definition at line 863 of file packets.c.

References dhcp_packet::chaddr, chaddr_exact, DHCP_P_STR_HADDR_SIZE_EXACT, int_to_char(), and packets_get_hlen().

char* packets_get_ciaddr struct dhcp_packet   p
 

Get the client's IP address (field 'ciaddr').

Author:
Denis BEURIVE
Parameters:
p  Pointer to the packet.
Returns:
The function return a pointer to a zero terminated string of characters that represents the IP address of the client 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 661 of file packets.c.

References dhcp_packet::ciaddr.

Referenced by packet_dump().

char* packets_get_file struct dhcp_packet   p
 

Get the path to the boot file (field 'file').

Author:
Denis BEURIVE
Parameters:
p  Pointer to the packet.
Returns:
The function returns a zero terminated string of characters that represents the pat to the boot file.
Warning:
The string is returned in a statically allocated buffer, which subsequent calls will overwrite. Do not try to free it!

Definition at line 933 of file packets.c.

References DHCP_P_STR_FILE_SIZE, dhcp_packet::file, and file.

Referenced by packet_dump().

unsigned short int packets_get_flags struct dhcp_packet   p
 

Get the packet's flags (field (flags').

Author:
Denis BEURIVE
Parameters:
p  Pointer to the packet.
Returns:
The function returns the packet's flags (field (flags').

Definition at line 622 of file packets.c.

References dhcp_packet::flags.

Referenced by packet_dump(), packets_send_ack(), packets_send_nack(), packets_send_offer(), and reply_to_inform().

char* packets_get_giaddr struct dhcp_packet   p
 

Get the gateway IP address (field 'giaddr').

Author:
Denis BEURIVE
Parameters:
p  Pointer to the packet.
Returns:
The function returns a pointer to a zero terminated string of characters 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 791 of file packets.c.

References dhcp_packet::giaddr.

Referenced by packet_dump().

unsigned char packets_get_hlen struct dhcp_packet   p
 

Get the length of the binary representation of the hardware address (field 'hlen').

Author:
Denis BEURIVE
Parameters:
p  Pointer to the packet.
Returns:
The function returns the length of the binary representation of the hardware address (field 'hlen').

Definition at line 558 of file packets.c.

References dhcp_packet::hlen.

Referenced by packet_dump(), packets_get_chaddr(), packets_get_chaddr_no_separator(), packets_send_ack(), packets_send_nack(), packets_send_offer(), and reply_to_inform().

unsigned char packets_get_hops struct dhcp_packet   p
 

Get the number of hops (field 'hops').

Author:
Denis BEURIVE
Parameters:
p  Pointer to the packet.
Returns:
The function returns the number of hops (field 'hops').

Definition at line 574 of file packets.c.

References dhcp_packet::hops.

Referenced by packet_dump().

unsigned char packets_get_htype struct dhcp_packet   p
 

Get the type of hardware address (field 'htype').

Author:
Denis BEURIVE
Parameters:
p  Pointer to the packet.
Returns:
The function returns the type of hardware address (field 'htype').

Definition at line 542 of file packets.c.

References dhcp_packet::htype.

Referenced by packet_dump(), packets_send_ack(), packets_send_nack(), packets_send_offer(), and reply_to_inform().

int packets_get_message_type struct dhcp_packet   p
 

Get the type of packet (value of option 53 (DHCP Message Type).

Author:
Denis BEURIVE
Parameters:
p  Pointer to the packet.
Returns:
Upon successful completion, the function returns the numerical representation of the message type. This could be:
  • DHCPDISCOVER (1)
  • DHCPOFFER (2)
  • DHCPREQUEST (3)
  • DHCPDECLINE (4)
  • DHCPACK (5)
  • DHCPNAK (6)
  • DHCPRELEASE (7)
  • DHCPINFORM (8)
If an error occured, the function returns the value -1.
Warning:
You must call packets_parse_options() first. The proper way to operate is:

Definition at line 1592 of file packets.c.

References packets_get_option().

Referenced by find_ip_and_reply(), look_up_logistic(), main(), and packet_dump().

char* packets_get_node_id struct dhcp_packet   p
 

Return a zero terminated string of characters the represents the DSLAM's node ID from the option 82.

Author:
Denis BEURIVE
Parameters:
p  Pointer to the packet.
Returns:
The function returns the DSLAM's node ID.
Warning:
You must call packets_parse_options() first. The proper way to operate is:

Definition at line 1643 of file packets.c.

References dhcp_packet::ctrl.

Referenced by main().

unsigned char packets_get_numero_port struct dhcp_packet   p
 

Return the DSLAM's port number from the option 82.

Author:
Denis BEURIVE
Parameters:
p  Pointer to the packet.
Returns:
The function returns the DSLAM's port number.
Warning:
You must call packets_parse_options() first. The proper way to operate is:

Definition at line 1711 of file packets.c.

References dhcp_packet::ctrl.

Referenced by main().

unsigned char packets_get_numero_slot struct dhcp_packet   p
 

Return the DSLAM's slot number from the option 82.

Author:
Denis BEURIVE
Parameters:
p  Pointer to the packet.
Returns:
The function returns the DSLAM's slot number.
Warning:
You must call packets_parse_options() first. The proper way to operate is:

Definition at line 1677 of file packets.c.

References dhcp_packet::ctrl.

Referenced by main().

unsigned char packets_get_op struct dhcp_packet   p
 

Get the packet's opcode.

Author:
Denis BEURIVE
Parameters:
p  Pointer to the packet.
Returns:
The function returns the packet's opcode.

Definition at line 526 of file packets.c.

References dhcp_packet::op.

Referenced by packet_dump().

int packets_get_option struct dhcp_packet   p,
int    option,
int *    len,
unsigned char **    value
 

Get a specific option.

Author:
Denis BEURIVE
Parameters:
p  Pointer to the packet.
option  Option's code (value between 1 and 254 included).
len  Pointer to an integer used to store the size of the option's value.
value  Pointer to a pointer that will point to the option's value.
Returns:
Upon successful completion, the function returns the value 0. Otherwize, the function returns the value 1.
Warning:
You must call packets_parse_options() first. The proper way to operate is:

Definition at line 1557 of file packets.c.

References dhcp_packet::ctrl.

Referenced by packets_get_message_type(), and packets_get_subnet_mask().

unsigned short int packets_get_secs struct dhcp_packet   p
 

Get the number of seconds (field 'secs').

Author:
Denis BEURIVE
Parameters:
p  Pointer to the packet.
Returns:
The function returns the number of seconds (field 'secs').

Definition at line 606 of file packets.c.

References dhcp_packet::secs.

Referenced by packet_dump(), packets_send_ack(), packets_send_nack(), packets_send_offer(), and reply_to_inform().

unsigned char packets_get_shelf struct dhcp_packet   p
 

Return the DSLAM's shelf from the option 82.

Author:
Denis BEURIVE
Parameters:
p  Pointer to the packet.
Returns:
The function returns the DSLAM's shelf.
Warning:
You must call packets_parse_options() first. The proper way to operate is:

Definition at line 1660 of file packets.c.

References dhcp_packet::ctrl.

Referenced by main().

char* packets_get_siaddr struct dhcp_packet   p
 

Get the server IP address (field 'siaddr).

Author:
Denis BEURIVE
Parameters:
p  Pointer to the packet.
Returns:
The function returns a pointer to a zero terminated string of characters 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 745 of file packets.c.

References dhcp_packet::siaddr.

Referenced by packet_dump().

char* packets_get_sname struct dhcp_packet   p
 

Get the server name (field 'sname').

Author:
Denis BEURIVE
Parameters:
p  Pointer to the packet.
Returns:
The function returns a zero terminated string of characters that represents name of the server.
Warning:
The string is returned in a statically allocated buffer, which subsequent calls will overwrite. Do not try to free it!

Definition at line 911 of file packets.c.

References DHCP_P_STR_SNAME_SIZE, dhcp_packet::sname, and sname.

Referenced by packet_dump().

char* packets_get_subnet_mask struct dhcp_packet   p
 

Get the subnet mask associated with a given packet.

Author:
Denis BEURIVE
Parameters:
p  Pointer to the packet.
Returns:
Upon successful completion, the function returns a non NULL pointer to a zero terminated string of characters that represents the network mask. Otherwise the function returns the value NULL.
Warning:
The returned string can only be used until the next call to packets_get_subnet_mask(). The string is returned in a statically allocated buffer, which subsequent calls will overwrite. Do not try to free it!

Definition at line 1613 of file packets.c.

References OPTIONS_OPTION_VALUE_SIZE, and packets_get_option().

unsigned short int packets_get_vci struct dhcp_packet   p
 

Return the DSLAM's VCI from the option 82.

Author:
Denis BEURIVE
Parameters:
p  Pointer to the packet.
Returns:
The function returns the DSLAM's VCI.
Warning:
You must call packets_parse_options() first. The proper way to operate is:

Definition at line 1694 of file packets.c.

References dhcp_packet::ctrl.

Referenced by main().

unsigned short int packets_get_vlan_id struct dhcp_packet   p
 

Return the DSLAM's VLAN ID from the option 82.

Author:
Denis BEURIVE
Parameters:
p  Pointer to the packet.
Returns:
The function returns the DSLAM's VLAN ID.
Warning:
You must call packets_parse_options() first. The proper way to operate is:

Definition at line 1728 of file packets.c.

References dhcp_packet::ctrl.

Referenced by find_ip_and_reply(), and main().

unsigned long int packets_get_xid struct dhcp_packet   p
 

Get the transaction ID (field 'xid'.

Author:
Denis BEURIVE
Parameters:
p  Pointer to the packet.
Returns:
The function returns the transaction ID (field 'xid').

Definition at line 590 of file packets.c.

References dhcp_packet::xid.

Referenced by main(), packet_dump(), packets_send_ack(), packets_send_nack(), packets_send_offer(), and reply_to_inform().

char* packets_get_yiaddr struct dhcp_packet   p
 

Get the field 'yiaddr' ("Your IP address").

Author:
Denis BEURIVE
Parameters:
p  Pointer to the packet.
Returns:
The function returns a pointer to a zero terminated string of characters 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 708 of file packets.c.

References dhcp_packet::yiaddr.

Referenced by packet_dump().

void packets_init_option_reader struct dhcp_packet   p
 

Initialize the packet's data before reading options.

Author:
Denis BEURIVE
Parameters:
p  Pointer to the packet to initialize.
Warning:
You must always call this function before calling packets_parse_options(). Note that packets_clear() calls packets_init_option_reader().

Definition at line 467 of file packets.c.

References dhcp_packet::ctrl, dhcp_packet::options, and VALUE_MAX_SIZE.

Referenced by packets_clear(), and packets_parse_options().

void packets_init_option_writer struct dhcp_packet   p
 

Initialize the packet's data before writing options.

Author:
Denis BEURIVE
Parameters:
p  Pointer to the packet to initialize.
Warning:
You must always call this function before calling packets_set_option(). Once you have set all the options you want to set, then you must call packets_close_option(). The shema is:

Definition at line 446 of file packets.c.

References dhcp_packet::ctrl, and dhcp_packet::options.

Referenced by packets_clear().

void packets_options_clear struct dhcp_packet   p
 

Clear the option's part of a given packet.

Author:
Denis BEURIVE
Parameters:
p  Pointer to the packet that you want to clear the option's part.

Definition at line 502 of file packets.c.

References OPTION_SIZE, and dhcp_packet::options.

int packets_parse_options struct dhcp_packet   p
 

Read options from a given packet.

Author:
Denis BEURIVE
Parameters:
p  Pointer to the packet.
Returns:
Upon successful completion, the function returns the value 0. Otherwise, the function returns the value 1.
Warning:
You MUST call packets_init_option_reader() first!

Definition at line 1002 of file packets.c.

References dhcp_packet::ctrl, debug, DSLAM_ALCATEL, DSLAM_UNKNOWN, DSLAM_UTSTARCOM, m_dhcp82::length, log_file, my_syslog(), m_dhcp82::nas_ip, m_dhcp82::nas_mac, NODE_BUFFER_SIZE, m_dhcp82::node_id, m_dhcp82::numero_port, m_dhcp82::numero_slot, OPTION_SIZE, packets_init_option_reader(), m_dhcp82::port_type, m_dhcp82::shelf, m_dhcp82::sub_option, VALUE_MAX_SIZE, m_dhcp82::vci, vci, m_dhcp82::vendor_id, m_dhcp82::version, m_dhcp82::vlan_id, and m_dhcp82::vpi.

Referenced by main(), and packet_dump().

void packets_set_bin_ciaddr struct dhcp_packet   p,
unsigned long int    ciaddr
 

Set the client's IP address (field 'ciaddr'). The field 'ciaddr' is given as an unsigned long integer in network byte order.

Author:
Denis BEURIVE
Parameters:
p  Pointer to the packet.
ciaddr  IP address of the client in RAW format (4 bytes in network byte order).

Definition at line 649 of file packets.c.

References dhcp_packet::ciaddr.

Referenced by packets_send_ack(), packets_send_nack(), and reply_to_inform().

void packets_set_bin_giaddr struct dhcp_packet   p,
unsigned long int    giaddr
 

Set the gateway IP address (field 'giaddr'). The IP address is given as 4 bytes entity in network byte order.

Author:
Denis BEURIVE
Parameters:
p  Pointer to the packet.
giaddr  4 bytes in network byte order that represents an IP address.

Definition at line 780 of file packets.c.

References dhcp_packet::giaddr.

Referenced by packets_send_ack(), packets_send_nack(), packets_send_offer(), and reply_to_inform().

void packets_set_chaddr struct dhcp_packet   p,
char *    chaddr
 

Set the client hardware address (field 'chaddr').

Author:
Denis BEURIVE
Parameters:
p  Pointer to the packet.
chaddr  Pointer to 16 bytes long buffer that represents the binary representation of the client's hardware address.
Warning:
If the client hardware address is only 6 bytes long, the 10 last bytes must be set to 0.

Definition at line 818 of file packets.c.

References dhcp_packet::chaddr, and chaddr.

Referenced by packets_send_ack(), packets_send_nack(), packets_send_offer(), and reply_to_inform().

int packets_set_ciaddr struct dhcp_packet   p,
char *    ciaddr
 

Set the client's IP address (field 'ciaddr').

Author:
Denis BEURIVE
Parameters:
p  Pointer to the packet.
ciaddr  Pointer to a zero terminated string of characters that represents the IP address of the client in standard numbers-and-dots notation.
Returns:
If the IP address is valid, the function returns the value 0. Otherwize, the function returns the value 1.

Definition at line 632 of file packets.c.

References dhcp_packet::ciaddr.

void packets_set_file struct dhcp_packet   p,
char *    file
 

Set the boot file (field 'file').

Author:
Denis BEURIVE
Parameters:
p  Pointer to the packet.
file  Pointer to a zero terminated string that represents the path to the boot file.

Definition at line 924 of file packets.c.

References DHCP_P_STR_FILE_SIZE, dhcp_packet::file, and file.

void packets_set_flags struct dhcp_packet   p,
unsigned short int    flags
 

Set the packet's flags (field (flags').

Author:
Denis BEURIVE
Parameters:
p  Pointer to the packet.
flags  Flags.

Definition at line 614 of file packets.c.

References dhcp_packet::flags.

Referenced by packets_send_ack(), packets_send_nack(), packets_send_offer(), and reply_to_inform().

int packets_set_giaddr struct dhcp_packet   p,
char *    giaddr
 

Set the gateway IP address (field 'giaddr').

Author:
Denis BEURIVE
Parameters:
p  Pointer to the packet.
giaddr  Pointer to a zero terminated string of characters that represents the IP address in standard numbers-and-dots notation.
Returns:
If the IP address is valid, the function returns the value 0. Otherwize, the function returns the value 1.

Definition at line 763 of file packets.c.

References dhcp_packet::giaddr.

void packets_set_hlen struct dhcp_packet   p,
int    hlen
 

Set the length of the binary representation of the hardware address (field 'hlen').

Author:
Denis BEURIVE
Parameters:
p  Pointer to the packet.
hlen  Lenght, in bytes, of the binary representation of the hardware address.

Definition at line 550 of file packets.c.

References dhcp_packet::hlen.

Referenced by packets_send_ack(), packets_send_nack(), packets_send_offer(), and reply_to_inform().

void packets_set_hops struct dhcp_packet   p,
int    hops
 

Set the number of hops (field 'hops').

Author:
Denis BEURIVE
Parameters:
p  Pointer to the packet.
hops  Number of hops.

Definition at line 566 of file packets.c.

References dhcp_packet::hops.

Referenced by packets_send_ack(), packets_send_nack(), packets_send_offer(), and reply_to_inform().

void packets_set_htype struct dhcp_packet   p,
int    htype
 

Set the type of hardware address (field 'htype').

Author:
Denis BEURIVE
Parameters:
p  Pointer to the packet.
htype  Value that represents the type of hardware address.

Definition at line 534 of file packets.c.

References dhcp_packet::htype.

Referenced by packets_send_ack(), packets_send_nack(), packets_send_offer(), and reply_to_inform().

void packets_set_op struct dhcp_packet   p,
int    op
 

Set the packet's opcode.

Author:
Denis BEURIVE
Parameters:
p  Pointer to the packet.
op  Valur of the opcode (should be 1 or 2).

Definition at line 518 of file packets.c.

References dhcp_packet::op.

Referenced by packets_send_ack(), packets_send_nack(), packets_send_offer(), and reply_to_inform().

int packets_set_option struct dhcp_packet   p,
unsigned char    option,
char *    value,
int    len
 

Set a given DHCP option.

Author:
Denis BEURIVE
Parameters:
p  Pointer to the packet.
option  Option's code (from 1 to 254 included).
value  Pointer to a buffer that contains tha binary representation of the option's value.
len  Number of bytes for the buffer pointed by 'value'.
Returns:
Upon successful completion, the function returns the value 0. Otherwize, it returns the value 1.
Warning:
You must call packets_init_option_writer() before! The proper way to operate is:

Definition at line 955 of file packets.c.

References dhcp_packet::ctrl, and VALUE_MAX_SIZE.

Referenced by packets_send_ack(), packets_send_nack(), packets_send_offer(), and reply_to_inform().

void packets_set_secs struct dhcp_packet   p,
unsigned short int    secs
 

Set the number of seconds (field 'secs').

Author:
Denis BEURIVE
Parameters:
p  Pointer to the packet.
secs  Number of seconds.

Definition at line 598 of file packets.c.

References dhcp_packet::secs.

Referenced by packets_send_ack(), packets_send_nack(), packets_send_offer(), and reply_to_inform().

int packets_set_siaddr struct dhcp_packet   p,
char *    siaddr
 

Set the server IP address (field 'siaddr).

Author:
Denis BEURIVE
Parameters:
p  Pointer to the packet.
siaddr  Pointer to a zero terminated string of characters that represents the IP address in standard numbers-and-dots notation.
Returns:
If the IP address is valid, the function returns the value 0. Otherwize, the function returns the value 1.

Definition at line 726 of file packets.c.

References dhcp_packet::siaddr.

Referenced by packets_send_ack(), packets_send_nack(), packets_send_offer(), and reply_to_inform().

void packets_set_sname struct dhcp_packet   p,
char *    sname
 

Set the server name (field 'sname').

Author:
Denis BEURIVE
Parameters:
p  Pointer to the packet.
sname  Pointer to a sero terminated string that represents the name of the server.

Definition at line 902 of file packets.c.

References DHCP_P_STR_SNAME_SIZE, dhcp_packet::sname, and sname.

void packets_set_xid struct dhcp_packet   p,
unsigned long int    xid
 

Set the transaction ID (field 'xid').

Author:
Denis BEURIVE
Parameters:
p  Pointer to the packet.
xid  Transaction ID.

Definition at line 582 of file packets.c.

References dhcp_packet::xid.

Referenced by packets_send_ack(), packets_send_nack(), packets_send_offer(), and reply_to_inform().

int packets_set_yiaddr struct dhcp_packet   p,
char *    yiaddr
 

Set the field 'Your IP address' (field 'yiaddr').

Author:
Denis BEURIVE
Parameters:
p  Pointer to the packet.
yiaddr  Pointer to a zero terminated string of characters that represents the IP address in standard numbers-and-dots notation.
Returns:
If the IP address is valid, the function returns the value 0. Otherwize, the function returns the value 1.

Definition at line 689 of file packets.c.

References dhcp_packet::yiaddr.

Referenced by packets_send_ack(), packets_send_nack(), and packets_send_offer().

char* packets_type_to_char int    type
 

Returns a string that describes the type of DHCP packet.

Author:
Denis BEURIVE
Parameters:
type  Value of the option 53 (DHCP Message Type).
Returns:
The function returns a pointer to a zero terminated string that represents the type of the packet.
Warning:
The string is returned in a statically allocated buffer, which subsequent calls will overwrit. Do not try to free it!

Definition at line 405 of file packets.c.

References DHCPACK, DHCPDECLINE, DHCPDISCOVER, DHCPINFORM, DHCPNAK, DHCPOFFER, DHCPRELEASE, and DHCPREQUEST.

Referenced by packet_dump().


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