1 /*
2  * Copyright (c) 2004-2006 Maxim Sobolev <sobomax@FreeBSD.org>
3  * Copyright (c) 2006-2007 Sippy Software, Inc., http://www.sippysoft.com
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  *
27  */
28 
29 #ifndef _RTPP_RECORD_PRIVATE_H_
30 #define _RTPP_RECORD_PRIVATE_H_
31 
32 #define	DLT_NULL	0
33 #define	DLT_EN10MB	1
34 #define	PCAP_MAGIC	0xa1b2c3d4
35 #define	PCAP_VER_MAJR	2
36 #define	PCAP_VER_MINR	4
37 
38 #define	ETHERTYPE_INET	htons(0x0800)
39 #define	ETHERTYPE_INET6	htons(0x86DD)
40 
41 /* Global PCAP Header */
42 typedef struct pcap_hdr_s {
43     uint32_t magic_number;   /* magic number */
44     uint16_t version_major;  /* major version number */
45     uint16_t version_minor;  /* minor version number */
46     int32_t  thiszone;       /* GMT to local correction */
47     uint32_t sigfigs;        /* accuracy of timestamps */
48     uint32_t snaplen;        /* max length of captured packets, in octets */
49     uint32_t network;        /* data link type */
50 } pcap_hdr_t;
51 
52 /* PCAP Packet Header */
53 typedef struct pcaprec_hdr_s {
54     uint32_t ts_sec;         /* timestamp seconds */
55     uint32_t ts_usec;        /* timestamp microseconds */
56     uint32_t incl_len;       /* number of octets of packet saved in file */
57     uint32_t orig_len;       /* actual length of packet */
58 } pcaprec_hdr_t;
59 
60 struct udpip {
61     struct ip iphdr;
62     struct udphdr udphdr;
63 } __attribute__((__packed__));
64 
65 #if !defined(IPV6_DEFHLIM)
66 # define 	IPV6_DEFHLIM   64 /* default hlim */
67 #endif
68 #if !defined(IPV6_VERSION)
69 # define 	IPV6_VERSION   0x60
70 #endif
71 
72 struct udpip6 {
73     struct ip6_hdr iphdr;
74     struct udphdr udphdr;
75 } __attribute__((__packed__));
76 
77 
78 struct layer2_hdr {
79     uint8_t dhost[6];
80     uint8_t shost[6];
81     uint16_t type;
82 } __attribute__((__packed__));
83 
84 /*
85  * Recorded data header
86  */
87 struct pkt_hdr_pcap_null {
88     pcaprec_hdr_t pcaprec_hdr;
89     uint32_t family;
90     struct udpip udpip;
91 } __attribute__((__packed__));
92 struct pkt_hdr_pcap_null_v6 {
93     pcaprec_hdr_t pcaprec_hdr;
94     uint32_t family;
95     struct udpip6 udpip6;
96 } __attribute__((__packed__));
97 struct pkt_hdr_pcap_en10t {
98     pcaprec_hdr_t pcaprec_hdr;
99     struct layer2_hdr ether;
100     struct udpip udpip;
101 } __attribute__((__packed__));
102 struct pkt_hdr_pcap_en10t_v6 {
103     pcaprec_hdr_t pcaprec_hdr;
104     struct layer2_hdr ether;
105     struct udpip6 udpip6;
106 } __attribute__((__packed__));
107 
108 union pkt_hdr_pcap {
109     struct pkt_hdr_pcap_null null;
110     struct pkt_hdr_pcap_null_v6 null_v6;
111     struct pkt_hdr_pcap_en10t en10t;
112     struct pkt_hdr_pcap_en10t_v6 en10t_v6;
113 };
114 
115 /* Stripped down version of sockaddr_in* for saving space */
116 struct sockaddr_in4_s {
117     sa_family_t sin_family;
118     in_port_t sin_port;
119     struct in_addr sin_addr;
120 };
121 
122 struct sockaddr_in6_s {
123     sa_family_t sin_family;
124     in_port_t sin_port;
125     struct in6_addr sin_addr;
126 };
127 
128 union sockaddr_in_s {
129     struct sockaddr_in4_s in4;
130     struct sockaddr_in6_s in6;
131 };
132 
133 struct pkt_hdr_adhoc {
134     union sockaddr_in_s addr;   /* Source address */
135     double time;		/* Time of arrival */
136     unsigned short plen;	/* Length of following RTP/RTCP packet */
137 } __attribute__((__packed__));
138 
139 #endif
140