Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals  

packets.h

Go to the documentation of this file.
00001 /*! \file packets.h
00002     Header file for the low level DHCP packet manipulation module (packet.c).
00003  */
00004 
00005 #ifdef __cplusplus
00006 extern "C" {
00007 #endif
00008 
00009 #ifndef PACKETS_HEADER_FILE
00010 #define PACKETS_HEADER_FILE
00011 
00012 #include <stdio.h>
00013 #include <string.h>
00014 #include <sys/socket.h>
00015 #include <netinet/in.h>
00016 #include <arpa/inet.h>
00017 #include <errno.h>
00018 #include <stdarg.h>
00019 
00020 #include "packets_data.h" 
00021 #include "conversion.h"
00022 
00023 
00024 /*! \brief Maximum number of characters used to represent a hardware address in standard ':' notation
00025            (HH:HH:HH:HH:HH:HH). Maximum size is 16*2 + 15 + 1 = 48
00026            <UL>
00027               <LI>The binary representation is 16 bytes long (maximum).
00028                   1 byte is represented by 2 hexa characters. So, we have 16*2 hexa characters.
00029               <LI>Each couple of 2 hexa characters is separated by a ':' character. So we need 15 characters ':'.
00030               <LI>We add 1 byte for the terminal zero.
00031            </UL>
00032  */
00033 
00034 #define DHCP_P_STR_HADDR_SIZE 48
00035 
00036 /*! \brief Maximum number of characters used to represent a hardware address in hexa (without ':' separators).
00037            Maximum size is 16*2 + 1 = 33
00038            <UL>
00039               <LI>The binary representation is 16 bytes long (maximum).
00040                   1 byte is represented by 2 hexa characters. So, we have 16*2 hexa characters.
00041               <LI>We add 1 byte for the terminal zero.
00042            </UL>
00043  */
00044 
00045 #define DHCP_P_STR_HADDR_SIZE_EXACT 33
00046 
00047 /*! \brief Maximum number of characters used to represent the field 'sname' of a DHCP packet.
00048            The size of the field 'sname' of a DHCP packet is 64 bytes. We add one byte for the terminal zero.
00049  */
00050 
00051 #define DHCP_P_STR_SNAME_SIZE 65
00052 
00053 /*! \brief Maximum number of characters used to represent the field 'file' of a DHCP packet.
00054            The size of the field 'file' of a DHCP packet is 128 bytes. We add one byte for the terminal zero.
00055  */
00056 
00057 #define DHCP_P_STR_FILE_SIZE  129
00058 
00059 /*! \brief Size, in bytes, for the option's value. */
00060 
00061 #define OPTIONS_OPTION_VALUE_SIZE         256
00062 
00063 
00064 
00065 
00066 
00067 void packet_logging_service (int dbg,
00068                              char *logfile,
00069                              int (*logger) (const char *file, const char * fmt,...));
00070 
00071 void packets_clear (struct dhcp_packet *p);
00072 
00073 void packets_set_op (struct dhcp_packet *p, int op);
00074 void packets_set_htype (struct dhcp_packet *p, int htype);
00075 void packets_set_hlen (struct dhcp_packet *p, int hlen);
00076 void packets_set_hops (struct dhcp_packet *p, int hops);
00077 void packets_set_xid (struct dhcp_packet *p, unsigned long int xid);
00078 void packets_set_secs (struct dhcp_packet *p, unsigned short int secs);
00079 void packets_set_flags (struct dhcp_packet *p, unsigned short int flags);
00080 int packets_set_ciaddr (struct dhcp_packet *p, char *ciaddr);
00081 void packets_set_bin_ciaddr (struct dhcp_packet *p, unsigned long int ciaddr);
00082 int packets_set_yiaddr (struct dhcp_packet *p, char *yiaddr);
00083 int packets_set_siaddr (struct dhcp_packet *p, char *siaddr);
00084 int packets_set_giaddr (struct dhcp_packet *p, char *giaddr);
00085 void packets_set_bin_giaddr (struct dhcp_packet *p, unsigned long int giaddr);
00086 void packets_set_chaddr (struct dhcp_packet *p, char *chaddr);
00087 void packets_set_sname (struct dhcp_packet *p, char *sname);
00088 void packets_set_file (struct dhcp_packet *p, char *file);
00089 
00090 unsigned char packets_get_op (struct dhcp_packet *p);
00091 unsigned char packets_get_htype (struct dhcp_packet *p);
00092 unsigned char packets_get_hlen (struct dhcp_packet *p);
00093 unsigned char packets_get_hops (struct dhcp_packet *p);
00094 unsigned long int packets_get_xid (struct dhcp_packet *p);
00095 unsigned short int packets_get_secs (struct dhcp_packet *p);
00096 unsigned short int packets_get_flags (struct dhcp_packet *p);
00097 char* packets_get_ciaddr (struct dhcp_packet *p);
00098 unsigned long int packets_get_bin_ciaddr (struct dhcp_packet *p);
00099 char* packets_get_yiaddr (struct dhcp_packet *p);
00100 char* packets_get_siaddr (struct dhcp_packet *p);
00101 char* packets_get_giaddr (struct dhcp_packet *p);
00102 unsigned long int packets_get_bin_giaddr (struct dhcp_packet *p);
00103 char* packets_get_chaddr (struct dhcp_packet *p);
00104 char* packets_get_chaddr_no_separator (struct dhcp_packet *p);
00105 char* packets_get_bin_chaddr (struct dhcp_packet *p);
00106 char* packets_get_sname (struct dhcp_packet *p);
00107 char* packets_get_file (struct dhcp_packet *p);
00108 
00109 char* packets_get_node_id (struct dhcp_packet *p);
00110 unsigned char packets_get_shelf (struct dhcp_packet *p);
00111 unsigned char packets_get_numero_slot (struct dhcp_packet *p);
00112 unsigned char packets_get_numero_port (struct dhcp_packet *p);
00113 unsigned short int packets_get_vci (struct dhcp_packet *p);
00114 unsigned short int packets_get_vlan_id (struct dhcp_packet *p);
00115 
00116 void packets_init_option_writer (struct dhcp_packet *p);
00117 void packets_options_clear (struct dhcp_packet *p);
00118 int packets_set_option (struct dhcp_packet *p, unsigned char option, char *value, int len);
00119 void packets_close_option (struct dhcp_packet *p);
00120 
00121 void packets_init_option_reader (struct dhcp_packet *p);
00122 int packets_parse_options (struct dhcp_packet *p);
00123 int packets_get_option (struct dhcp_packet *p, int option, int *len, unsigned char **value);
00124 int packets_get_message_type (struct dhcp_packet *p);
00125 char* packets_get_subnet_mask (struct dhcp_packet *p);
00126 
00127 void packet_init_dump_service();
00128 int packet_dump (struct dhcp_packet *p, char *file, char *csv, struct sockaddr_in *from, struct sockaddr_in *to);
00129 int check_packet_size (int size);
00130 void packet_set_taille (struct dhcp_packet *p, int taille);
00131 
00132 char* packets_type_to_char (int type);
00133 
00134 #endif
00135 
00136 
00137 
00138 
00139 #ifdef __cplusplus
00140 }
00141 #endif
00142 
00143 

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