#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
| |
#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
| |
#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... |
Definition in file packets.h.
|
Check the size of a packet.
Definition at line 2310 of file packets.c. Referenced by main(). |
|
Dump the DHCP packet in a file (in human readable format).
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(). |
|
Initialize the dump service for DHCP packets.
Definition at line 120 of file packets.c. References myhostname. Referenced by main(). |
|
Assign a logging service to the packet module.
Definition at line 69 of file packets.c. References debug, file, log_file, and my_syslog. Referenced by main(). |
|
Set the total size of a packet.
Definition at line 2332 of file packets.c. References dhcp_packet::ctrl. Referenced by main(). |
|
Clear the content of a packet and intialize it for read/write option.
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(). |
|
Terminate the option's part cleanly.
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(). |
|
Get the client hardware address (field 'chaddr'). The hardware address is returned as RAW buffer.
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(). |
|
Get the client's IP address (field 'ciaddr') as a 4 bytes integer in network byte order.
Definition at line 678 of file packets.c. References dhcp_packet::ciaddr. Referenced by packets_send_ack(), packets_send_nack(), and reply_to_inform(). |
|
Get the gateway IP address (field 'giaddr'). IP address is returned as a 4 bytes integer in network byte order.
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(). |
|
Get the client hardware address (field 'chaddr').
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(). |
|
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 ':'.
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(). |
|
Get the client's IP address (field 'ciaddr').
Definition at line 661 of file packets.c. References dhcp_packet::ciaddr. Referenced by packet_dump(). |
|
Get the path to the boot file (field 'file').
Definition at line 933 of file packets.c. References DHCP_P_STR_FILE_SIZE, dhcp_packet::file, and file. Referenced by packet_dump(). |
|
Get 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(). |
|
Get the gateway IP address (field 'giaddr').
Definition at line 791 of file packets.c. References dhcp_packet::giaddr. Referenced by packet_dump(). |
|
Get 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(). |
|
Get the number of hops (field 'hops').
Definition at line 574 of file packets.c. References dhcp_packet::hops. Referenced by packet_dump(). |
|
Get 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(). |
|
Get the type of packet (value of option 53 (DHCP Message Type).
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(). |
|
Return a zero terminated string of characters the represents the DSLAM's node ID from the option 82.
Definition at line 1643 of file packets.c. References dhcp_packet::ctrl. Referenced by main(). |
|
Return the DSLAM's port number from the option 82.
Definition at line 1711 of file packets.c. References dhcp_packet::ctrl. Referenced by main(). |
|
Return the DSLAM's slot number from the option 82.
Definition at line 1677 of file packets.c. References dhcp_packet::ctrl. Referenced by main(). |
|
Get the packet's opcode.
Definition at line 526 of file packets.c. References dhcp_packet::op. Referenced by packet_dump(). |
|
Get a specific option.
Definition at line 1557 of file packets.c. References dhcp_packet::ctrl. Referenced by packets_get_message_type(), and packets_get_subnet_mask(). |
|
Get 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(). |
|
Return the DSLAM's shelf from the option 82.
Definition at line 1660 of file packets.c. References dhcp_packet::ctrl. Referenced by main(). |
|
Get the server IP address (field 'siaddr).
Definition at line 745 of file packets.c. References dhcp_packet::siaddr. Referenced by packet_dump(). |
|
Get the server name (field 'sname').
Definition at line 911 of file packets.c. References DHCP_P_STR_SNAME_SIZE, dhcp_packet::sname, and sname. Referenced by packet_dump(). |
|
Get the subnet mask associated with a given packet.
Definition at line 1613 of file packets.c. References OPTIONS_OPTION_VALUE_SIZE, and packets_get_option(). |
|
Return the DSLAM's VCI from the option 82.
Definition at line 1694 of file packets.c. References dhcp_packet::ctrl. Referenced by main(). |
|
Return the DSLAM's VLAN ID from the option 82.
Definition at line 1728 of file packets.c. References dhcp_packet::ctrl. Referenced by find_ip_and_reply(), and main(). |
|
Get 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(). |
|
Get the field 'yiaddr' ("Your IP address").
Definition at line 708 of file packets.c. References dhcp_packet::yiaddr. Referenced by packet_dump(). |
|
Initialize the packet's data before reading options.
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(). |
|
Initialize the packet's data before writing options.
Definition at line 446 of file packets.c. References dhcp_packet::ctrl, and dhcp_packet::options. Referenced by packets_clear(). |
|
Clear the option's part of a given packet.
Definition at line 502 of file packets.c. References OPTION_SIZE, and dhcp_packet::options. |
|
Read options from a given packet.
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(). |
|
Set the client's IP address (field 'ciaddr'). The field 'ciaddr' is given as an unsigned long integer 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(). |
|
Set the gateway IP address (field 'giaddr'). The IP address is given as 4 bytes entity in network byte order.
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(). |
|
Set the client hardware address (field 'chaddr').
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(). |
|
Set the client's IP address (field 'ciaddr').
Definition at line 632 of file packets.c. References dhcp_packet::ciaddr. |
|
Set the boot file (field 'file').
Definition at line 924 of file packets.c. References DHCP_P_STR_FILE_SIZE, dhcp_packet::file, and file. |
|
Set the packet's flags (field (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(). |
|
Set the gateway IP address (field 'giaddr').
Definition at line 763 of file packets.c. References dhcp_packet::giaddr. |
|
Set the length of the binary representation of the hardware address (field 'hlen').
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(). |
|
Set the number of hops (field '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(). |
|
Set the type of hardware address (field 'htype').
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(). |
|
Set the packet's opcode.
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(). |
|
Set a given DHCP option.
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(). |
|
Set the number of seconds (field 'secs').
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(). |
|
Set the server IP address (field 'siaddr).
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(). |
|
Set the server name (field 'sname').
Definition at line 902 of file packets.c. References DHCP_P_STR_SNAME_SIZE, dhcp_packet::sname, and sname. |
|
Set the transaction ID (field 'xid').
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(). |
|
Set the field 'Your IP address' (field 'yiaddr').
Definition at line 689 of file packets.c. References dhcp_packet::yiaddr. Referenced by packets_send_ack(), packets_send_nack(), and packets_send_offer(). |
|
Returns a string that describes the type of DHCP packet.
Definition at line 405 of file packets.c. References DHCPACK, DHCPDECLINE, DHCPDISCOVER, DHCPINFORM, DHCPNAK, DHCPOFFER, DHCPRELEASE, and DHCPREQUEST. Referenced by packet_dump(). |