source: mainline/uspace/lib/pcap/include/pcap.h@ e5b2777

Last change on this file since e5b2777 was e5b2777, checked in by Nataliia Korop <n.corop08@…>, 10 months ago

create drv iface for drivers

  • Property mode set to 100644
File size: 3.4 KB
Line 
1/*
2 * Copyright (c) 2023 Nataliia Korop
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - 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 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/**
30 * @addtogroup libpcap
31 * @{
32 */
33/**
34 * @file
35 * @brief Headers and functions for .pcap file and packets to be dumped
36 */
37
38#ifndef PCAP_H_
39#define PCAP_H_
40
41#include <stdint.h>
42#include <stdio.h>
43#include <str_error.h>
44#include <time.h>
45#include <stdbool.h>
46#include <errno.h>
47
48#define PCAP_MAGIC_MICRO 0xA1B2C3D4
49#define PCAP_MAGIC_NANO 0xA1B23C4D
50#define PCAP_MAJOR_VERSION 0x0002
51#define PCAP_MINOR_VERSION 0x0004
52#define PCAP_SNAP_LEN 0x00040000
53
54#define PCAP_LINKTYPE_ETHERNET 1 /* IEEE 802.3 Ethernet */
55#define PCAP_LINKTYPE_IP_RAW 101 /* Raw IP packet */
56#define PCAP_LINKTYPE_IEEE802_11_RADIO 127
57#define PCAP_LINKTYPE_USB_LINUX_MMAPPED 220
58#define WIRESHARK_EX 0xc
59#define WIRESHARK_SNAPLEN 0xffff
60
61/** Header of the .pcap file. */
62typedef struct {
63 uint32_t magic_number;
64 uint16_t major_v;
65 uint16_t minor_v;
66 uint32_t reserved1;
67 uint32_t reserved2;
68 uint32_t snaplen;
69 uint32_t additional; /** The LinkType and additional information field is in the form */
70} pcap_file_header_t;
71
72/** Header of the packet to be dumped to .pcap file. */
73typedef struct pcap_packet_header {
74 uint32_t seconds_stamp;
75 uint32_t magic_stamp;
76 uint32_t captured_length;
77 uint32_t original_length;
78} pcap_packet_header_t;
79
80typedef struct pcap_writer pcap_writer_t;
81
82/** Operations for dumper. */
83typedef struct {
84 errno_t (*open)(pcap_writer_t *, const char *);
85 size_t (*write_u32)(struct pcap_writer *, uint32_t);
86 size_t (*write_u16)(struct pcap_writer *, uint16_t);
87 size_t (*write_buffer)(struct pcap_writer *, const void *, size_t);
88 void (*close)(struct pcap_writer *);
89} pcap_writer_ops_t;
90
91/** Interface for working with .pcap file. */
92struct pcap_writer {
93 void *data;
94 pcap_writer_ops_t *ops;
95};
96
97extern void pcap_writer_add_header(pcap_writer_t *writer, uint32_t linktype, bool nano);
98extern void pcap_writer_add_packet(pcap_writer_t *writer, const void *captured_packet, size_t size);
99extern void pcap_set_time(pcap_packet_header_t *header);
100
101#endif
102
103/** @}
104 */
Note: See TracBrowser for help on using the repository browser.