forked from kynesim/tstools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ipv4.h
131 lines (99 loc) · 2.57 KB
/
ipv4.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
/* ipv4.h */
/*
* Routines for dissecting IPv4 and UDP packets.
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is the MPEG TS, PS and ES tools.
*
* The Initial Developer of the Original Code is Amino Communications Ltd.
* Portions created by the Initial Developer are Copyright (C) 2008
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Richard Watts, Kynesim <rrw@kynesim.co.uk>
*
* ***** END LICENSE BLOCK *****
*/
#ifndef _ipv4_h
#define _ipv4_h
#include "compat.h"
/*! This is all held in host byte order (including the
* IP addresses! You have been warned .. )
*/
typedef struct ipv4_header_s
{
// IP version. Should really be 4 :-)
uint8_t version;
// Header length.
uint8_t hdr_length;
// Type of service.
uint8_t serv_type;
//! Total length
uint16_t length;
//! Ident
uint16_t ident;
//! Flags
uint8_t flags;
//! Frag offset.
uint16_t frag_offset;
//! TTL
uint8_t ttl;
//! Protocol (typically UDP or TCP)
uint8_t proto;
//! Header checksum (we don't check this!)
uint16_t csum;
//! Source address.
uint32_t src_addr;
//! Destination address.
uint32_t dest_addr;
//! We don't track options.
} ipv4_header_t;
// Is this header UDP?
#define IPV4_HDR_IS_UDP(h) ((h)->proto == 17)
#define IPV4_ERR_PKT_TOO_SHORT (-1)
/*!
* Unwrap ipv4.
*
* \param out_st OUT Index into data at which IPv4 payload starts.
* \param out_len OUT Length of the IPv4 payload.
* \return 0 on success, -1 on failure.
*/
int ipv4_from_payload(const uint8_t *data,
const uint32_t len,
ipv4_header_t *out_hdr,
uint32_t *out_st,
uint32_t *out_len);
typedef struct ipv4_udp_header_s
{
//! Source port.
uint16_t source_port;
//! Dest port.
uint16_t dest_port;
//! Length (yes, yet another one!)
uint16_t length;
//! Checksum
uint16_t csum;
} ipv4_udp_header_t;
/*!
* Unwrap UDP.
*
*/
int ipv4_udp_from_payload(const uint8_t *data,
const uint32_t len,
ipv4_udp_header_t *out_hdr,
uint32_t *out_st,
uint32_t *out_len);
#endif
/* End file */