1 /* 2 * Author Jerry Lundström <jerry@dns-oarc.net> 3 * Copyright (c) 2016-2017, OARC, Inc. 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in 15 * the documentation and/or other materials provided with the 16 * distribution. 17 * 18 * 3. Neither the name of the copyright holder nor the names of its 19 * contributors may be used to endorse or promote products derived 20 * from this software without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 30 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 32 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 * POSSIBILITY OF SUCH DAMAGE. 34 */ 35 36 #ifndef __pcap_thread_h 37 #define __pcap_thread_h 38 39 #ifdef HAVE_PTHREAD 40 #include <pthread.h> 41 #endif 42 #include <pcap/pcap.h> 43 #include <sys/socket.h> 44 #ifdef TIME_WITH_SYS_TIME 45 #include <sys/time.h> 46 #include <time.h> 47 #else 48 #ifdef HAVE_SYS_TIME_H 49 #include <sys/time.h> 50 #else 51 #include <time.h> 52 #endif 53 #endif 54 #include <sys/types.h> 55 #include <netinet/in.h> 56 #include <net/if_arp.h> 57 #include <netinet/if_ether.h> 58 #include <netinet/ip.h> 59 #include <netinet/ip6.h> 60 #ifdef HAVE_ENDIAN_H 61 #include <endian.h> 62 #endif 63 #ifdef HAVE_SYS_ENDIAN_H 64 #include <sys/endian.h> 65 #endif 66 #ifdef HAVE_MACHINE_ENDIAN_H 67 #include <machine/endian.h> 68 #endif 69 70 #ifndef __BYTE_ORDER 71 #if defined(BYTE_ORDER) 72 #define __BYTE_ORDER BYTE_ORDER 73 #elif defined(_BYTE_ORDER) 74 #define __BYTE_ORDER _BYTE_ORDER 75 #else 76 #error "No endian byte order define, please fix" 77 #endif 78 #endif 79 #ifndef __LITTLE_ENDIAN 80 #if defined(LITTLE_ENDIAN) 81 #define __LITTLE_ENDIAN LITTLE_ENDIAN 82 #elif defined(_LITTLE_ENDIAN) 83 #define __LITTLE_ENDIAN _LITTLE_ENDIAN 84 #else 85 #error "No little endian define, please fix" 86 #endif 87 #endif 88 #ifndef __BIG_ENDIAN 89 #if defined(BIG_ENDIAN) 90 #define __BIG_ENDIAN BIG_ENDIAN 91 #elif defined(_BIG_ENDIAN) 92 #define __BIG_ENDIAN _BIG_ENDIAN 93 #else 94 #error "No big endian define, please fix" 95 #endif 96 #endif 97 98 #ifndef PCAP_NETMASK_UNKNOWN 99 #define PCAP_NETMASK_UNKNOWN 0xffffffff 100 #endif 101 102 #ifdef __cplusplus 103 extern "C" { 104 #endif 105 106 /* clang-format off */ 107 108 #define PCAP_THREAD_VERSION_STR "3.1.0" 109 #define PCAP_THREAD_VERSION_MAJOR 3 110 #define PCAP_THREAD_VERSION_MINOR 1 111 #define PCAP_THREAD_VERSION_PATCH 0 112 113 #define PCAP_THREAD_DEFAULT_TIMEOUT 1000 114 #define PCAP_THREAD_DEFAULT_QUEUE_SIZE 64 115 #define PCAP_THREAD_DEFAULT_QUEUE_MODE PCAP_THREAD_QUEUE_MODE_COND 116 #define PCAP_THREAD_DEFAULT_ACTIVATE_MODE PCAP_THREAD_ACTIVATE_MODE_IMMEDIATE 117 118 #define PCAP_THREAD_OK 0 119 #define PCAP_THREAD_EPCAP 1 120 #define PCAP_THREAD_ENOMEM 2 121 #define PCAP_THREAD_ENOMON 3 122 #define PCAP_THREAD_ENODIR 4 123 #define PCAP_THREAD_EINVAL 5 124 #define PCAP_THREAD_EWOULDBLOCK 6 125 #define PCAP_THREAD_NOPCAPS 7 126 #define PCAP_THREAD_NOCALLBACK 8 127 #define PCAP_THREAD_ERRNO 9 128 #define PCAP_THREAD_NOYIELD 10 129 #define PCAP_THREAD_EOBSOLETE 11 130 #define PCAP_THREAD_ERUNNING 12 131 #define PCAP_THREAD_ENOPCAPLIST 13 132 #define PCAP_THREAD_ELAYERCB 14 133 134 #define PCAP_THREAD_EPCAP_STR "libpcap error" 135 #define PCAP_THREAD_ENOMEM_STR "out of memory" 136 #define PCAP_THREAD_ENOMON_STR "monitor mode requested but not supported" 137 #define PCAP_THREAD_ENODIR_STR "direction specified but not supported" 138 #define PCAP_THREAD_EINVAL_STR "invalid argument" 139 #define PCAP_THREAD_EWOULDBLOCK_STR "nonblocking pcap can not be added" 140 #define PCAP_THREAD_NOPCAPS_STR "nothing to capture on" 141 #define PCAP_THREAD_NOCALLBACK_STR "no callback set" 142 #define PCAP_THREAD_ERRNO_STR "system error, check errno" 143 #define PCAP_THREAD_NOYIELD_STR "queue more yield requested but not supported" 144 #define PCAP_THREAD_EOBSOLETE_STR "obsolete function or feature" 145 #define PCAP_THREAD_ERUNNING_STR "pcap thread are running, can not complete task" 146 #define PCAP_THREAD_ENOPCAPLIST_STR "no internal reference to the pcap that captured the packet" 147 #define PCAP_THREAD_ELAYERCB_STR "layer callback already set in lower or higher segment" 148 149 /* clang-format on */ 150 151 struct pcap_thread_linux_sll { 152 uint16_t packet_type; 153 uint16_t arp_hardware; 154 uint16_t link_layer_address_length; 155 uint8_t link_layer_address[8]; 156 uint16_t ether_type; 157 }; 158 struct pcap_thread_null_hdr { 159 uint32_t family; 160 }; 161 struct pcap_thread_loop_hdr { 162 uint32_t family; 163 }; 164 struct pcap_thread_ieee802_hdr { 165 uint16_t tpid; 166 unsigned short pcp : 3; 167 unsigned short dei : 1; 168 unsigned short vid : 12; 169 uint16_t ether_type; 170 }; 171 struct pcap_thread_gre_hdr { 172 uint16_t gre_flags; 173 uint16_t ether_type; 174 }; 175 struct pcap_thread_gre { 176 uint16_t checksum; 177 uint16_t key; 178 uint16_t sequence; 179 }; 180 typedef enum pcap_thread_packet_state pcap_thread_packet_state_t; 181 enum pcap_thread_packet_state { 182 PCAP_THREAD_PACKET_OK = 0, 183 PCAP_THREAD_PACKET_INVALID, 184 PCAP_THREAD_PACKET_UNSUPPORTED, 185 PCAP_THREAD_PACKET_UNPROCESSED, 186 PCAP_THREAD_PACKET_INVALID_ETHER, 187 PCAP_THREAD_PACKET_INVALID_LINUX_SLL, 188 PCAP_THREAD_PACKET_INVALID_NULL, 189 PCAP_THREAD_PACKET_INVALID_LOOP, 190 PCAP_THREAD_PACKET_INVALID_IEEE802, 191 PCAP_THREAD_PACKET_INVALID_GRE, 192 PCAP_THREAD_PACKET_INVALID_IP, 193 PCAP_THREAD_PACKET_INVALID_IPV4, 194 PCAP_THREAD_PACKET_INVALID_IPV6, 195 PCAP_THREAD_PACKET_INVALID_IPV6HDR, 196 PCAP_THREAD_PACKET_INVALID_ICMP, 197 PCAP_THREAD_PACKET_INVALID_ICMPV6, 198 PCAP_THREAD_PACKET_INVALID_UDP, 199 PCAP_THREAD_PACKET_INVALID_TCP, 200 PCAP_THREAD_PACKET_IS_FRAGMENT, 201 PCAP_THREAD_PACKET_INVALID_FRAGMENT, 202 PCAP_THREAD_PACKET_ENOMEM, 203 PCAP_THREAD_PACKET_EMUTEX, 204 PCAP_THREAD_PACKET_FRAGMENTED_GREHDR, 205 PCAP_THREAD_PACKET_FRAGMENTED_ICMPHDR, 206 PCAP_THREAD_PACKET_FRAGMENTED_ICMPV6HDR, 207 PCAP_THREAD_PACKET_FRAGMENTED_UDPHDR, 208 PCAP_THREAD_PACKET_FRAGMENTED_TCPHDR 209 }; 210 211 typedef struct pcap_thread_packet pcap_thread_packet_t; 212 struct pcap_thread_packet { 213 unsigned short have_prevpkt : 1; 214 unsigned short have_pkthdr : 1; 215 unsigned short have_linux_sll : 1; 216 unsigned short have_ethhdr : 1; 217 unsigned short have_nullhdr : 1; 218 unsigned short have_loophdr : 1; 219 unsigned short have_ieee802hdr : 1; 220 unsigned short have_grehdr : 1; 221 unsigned short have_gre : 1; 222 unsigned short have_iphdr : 1; 223 unsigned short have_ip6hdr : 1; 224 unsigned short have_ip6frag : 1; 225 unsigned short have_ip6rtdst : 1; 226 unsigned short have_icmphdr : 1; 227 unsigned short have_icmpv6hdr : 1; 228 unsigned short have_udphdr : 1; 229 unsigned short have_tcphdr : 1; 230 unsigned short have_tcpopts : 1; 231 unsigned short have_ippadding : 1; 232 unsigned short have_ip6padding : 1; 233 234 const char* name; 235 int dlt; 236 pcap_thread_packet_t* prevpkt; 237 struct pcap_pkthdr pkthdr; 238 struct pcap_thread_linux_sll linux_sll; 239 struct ether_header ethhdr; 240 struct pcap_thread_null_hdr nullhdr; 241 struct pcap_thread_loop_hdr loophdr; 242 struct pcap_thread_ieee802_hdr ieee802hdr; 243 struct pcap_thread_gre_hdr grehdr; 244 struct pcap_thread_gre gre; 245 struct ip iphdr; 246 struct ip6_hdr ip6hdr; 247 struct ip6_frag ip6frag; 248 uint8_t ip6frag_payload; 249 struct in6_addr ip6rtdst; 250 struct { 251 u_int8_t type; 252 u_int8_t code; 253 u_int16_t checksum; 254 } icmphdr; 255 struct { 256 u_int8_t icmp6_type; 257 u_int8_t icmp6_code; 258 u_int16_t icmp6_cksum; 259 } icmpv6hdr; 260 struct { 261 union { 262 struct { 263 u_int16_t uh_sport; 264 u_int16_t uh_dport; 265 u_int16_t uh_ulen; 266 u_int16_t uh_sum; 267 }; 268 struct { 269 u_int16_t source; 270 u_int16_t dest; 271 u_int16_t len; 272 u_int16_t check; 273 }; 274 }; 275 } udphdr; 276 struct { 277 union { 278 struct { 279 u_int16_t th_sport; 280 u_int16_t th_dport; 281 u_int32_t th_seq; 282 u_int32_t th_ack; 283 #if __BYTE_ORDER == __LITTLE_ENDIAN 284 u_int8_t th_x2 : 4; 285 u_int8_t th_off : 4; 286 #endif 287 #if __BYTE_ORDER == __BIG_ENDIAN 288 u_int8_t th_off : 4; 289 u_int8_t th_x2 : 4; 290 #endif 291 u_int8_t th_flags; 292 u_int16_t th_win; 293 u_int16_t th_sum; 294 u_int16_t th_urp; 295 }; 296 struct { 297 u_int16_t source; 298 u_int16_t dest; 299 u_int32_t seq; 300 u_int32_t ack_seq; 301 #if __BYTE_ORDER == __LITTLE_ENDIAN 302 u_int16_t res1 : 4; 303 u_int16_t doff : 4; 304 u_int16_t fin : 1; 305 u_int16_t syn : 1; 306 u_int16_t rst : 1; 307 u_int16_t psh : 1; 308 u_int16_t ack : 1; 309 u_int16_t urg : 1; 310 u_int16_t res2 : 2; 311 #elif __BYTE_ORDER == __BIG_ENDIAN 312 u_int16_t doff : 4; 313 u_int16_t res1 : 4; 314 u_int16_t res2 : 2; 315 u_int16_t urg : 1; 316 u_int16_t ack : 1; 317 u_int16_t psh : 1; 318 u_int16_t rst : 1; 319 u_int16_t syn : 1; 320 u_int16_t fin : 1; 321 #endif 322 u_int16_t window; 323 u_int16_t check; 324 u_int16_t urg_ptr; 325 }; 326 }; 327 } tcphdr; 328 u_int8_t tcpopts[64]; 329 size_t tcpopts_len; 330 331 size_t ippadding; 332 size_t ip6padding; 333 334 pcap_thread_packet_state_t state; 335 }; 336 337 typedef enum pcap_thread_queue_mode pcap_thread_queue_mode_t; 338 typedef struct pcap_thread pcap_thread_t; 339 typedef void (*pcap_thread_callback_t)(u_char* user, const struct pcap_pkthdr* pkthdr, const u_char* pkt, const char* name, int dlt); 340 typedef void (*pcap_thread_layer_callback_t)(u_char* user, const pcap_thread_packet_t* packet, const u_char* payload, size_t length); 341 typedef void (*pcap_thread_stats_callback_t)(u_char* user, const struct pcap_stat* stats, const char* name, int dlt); 342 #ifndef HAVE_PCAP_DIRECTION_T 343 typedef int pcap_direction_t; 344 #endif 345 typedef struct pcap_thread_pcaplist pcap_thread_pcaplist_t; 346 typedef enum pcap_thread_activate_mode pcap_thread_activate_mode_t; 347 348 enum pcap_thread_queue_mode { 349 PCAP_THREAD_QUEUE_MODE_COND, 350 PCAP_THREAD_QUEUE_MODE_WAIT, 351 PCAP_THREAD_QUEUE_MODE_YIELD, 352 PCAP_THREAD_QUEUE_MODE_DROP, 353 PCAP_THREAD_QUEUE_MODE_DIRECT 354 }; 355 356 enum pcap_thread_activate_mode { 357 PCAP_THREAD_ACTIVATE_MODE_IMMEDIATE, 358 PCAP_THREAD_ACTIVATE_MODE_DELAYED 359 }; 360 361 #ifdef HAVE_PCAP_DIRECTION_T 362 #define PCAP_THREAD_T_INIT_DIRECTION_T 0, 363 #else 364 #define PCAP_THREAD_T_INIT_DIRECTION_T 365 #endif 366 367 #ifdef HAVE_PTHREAD 368 #define PCAP_THREAD_T_INIT_QUEUE PTHREAD_COND_INITIALIZER, PTHREAD_COND_INITIALIZER, PTHREAD_MUTEX_INITIALIZER, \ 369 0, 0, 0, 0, 0, 0, 370 #else 371 #define PCAP_THREAD_T_INIT_QUEUE 372 #endif 373 374 #ifdef PCAP_TSTAMP_PRECISION_MICRO 375 #define PCAP_THREAD_T_INIT_PRECISION PCAP_TSTAMP_PRECISION_MICRO 376 #else 377 #define PCAP_THREAD_T_INIT_PRECISION 0 378 #endif 379 380 typedef void* (*pcap_thread_layer_callback_frag_new_t)(void* conf, u_char* user); 381 typedef void (*pcap_thread_layer_callback_frag_free_t)(void* ctx); 382 typedef pcap_thread_packet_state_t (*pcap_thread_layer_callback_frag_reassemble_t)(void* ctx, const pcap_thread_packet_t* packet, const u_char* payload, size_t length, pcap_thread_packet_t** whole_packet, const u_char** whole_payload, size_t* whole_length); 383 typedef void (*pcap_thread_layer_callback_frag_release_t)(void* ctx, const pcap_thread_packet_t* packet, const u_char* payload, size_t length); 384 385 /* clang-format off */ 386 #define PCAP_THREAD_LAYER_CALLBACK_FRAG_T_INIT { \ 387 0, 0, 0, 0, 0, \ 388 } 389 /* clang-format on */ 390 391 typedef struct pcap_thread_layer_callback_frag pcap_thread_layer_callback_frag_t; 392 struct pcap_thread_layer_callback_frag { 393 void* conf; 394 pcap_thread_layer_callback_frag_new_t new; 395 pcap_thread_layer_callback_frag_free_t free; 396 pcap_thread_layer_callback_frag_reassemble_t reassemble; 397 pcap_thread_layer_callback_frag_release_t release; 398 }; 399 400 /* clang-format off */ 401 #define PCAP_THREAD_T_INIT { \ 402 0, 0, 0, 0, \ 403 0, 1, 0, PCAP_THREAD_DEFAULT_QUEUE_MODE, PCAP_THREAD_DEFAULT_QUEUE_SIZE, \ 404 PCAP_THREAD_T_INIT_QUEUE \ 405 0, 0, 0, 0, PCAP_THREAD_DEFAULT_TIMEOUT, \ 406 0, 0, PCAP_THREAD_T_INIT_PRECISION, 0, \ 407 PCAP_THREAD_T_INIT_DIRECTION_T \ 408 0, 0, 0, 1, PCAP_NETMASK_UNKNOWN, \ 409 0, 0, \ 410 0, "", 0, 0, \ 411 { 0, 0 }, { 0, 0 }, \ 412 PCAP_THREAD_DEFAULT_ACTIVATE_MODE, \ 413 0, 0, 0, 0, 0, 0, 0, 0, PCAP_THREAD_LAYER_CALLBACK_FRAG_T_INIT, 0, PCAP_THREAD_LAYER_CALLBACK_FRAG_T_INIT, 0, 0, 0, 0, \ 414 0 \ 415 } 416 /* clang-format on */ 417 418 struct pcap_thread { 419 unsigned short have_timestamp_precision : 1; 420 unsigned short have_timestamp_type : 1; 421 unsigned short have_direction : 1; 422 unsigned short was_stopped : 1; 423 424 int running; 425 int use_threads; 426 int use_layers; 427 pcap_thread_queue_mode_t queue_mode; 428 size_t queue_size; 429 430 #ifdef HAVE_PTHREAD 431 pthread_cond_t have_packets; 432 pthread_cond_t can_write; 433 pthread_mutex_t mutex; 434 435 struct pcap_pkthdr* pkthdr; 436 u_char* pkt; 437 pcap_thread_pcaplist_t** pcaplist_pkt; 438 size_t read_pos; 439 size_t write_pos; 440 size_t pkts; 441 #endif 442 443 int snapshot; 444 int snaplen; 445 int promiscuous; 446 int monitor; 447 int timeout; 448 449 int buffer_size; 450 int timestamp_type; 451 int timestamp_precision; 452 int immediate_mode; 453 454 #ifdef HAVE_PCAP_DIRECTION_T 455 pcap_direction_t direction; 456 #endif 457 458 char* filter; 459 size_t filter_len; 460 int filter_errno; 461 int filter_optimize; 462 bpf_u_int32 filter_netmask; 463 464 pcap_thread_callback_t callback; 465 pcap_thread_callback_t dropback; 466 467 int status; 468 char errbuf[PCAP_ERRBUF_SIZE]; 469 pcap_thread_pcaplist_t* pcaplist; 470 pcap_thread_pcaplist_t* step; 471 472 struct timeval timedrun; 473 struct timeval timedrun_to; 474 475 pcap_thread_activate_mode_t activate_mode; 476 477 pcap_thread_layer_callback_t callback_linux_sll; 478 pcap_thread_layer_callback_t callback_ether; 479 pcap_thread_layer_callback_t callback_null; 480 pcap_thread_layer_callback_t callback_loop; 481 pcap_thread_layer_callback_t callback_ieee802; 482 pcap_thread_layer_callback_t callback_gre; 483 pcap_thread_layer_callback_t callback_ip; 484 pcap_thread_layer_callback_t callback_ipv4; 485 pcap_thread_layer_callback_frag_t callback_ipv4_frag; 486 pcap_thread_layer_callback_t callback_ipv6; 487 pcap_thread_layer_callback_frag_t callback_ipv6_frag; 488 pcap_thread_layer_callback_t callback_icmp; 489 pcap_thread_layer_callback_t callback_icmpv6; 490 pcap_thread_layer_callback_t callback_udp; 491 pcap_thread_layer_callback_t callback_tcp; 492 493 pcap_thread_layer_callback_t callback_invalid; 494 }; 495 496 #define PCAP_THREAD_SET_ERRBUF(x, y) strncpy(x->errbuf, y, sizeof(x->errbuf) - 1) 497 498 #ifdef HAVE_PTHREAD 499 #define PCAP_THREAD_PCAPLIST_T_INIT_THREAD 0, 500 #else 501 #define PCAP_THREAD_PCAPLIST_T_INIT_THREAD 502 #endif 503 504 /* clang-format off */ 505 #define PCAP_THREAD_PCAPLIST_T_INIT { \ 506 0, 0, 0, \ 507 0, 0, 0, 0, 0, 0, 0, 0, \ 508 0, \ 509 PCAP_THREAD_PCAPLIST_T_INIT_THREAD \ 510 { 0, 0 }, \ 511 0, \ 512 } 513 /* clang-format on */ 514 515 struct pcap_thread_pcaplist { 516 unsigned short have_bpf : 1; 517 unsigned short have_ipv4_frag_ctx : 1; 518 unsigned short have_ipv6_frag_ctx : 1; 519 520 pcap_thread_pcaplist_t* next; 521 char* name; 522 pcap_t* pcap; 523 void* user; 524 int running; 525 int is_offline; 526 void* ipv4_frag_ctx; 527 void* ipv6_frag_ctx; 528 529 pcap_thread_t* pcap_thread; 530 531 #ifdef HAVE_PTHREAD 532 pthread_t thread; 533 #endif 534 535 struct bpf_program bpf; 536 537 pcap_thread_callback_t layer_callback; 538 }; 539 540 const char* pcap_thread_version_str(void); 541 542 int pcap_thread_version_major(void); 543 int pcap_thread_version_minor(void); 544 int pcap_thread_version_patch(void); 545 546 pcap_thread_t* pcap_thread_create(void); 547 void pcap_thread_free(pcap_thread_t* pcap_thread); 548 549 int pcap_thread_use_threads(const pcap_thread_t* pcap_thread); 550 int pcap_thread_set_use_threads(pcap_thread_t* pcap_thread, const int use_threads); 551 int pcap_thread_use_layers(const pcap_thread_t* pcap_thread); 552 int pcap_thread_set_use_layers(pcap_thread_t* pcap_thread, const int use_layers); 553 pcap_thread_queue_mode_t pcap_thread_queue_mode(const pcap_thread_t* pcap_thread); 554 int pcap_thread_set_queue_mode(pcap_thread_t* pcap_thread, const pcap_thread_queue_mode_t queue_mode); 555 struct timeval pcap_thread_queue_wait(const pcap_thread_t* pcap_thread); 556 int pcap_thread_set_queue_wait(pcap_thread_t* pcap_thread, const struct timeval queue_wait); 557 pcap_thread_queue_mode_t pcap_thread_callback_queue_mode(const pcap_thread_t* pcap_thread); 558 int pcap_thread_set_callback_queue_mode(pcap_thread_t* pcap_thread, const pcap_thread_queue_mode_t callback_queue_mode); 559 struct timeval pcap_thread_callback_queue_wait(const pcap_thread_t* pcap_thread); 560 int pcap_thread_set_callback_queue_wait(pcap_thread_t* pcap_thread, const struct timeval callback_queue_wait); 561 int pcap_thread_snapshot(const pcap_thread_t* pcap_thread); 562 int pcap_thread_snaplen(const pcap_thread_t* pcap_thread); 563 int pcap_thread_set_snaplen(pcap_thread_t* pcap_thread, const int snaplen); 564 int pcap_thread_promiscuous(const pcap_thread_t* pcap_thread); 565 int pcap_thread_set_promiscuous(pcap_thread_t* pcap_thread, const int promiscuous); 566 int pcap_thread_monitor(const pcap_thread_t* pcap_thread); 567 int pcap_thread_set_monitor(pcap_thread_t* pcap_thread, const int monitor); 568 int pcap_thread_timeout(const pcap_thread_t* pcap_thread); 569 int pcap_thread_set_timeout(pcap_thread_t* pcap_thread, const int timeout); 570 int pcap_thread_buffer_size(const pcap_thread_t* pcap_thread); 571 int pcap_thread_set_buffer_size(pcap_thread_t* pcap_thread, const int buffer_size); 572 int pcap_thread_timestamp_type(const pcap_thread_t* pcap_thread); 573 int pcap_thread_set_timestamp_type(pcap_thread_t* pcap_thread, const int timestamp_type); 574 int pcap_thread_timestamp_precision(const pcap_thread_t* pcap_thread); 575 int pcap_thread_set_timestamp_precision(pcap_thread_t* pcap_thread, const int timestamp_precision); 576 int pcap_thread_immediate_mode(const pcap_thread_t* pcap_thread); 577 int pcap_thread_set_immediate_mode(pcap_thread_t* pcap_thread, const int immediate_mode); 578 pcap_direction_t pcap_thread_direction(const pcap_thread_t* pcap_thread); 579 int pcap_thread_set_direction(pcap_thread_t* pcap_thread, const pcap_direction_t direction); 580 const char* pcap_thread_filter(const pcap_thread_t* pcap_thread); 581 int pcap_thread_set_filter(pcap_thread_t* pcap_thread, const char* filter, const size_t filter_len); 582 int pcap_thread_clear_filter(pcap_thread_t* pcap_thread); 583 int pcap_thread_filter_errno(const pcap_thread_t* pcap_thread); 584 int pcap_thread_filter_optimze(const pcap_thread_t* pcap_thread); 585 int pcap_thread_set_filter_optimize(pcap_thread_t* pcap_thread, const int filter_optimize); 586 bpf_u_int32 pcap_thread_filter_netmask(const pcap_thread_t* pcap_thread); 587 int pcap_thread_set_filter_netmask(pcap_thread_t* pcap_thread, const bpf_u_int32 filter_netmask); 588 struct timeval pcap_thread_timedrun(const pcap_thread_t* pcap_thread); 589 int pcap_thread_set_timedrun(pcap_thread_t* pcap_thread, const struct timeval timedrun); 590 struct timeval pcap_thread_timedrun_to(const pcap_thread_t* pcap_thread); 591 int pcap_thread_set_timedrun_to(pcap_thread_t* pcap_thread, const struct timeval timedrun_to); 592 pcap_thread_activate_mode_t pcap_thread_activate_mode(const pcap_thread_t* pcap_thread); 593 int pcap_thread_set_activate_mode(pcap_thread_t* pcap_thread, const pcap_thread_activate_mode_t activate_mode); 594 int pcap_thread_was_stopped(const pcap_thread_t* pcap_thread); 595 596 size_t pcap_thread_queue_size(const pcap_thread_t* pcap_thread); 597 int pcap_thread_set_queue_size(pcap_thread_t* pcap_thread, const size_t queue_size); 598 599 int pcap_thread_set_callback(pcap_thread_t* pcap_thread, pcap_thread_callback_t callback); 600 int pcap_thread_set_dropback(pcap_thread_t* pcap_thread, pcap_thread_callback_t dropback); 601 602 int pcap_thread_set_callback_linux_sll(pcap_thread_t* pcap_thread, pcap_thread_layer_callback_t callback_linux_sll); 603 int pcap_thread_set_callback_ether(pcap_thread_t* pcap_thread, pcap_thread_layer_callback_t callback_ether); 604 int pcap_thread_set_callback_null(pcap_thread_t* pcap_thread, pcap_thread_layer_callback_t callback_null); 605 int pcap_thread_set_callback_loop(pcap_thread_t* pcap_thread, pcap_thread_layer_callback_t callback_loop); 606 int pcap_thread_set_callback_ieee802(pcap_thread_t* pcap_thread, pcap_thread_layer_callback_t callback_ieee802); 607 int pcap_thread_set_callback_gre(pcap_thread_t* pcap_thread, pcap_thread_layer_callback_t callback_gre); 608 int pcap_thread_set_callback_ip(pcap_thread_t* pcap_thread, pcap_thread_layer_callback_t callback_ip); 609 int pcap_thread_set_callback_ipv4(pcap_thread_t* pcap_thread, pcap_thread_layer_callback_t callback_ipv4); 610 int pcap_thread_set_callback_ipv4_frag(pcap_thread_t* pcap_thread, pcap_thread_layer_callback_frag_t callback_ipv4_frag); 611 int pcap_thread_set_callback_ipv6(pcap_thread_t* pcap_thread, pcap_thread_layer_callback_t callback_ipv6); 612 int pcap_thread_set_callback_ipv6_frag(pcap_thread_t* pcap_thread, pcap_thread_layer_callback_frag_t callback_ipv6_frag); 613 int pcap_thread_set_callback_icmp(pcap_thread_t* pcap_thread, pcap_thread_layer_callback_t callback_icmp); 614 int pcap_thread_set_callback_icmpv6(pcap_thread_t* pcap_thread, pcap_thread_layer_callback_t callback_icmpv6); 615 int pcap_thread_set_callback_udp(pcap_thread_t* pcap_thread, pcap_thread_layer_callback_t callback_udp); 616 int pcap_thread_set_callback_tcp(pcap_thread_t* pcap_thread, pcap_thread_layer_callback_t callback_tcp); 617 int pcap_thread_set_callback_invalid(pcap_thread_t* pcap_thread, pcap_thread_layer_callback_t callback_tcp); 618 619 int pcap_thread_open(pcap_thread_t* pcap_thread, const char* device, void* user); 620 int pcap_thread_open_offline(pcap_thread_t* pcap_thread, const char* file, void* user); 621 int pcap_thread_add(pcap_thread_t* pcap_thread, const char* name, pcap_t* pcap, void* user); 622 int pcap_thread_activate(pcap_thread_t* pcap_thread); 623 int pcap_thread_close(pcap_thread_t* pcap_thread); 624 625 int pcap_thread_run(pcap_thread_t* pcap_thread); 626 int pcap_thread_next(pcap_thread_t* pcap_thread); 627 int pcap_thread_next_reset(pcap_thread_t* pcap_thread); 628 int pcap_thread_stop(pcap_thread_t* pcap_thread); 629 630 int pcap_thread_stats(pcap_thread_t* pcap_thread, pcap_thread_stats_callback_t callback, u_char* user); 631 632 int pcap_thread_status(const pcap_thread_t* pcap_thread); 633 const char* pcap_thread_errbuf(const pcap_thread_t* pcap_thread); 634 const char* pcap_thread_strerr(int error); 635 636 #ifdef __cplusplus 637 } 638 #endif 639 640 #endif /* __pcap_thread_h */ 641