Lines Matching refs:handle

37 PCAPNG_RESULT pcapng_create( PCAPNG_HANDLE * handle,  in pcapng_create()  argument
51 handle->section_header = NULL; in pcapng_create()
52 handle->interface_description = NULL; in pcapng_create()
53 handle->section_header_size = handle->next_section_option_offset = in pcapng_create()
54 handle->interface_description_size = in pcapng_create()
55 handle->next_interface_option_offset = 0; in pcapng_create()
57 handle->fd = open( filename, O_RDWR|O_CREAT|O_EXCL, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP ); in pcapng_create()
58 if (handle->fd == -1) { in pcapng_create()
86 handle->section_header_size = sizeof( shb ); in pcapng_create()
87 result = write( handle->fd, &shb, sizeof( shb ) ); in pcapng_create()
95 result = write( handle->fd, section_options, 4+section_options->option_length ); in pcapng_create()
97 result = write( handle->fd, "\0", 1 ); in pcapng_create()
101 handle->section_header_size += (4+paddedsz); in pcapng_create()
103 handle->next_section_option_offset = handle->section_header_size; in pcapng_create()
111 zeroes = (size_t) PGSZ*((handle->section_header_size + 4 + in pcapng_create()
113 handle->section_header_size; in pcapng_create()
114 handle->section_header_size += zeroes; in pcapng_create()
116 result = write( handle->fd, "\0", 1 ); in pcapng_create()
121 handle->section_header = mmap( NULL, handle->section_header_size, in pcapng_create()
124 handle->fd, 0 ); in pcapng_create()
131 else if (handle->section_header == MAP_FAILED) { in pcapng_create()
142 handle->interface_description_size = sizeof( idb ); in pcapng_create()
143 result = write( handle->fd, &idb, sizeof( idb ) ); in pcapng_create()
152 result = write( handle->fd, interface_options, 4+interface_options->option_length ); in pcapng_create()
154 result = write( handle->fd, "\0", 1 ); in pcapng_create()
158 handle->interface_description_size += (4+paddedsz); in pcapng_create()
160 handle->next_interface_option_offset = handle->interface_description_size; in pcapng_create()
170 zeroes = (size_t) PGSZ*((handle->interface_description_size + 4 + in pcapng_create()
172 handle->interface_description_size; in pcapng_create()
173 handle->interface_description_size += zeroes; in pcapng_create()
175 result = write( handle->fd, "\0", 1 ); in pcapng_create()
180 handle->interface_description = mmap( NULL, handle->interface_description_size, in pcapng_create()
183 handle->fd, in pcapng_create()
184 handle->section_header_size ); in pcapng_create()
192 else if (handle->interface_description == MAP_FAILED) { in pcapng_create()
196 uint8_t * dest = &((uint8_t *)handle->section_header)[handle->next_section_option_offset]; in pcapng_create()
197 padopt.option_length = handle->section_header_size - in pcapng_create()
198 handle->next_section_option_offset - 12; in pcapng_create()
202 handle->section_header->block_total_length = in pcapng_create()
203 (uint32_t) handle->section_header_size; in pcapng_create()
204 ((uint32_t*)handle->section_header)[handle->section_header_size/4-1] = in pcapng_create()
205 (uint32_t) handle->section_header_size; in pcapng_create()
207 padopt.option_length = handle->interface_description_size - in pcapng_create()
208 handle->next_interface_option_offset - 12; in pcapng_create()
209 dest = &((uint8_t *)handle->interface_description)[handle->next_interface_option_offset]; in pcapng_create()
211 handle->interface_description->block_total_length = in pcapng_create()
212 (uint32_t) handle->interface_description_size; in pcapng_create()
213 ((uint32_t*)handle->interface_description)[handle->interface_description_size/4-1] = in pcapng_create()
214 (uint32_t) handle->interface_description_size; in pcapng_create()
216 handle->section_header->section_length = (uint64_t) handle->interface_description_size; in pcapng_create()
221 (void) pcapng_close( handle ); in pcapng_create()
227 PCAPNG_RESULT pcapng_append_section_option( PCAPNG_HANDLE * handle, in pcapng_append_section_option() argument
231 if (handle && (handle->fd != -1)) { in pcapng_append_section_option()
232 if (handle->section_header && in pcapng_append_section_option()
233 (handle->section_header != MAP_FAILED) && in pcapng_append_section_option()
234 handle->next_section_option_offset && in pcapng_append_section_option()
237 uint8_t * dest = &((uint8_t *)handle->section_header)[handle->next_section_option_offset]; in pcapng_append_section_option()
239 handle->next_section_option_offset += 4*((copysz+3)/4); in pcapng_append_section_option()
242 dest = &((uint8_t *)handle->section_header)[handle->next_section_option_offset]; in pcapng_append_section_option()
243 padopt.option_length = handle->section_header_size - in pcapng_append_section_option()
244 handle->next_section_option_offset - 12; in pcapng_append_section_option()
257 PCAPNG_RESULT pcapng_append_interface_option( PCAPNG_HANDLE * handle, in pcapng_append_interface_option() argument
261 if (handle && (handle->fd != -1)) { in pcapng_append_interface_option()
262 if (handle->interface_description && in pcapng_append_interface_option()
263 (handle->interface_description != MAP_FAILED) && in pcapng_append_interface_option()
264 handle->next_interface_option_offset && in pcapng_append_interface_option()
267 …uint8_t * dest = &((uint8_t *)handle->interface_description)[handle->next_interface_option_offset]; in pcapng_append_interface_option()
269 handle->next_interface_option_offset += 4*((copysz+3)/4); in pcapng_append_interface_option()
272 dest = &((uint8_t *)handle->interface_description)[handle->next_interface_option_offset]; in pcapng_append_interface_option()
273 padopt.option_length = handle->interface_description_size - in pcapng_append_interface_option()
274 handle->next_interface_option_offset - 12; in pcapng_append_interface_option()
287 PCAPNG_RESULT pcapng_append_packet( PCAPNG_HANDLE * handle, in pcapng_append_packet() argument
291 if (handle && (handle->fd != -1)) { in pcapng_append_packet()
293 ssize_t result = write( handle->fd, packet, writesz ); in pcapng_append_packet()
298 handle->section_header->section_length += writesz; in pcapng_append_packet()
307 PCAPNG_RESULT pcapng_close( PCAPNG_HANDLE * handle ) in pcapng_close() argument
309 if (handle->interface_description && in pcapng_close()
310 (handle->interface_description != MAP_FAILED)) { in pcapng_close()
311 (void) munmap( handle->interface_description, in pcapng_close()
312 handle->interface_description_size ); in pcapng_close()
314 if (handle->section_header && in pcapng_close()
315 (handle->section_header != MAP_FAILED)) { in pcapng_close()
316 (void) munmap( handle->section_header, in pcapng_close()
317 handle->section_header_size ); in pcapng_close()
319 if (handle->fd != -1) { in pcapng_close()
320 (void) close( handle->fd ); in pcapng_close()