File: ethernet.h

package info (click to toggle)
tstools 1.13~git20151030-6
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, trixie
  • size: 2,916 kB
  • sloc: ansic: 37,970; java: 2,243; makefile: 466; python: 319; sh: 5
file content (92 lines) | stat: -rw-r--r-- 2,221 bytes parent folder | download | duplicates (3)
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
/* ethernet.h */
/* 
 * Routines for taking ethernet packets apart.
 *
 * ***** 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 _ethernet_h
#define _ethernet_h

#include <stdio.h>
#include <stdlib.h>
#include "compat.h"

#include "pcap.h"

typedef struct ethernet_vlan_info_s
{
  char cfi;
  char pcp;
  int vid;
} ethernet_vlan_info_t;

typedef struct ethernet_packet_s
{
  // Source address.
  uint8_t src_addr[6];

  // Destination ddress.
  uint8_t dst_addr[6];


  // 0x5DC is the maximum frame length in 802.3
#define ETHERNET_MAY_BE_IP(typeorlen) ((typeorlen) == 0x800 || (typeorlen) <= 0x5DC)

#define ETHERNET_TYPE_IP 0x800
  // Type
  uint16_t typeorlen;

#define ETHERNET_VLANS_MAX 2
  int vlan_count;
  ethernet_vlan_info_t vlans[ETHERNET_VLANS_MAX];

  // Checksum if present. Note that pcap doesn't include checksums.
  uint32_t checksum;
} ethernet_packet_t;

#define ETHERNET_ERR_PKT_TOO_SHORT (-1)
#define ETHERNET_ERR_TOO_MANY_VLANS (-2)

/*
 * \param out_st OUT Index into data at which ethernet payload starts.
 * \param out_len OUT Length of the ethernet payload.
 * \return 0 on success, -1 on failure.
 *

 */
int ethernet_packet_from_pcap(pcaprec_hdr_t *hdr, 
			      const uint8_t *data,
			      const uint32_t len,
			      ethernet_packet_t *pkt,
			      uint32_t *out_st,
			      uint32_t *out_len);
			      



#endif

/* End file */