MCPcopy Create free account
hub / github.com/F-Stack/f-stack / pcapng_section_block

Function pcapng_section_block

dpdk/lib/pcapng/rte_pcapng.c:140–199  ·  view source on GitHub ↗

* Write required initial section header describing the capture */

Source from the content-addressed store, hash-verified

138 * Write required initial section header describing the capture
139 */
140static int
141pcapng_section_block(rte_pcapng_t *self,
142 const char *os, const char *hw,
143 const char *app, const char *comment)
144{
145 struct pcapng_section_header *hdr;
146 struct pcapng_option *opt;
147 uint32_t buf[PCAPNG_BLKSIZ];
148 uint32_t len;
149
150 len = sizeof(*hdr);
151 if (hw)
152 len += pcapng_optlen(strlen(hw));
153 if (os)
154 len += pcapng_optlen(strlen(os));
155 if (app)
156 len += pcapng_optlen(strlen(app));
157 if (comment)
158 len += pcapng_optlen(strlen(comment));
159
160 /* reserve space for OPT_END */
161 len += pcapng_optlen(0);
162 len += sizeof(uint32_t);
163
164 if (len > sizeof(buf))
165 return -1;
166
167 hdr = (struct pcapng_section_header *)buf;
168 *hdr = (struct pcapng_section_header) {
169 .block_type = PCAPNG_SECTION_BLOCK,
170 .block_length = len,
171 .byte_order_magic = PCAPNG_BYTE_ORDER_MAGIC,
172 .major_version = PCAPNG_MAJOR_VERS,
173 .minor_version = PCAPNG_MINOR_VERS,
174 .section_length = UINT64_MAX,
175 };
176
177 /* After the section header insert variable length options. */
178 opt = (struct pcapng_option *)(hdr + 1);
179 if (comment)
180 opt = pcapng_add_option(opt, PCAPNG_OPT_COMMENT,
181 comment, strlen(comment));
182 if (hw)
183 opt = pcapng_add_option(opt, PCAPNG_SHB_HARDWARE,
184 hw, strlen(hw));
185 if (os)
186 opt = pcapng_add_option(opt, PCAPNG_SHB_OS,
187 os, strlen(os));
188 if (app)
189 opt = pcapng_add_option(opt, PCAPNG_SHB_USERAPPL,
190 app, strlen(app));
191
192 /* The standard requires last option to be OPT_END */
193 opt = pcapng_add_option(opt, PCAPNG_OPT_END, NULL, 0);
194
195 /* clone block_length after option */
196 memcpy(opt, &hdr->block_length, sizeof(uint32_t));
197

Callers 1

rte_pcapng_fdopenFunction · 0.85

Calls 4

pcapng_optlenFunction · 0.85
pcapng_add_optionFunction · 0.85
memcpyFunction · 0.50
writeFunction · 0.50

Tested by

no test coverage detected