#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. |
Definition in file packets.c.
|
Size of the buffer used to write data in function packet_dump().
Definition at line 1735 of file packets.c. Referenced by packet_dump(). |
|
Check the size of a packet.
Definition at line 2310 of file packets.c. Referenced by main(). |
|
Return the current date as Apache's standard.
|
|
Return the IP address and the port number of a remote end point.
|
|
This is a handler to a fake loggin service.
Definition at line 49 of file packets.c. References file. |
|
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 dhcp_packet::chaddr, 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, file, and dhcp_packet::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, sname, and dhcp_packet::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, 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(). |
|
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 chaddr, and dhcp_packet::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, file, and dhcp_packet::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, sname, and dhcp_packet::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(). |
|
Logging service. by default it is assigned to the fake logging service that does nothing.
Definition at line 55 of file packets.c. Referenced by packet_logging_service(). |