pcap_t 구조체
pcap_t 구조체는 네트워크 디바이스나 패킷에 들어있는 pcap파일에서 패킷을 읽는데 사용되는 Handle이다.
이를 사용하는 함수로는 pcap_open_live(), pcap_create() 등을 통해 생성할 수 있고 , pcap_loop(), pcap_dispatch()등에 사용된다.
Source Code[libpcap-github]
PATH: libpcap/pcap/pcap.h
typedef struct pcap pcap_t;
PATH: libpcap/pcap-int.h
>> 가독성을 위해 WIN32 관련 코드는 제거함.
struct pcap { /* 라이브 캡처에에서 패킷을 읽기위해 메소드를 호출합니다. * Method to call to read packets on a live capture. */ read_op_t read_op; /* 저장된 파일에서 패킷을 읽기위해 메소드를 호출합니다. * Method to call to read packets from a savefile. */ int (*next_packet_op)(pcap_t *, struct pcap_pkthdr *, u_char **); /* * Read buffer. */ u_int bufsize; void *buffer; u_char *bp; int cc; /* packet-reading 루프에서 강제로 빠져나오기 위한 flag 설정 */ int break_loop; /* flag set to force break from packet-reading loop */ /* private 데이터를 위한 메소드들 */ void *priv; /* private data for methods */ int swapped; /* 라이브 캡처라면 null, 저장된파일이라면 non-null */ FILE *rfile; /* null if live capture, non-null if savefile */ u_int fddipad; /* 종료시 비워야할 open pcap 리스트 */ struct pcap *next; /* list of open pcaps that need stuff cleared on close */ /* 파일 버전 번호; 저장 파일에 대해서만 의미가 있지만, * (실수로) 버전 번호를 요청하는 앱이 항상 0 값을 갖도록 * 여기애 유지시킴. * File version number; meaningful only for a savefile, but we * keep it here so that apps that (mistakenly) ask for the * version numbers will get the same zero values that they * always did. */ int version_major; int version_minor; int snapshot; /* 네트워크 링크 타입 */ int linktype; /* Network linktype */ /* 파일의 링크타입 필드 안에 저장된 확장 정보 */ int linktype_ext; /* Extended information stored in the linktype field of a file */ /* 타임존 오프셋 */ int tzoff; /* timezone offset */ /* 정렬을 위한 오프셋 */ int offset; /* offset for proper alignment */ /* 캡처가 시작되면 true */ int activated; /* true if the capture is really started */ /* pcap_open_live()로 시작한다면, */ int oldstyle; /* if we're opening with pcap_open_live() */ struct pcap_opt opt; /* pcak_next()를 위한 위치 * Place holder for pcap_next(). */ u_char *pkt; /* direction의 패킷만 받아드림 */ /* We're accepting only packets in this direction/these directions. */ pcap_direction_t direction; /* BPF 코드 생성에 영향을 주는 flag * Flags to affect BPF code generation. */ int bpf_codegen_flags; /* 커널에 bpf가없는 경우 필터 코드의 위치 표시 * Placeholder for filter code if bpf not in kernel. */ struct bpf_program fcode; char errbuf[PCAP_ERRBUF_SIZE + 1]; int dlt_count; u_int *dlt_list; int tstamp_type_count; u_int *tstamp_type_list; int tstamp_precision_count; u_int *tstamp_precision_list; /* pcap_next_ex()가 동작하기 위해 필요한 것 */ struct pcap_pkthdr pcap_header; /* This is needed for the pcap_next_ex() to work */ /* * More methods. */ activate_op_t activate_op; can_set_rfmon_op_t can_set_rfmon_op; inject_op_t inject_op; save_current_filter_op_t save_current_filter_op; setfilter_op_t setfilter_op; setdirection_op_t setdirection_op; set_datalink_op_t set_datalink_op; getnonblock_op_t getnonblock_op; setnonblock_op_t setnonblock_op; stats_op_t stats_op; /* pcap_next()/pcap_next_ex()를 사용하기 위한 callback으로 사용할 루틴 * Routine to use as callback for pcap_next()/pcap_next_ex(). */ pcap_handler oneshot_callback; cleanup_op_t cleanup_op; };