update otp_hotp() to support 6,7,8,9 digit otp's
[freeradius.git] / src / include / radsniff.h
1 /*
2  *  radsniff.h  Structures and defines for the RADIUS sniffer.
3  *
4  *  Version:    $Id$
5  *
6  *  This program is free software; you can redistribute it and/or
7  *  modify it under the terms of the GNU General Public License
8  *  as published by the Free Software Foundation; either version 2
9  *  of the License, or (at your option) any later version.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  *
20  *  Copyright 2006  The FreeRADIUS server project
21  *  Copyright 2006  Nicolas Baradakis <nicolas.baradakis@cegetel.net>
22  */
23
24 #include <sys/types.h>
25 #include <netinet/in.h>
26
27 /*
28  *      The number of bytes in an ethernet (MAC) address.
29  */
30 #define ETHER_ADDR_LEN          6
31
32 /*
33  *      Structure of a DEC/Intel/Xerox or 802.3 Ethernet header.
34  */
35 struct  ethernet_header {
36         u_int8_t        ethernet_dhost[ETHER_ADDR_LEN];
37         u_int8_t        ethernet_shost[ETHER_ADDR_LEN];
38         u_int16_t       ethernet_type;
39 };
40
41 /*
42  *      Length of a DEC/Intel/Xerox or 802.3 Ethernet header.
43  *      Note that some compilers may pad "struct ether_header" to
44  *      a multiple of 4 *bytes, for example, so "sizeof (struct
45  *      ether_header)" may not give the right answer.
46  */
47 #define ETHER_HDRLEN            14
48
49 /*
50  *      Structure of an internet header, naked of options.
51  */
52 struct ip_header {
53         u_int8_t        ip_vhl;         /* header length, version */
54 #define IP_V(ip)        (((ip)->ip_vhl & 0xf0) >> 4)
55 #define IP_HL(ip)       ((ip)->ip_vhl & 0x0f)
56         u_int8_t        ip_tos;         /* type of service */
57         u_int16_t       ip_len;         /* total length */
58         u_int16_t       ip_id;          /* identification */
59         u_int16_t       ip_off;         /* fragment offset field */
60 #define IP_DF 0x4000                    /* dont fragment flag */
61 #define IP_MF 0x2000                    /* more fragments flag */
62 #define IP_OFFMASK 0x1fff               /* mask for fragmenting bits */
63         u_int8_t        ip_ttl;         /* time to live */
64         u_int8_t        ip_p;           /* protocol */
65         u_int16_t       ip_sum;         /* checksum */
66         struct in_addr  ip_src,ip_dst;  /* source and dest address */
67 };
68
69 /*
70  *      UDP protocol header.
71  *      Per RFC 768, September, 1981.
72  */
73 struct udp_header {
74         u_int16_t       udp_sport;               /* source port */
75         u_int16_t       udp_dport;               /* destination port */
76         u_int16_t       udp_ulen;                /* udp length */
77         u_int16_t       udp_sum;                 /* udp checksum */
78 };
79
80 /*
81  *      RADIUS packet length.
82  *      RFC 2865, Section 3., subsection 'length' says:
83  *      " ... and maximum length is 4096."
84  */
85 #define MAX_RADIUS_LEN 4096
86 #define MIN_RADIUS_LEN 20
87 #define SNAPLEN (sizeof(struct ethernet_header) + sizeof(struct ip_header) + sizeof(struct udp_header) + MAX_RADIUS_LEN)
88
89 typedef struct radius_packet_t {
90         uint8_t       code;
91         uint8_t       id;
92         uint8_t       length[2];
93         uint8_t       vector[AUTH_VECTOR_LEN];
94         uint8_t       data[1];
95 } radius_packet_t;
96
97 #define AUTH_HDR_LEN 20