Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals  

packets.c File Reference

#include "packets.h"
#include "modem.h"
#include "flock.h"
#include "dstring.h"
#include <unistd.h>
#include <time.h>

Go to the source code of this file.

Defines

#define BUFFER_SIZE   4096
 Size of the buffer used to write data in function packet_dump(). More...


Functions

char * dater ()
 Return the current date as Apache's standard. More...

void get_remote_address (struct sockaddr_in *sender, char *ip, int *port)
 Return the IP address and the port number of a remote end point. More...

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

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 packet_init_dump_service ()
 Initialize the dump service for DHCP packets. More...

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

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

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

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

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

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

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

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

unsigned char packets_get_htype (struct dhcp_packet *p)
 Get 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...

unsigned char packets_get_hlen (struct dhcp_packet *p)
 Get 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...

unsigned char packets_get_hops (struct dhcp_packet *p)
 Get 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...

unsigned long int packets_get_xid (struct dhcp_packet *p)
 Get 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...

unsigned short int packets_get_secs (struct dhcp_packet *p)
 Get 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...

unsigned short int packets_get_flags (struct dhcp_packet *p)
 Get 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...

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...

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

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

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

char * packets_get_siaddr (struct dhcp_packet *p)
 Get 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...

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...

void packets_set_chaddr (struct dhcp_packet *p, char *chaddr)
 Set the client hardware address (field 'chaddr'). 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...

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

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

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

char * packets_get_file (struct dhcp_packet *p)
 Get the path to the boot file (field 'file'). 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...

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...

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 short int packets_get_vci (struct dhcp_packet *p)
 Return the DSLAM's VCI 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_vlan_id (struct dhcp_packet *p)
 Return the DSLAM's VLAN ID from the option 82. 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...


Variables

int order [256] = {1, 3, 15, 6, 0, 2, 4, 5, 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255}
 Order used to print standard oprions (other than option 82).

int dump_sync_fd
 This file descriptor is defined in the main server source (dhcp.c). It is used to synchronize access to the dump file.

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. More...

char chaddr [DHCP_P_STR_HADDR_SIZE]
 Buffer used to store the client hardware address (with ':' as separator between bytes).

char chaddr_exact [DHCP_P_STR_HADDR_SIZE_EXACT]
 Buffer used to store the client hardware address (without separator between bytes).

char sname [DHCP_P_STR_SNAME_SIZE]
 Buffer used to store the server names.

char file [DHCP_P_STR_FILE_SIZE]
 Buffer used to store the boot file.

char myhostname [256]
 Buffer used to store the host name.

char * descriptions [256]
 This array contains the human readable description for all options.


Detailed Description

This file contains the low level DHCP packet manipulation tools.

Definition in file packets.c.


Define Documentation

#define BUFFER_SIZE   4096
 

Size of the buffer used to write data in function packet_dump().

Remarks:
the value 4096 should be more than enough, since it is much bigger than the maximum DHCP packet size.

Definition at line 1735 of file packets.c.

Referenced by packet_dump().


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().

char* dater   [static]
 

Return the current date as Apache's standard.

Author:
Denis BEURIVE
Returns:
The function returns a pointer to a string of characters that contains the current date.
Warning:
The string is returned in a statically allocated buffer, which subsequent calls will overwrite.

Definition at line 2343 of file packets.c.

void get_remote_address struct sockaddr_in *    sender,
char *    ip,
int *    port
[static]
 

Return the IP address and the port number of a remote end point.

Author:
Denis BEURIVE
Parameters:
sender  Pointer to the address of the destant end point.
ip  Pointer to a string of character used to store the IP address. This string should be, at least 16 characters long.
port  Pointer to an integer used to store the port number.

Definition at line 2362 of file packets.c.

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 49 of file packets.c.

References file.

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 dhcp_packet::chaddr, 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, file, and dhcp_packet::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, sname, and dhcp_packet::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, vci, m_dhcp82::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 chaddr, and dhcp_packet::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, file, and dhcp_packet::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, sname, and dhcp_packet::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().


Variable Documentation

int(* my_syslog)(const char *file, const char * fmt,...) = my_fake_syslog [static]
 

Logging service. by default it is assigned to the fake logging service that does nothing.

Author:
Denis BEURIVE

Definition at line 55 of file packets.c.

Referenced by packet_logging_service().


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