Stealth Mode script
[tomato.git] / release / src / router / udpxy / dpkt.h
blob91191ab33f13fc881673129426b42ffb0123bc12
1 /* @(#) definition of packet-io functions for udpxy
3 * Copyright 2008-2011 Pavel V. Cherenkov (pcherenkov@gmail.com)
5 * This file is part of udpxy.
7 * udpxy is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * udpxy is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with udpxy. If not, see <http://www.gnu.org/licenses/>.
21 #ifndef UDPXY_DPKTH_02182008
22 #define UDPXY_DPKTH_02182008
24 #include <stdio.h>
25 #include "udpxy.h"
27 /* data-stream format type */
28 typedef enum {
29 DT_FIRST = -1,
31 DT_UNKNOWN, /* no assumptions */
32 DT_TS, /* MPEG-TS */
33 DT_RTP_TS, /* RTP over MPEG-TS */
34 DT_UDS, /* UDS file format */
35 DT_RAW, /* read AS-IS */
37 DT_LAST
38 } upxfmt_t;
41 /* data stream context
43 struct dstream_ctx {
44 upxfmt_t stype;
45 int32_t flags;
46 size_t mtu;
48 struct iovec* pkt;
49 int32_t max_pkt,
50 pkt_count;
53 /* data-stream context flags
55 static const int32_t F_DROP_PACKET = (1 << 1);
56 static const int32_t F_CHECK_FMT = (1 << 2);
57 static const int32_t F_SCATTERED = (1 << 3);
58 static const int32_t F_FILE_INPUT = (1 << 4);
61 #ifdef __cplusplus
62 extern "C" {
63 #endif
65 /* return human-readable name of file/stream format
67 const char* fmt2str( upxfmt_t fmt );
70 /* determine type of stream saved in file
72 upxfmt_t
73 get_fstream_type( int fd, FILE* log );
75 /* determine type of stream in memory
77 upxfmt_t
78 get_mstream_type( const char* data, size_t len, FILE* log );
81 /* read record of one of the supported types from file
83 ssize_t
84 read_frecord( int fd, char* data, const size_t len,
85 upxfmt_t* stream_type, FILE* log );
88 /* write record after converting it from source into destination
89 * format
91 ssize_t
92 write_frecord( int fd, const char* data, size_t len,
93 upxfmt_t sfmt, upxfmt_t dfmt, FILE* log );
96 /* reset packet-buffer registry in stream context
98 void
99 reset_pkt_registry( struct dstream_ctx* ds );
102 /* release resources allocated for stream context
104 void
105 free_dstream_ctx( struct dstream_ctx* ds );
108 /* initialize incoming-stream context:
109 * set data type (if possible) and flags
112 init_dstream_ctx( struct dstream_ctx* ds, const char* cmd, const char* fname,
113 ssize_t nmsgs );
116 /* read data from source of specified type (UDP socket or otherwise);
117 * read as many fragments as specified (max_frgs) into the buffer
119 struct rdata_opt {
120 int max_frgs; /* max fragments to read in */
121 time_t buf_tmout; /* max time (sec) to hold data in buffer */
124 ssize_t
125 read_data( struct dstream_ctx* spc, int fd, char* data,
126 const ssize_t data_len, const struct rdata_opt* opt );
129 /* write data to destination(s)
131 ssize_t
132 write_data( const struct dstream_ctx* spc,
133 const char* data,
134 const ssize_t len,
135 int fd );
137 #ifdef __cplusplus
139 #endif
141 #endif /* UDPXY_DPKTH_02182008 */
143 /* __EOF__ */