문제 설명
libpcap으로 PPP 패킷을 스니핑하는 방법은 무엇입니까? (How to sniff PPP packet with libpcap?)
eth0 인터페이스에서 패킷을 캡처하고 다음과 같이 ip 패킷을 스니핑할 수 있습니다.
/* IP header */
struct sniff_ip {
u_char ip_vhl; /* version << 4 | header length >> 2 */
u_char ip_tos; /* type of service */
u_short ip_len; /* total length */
u_short ip_id; /* identification */
u_short ip_off; /* fragment offset field */
#define IP_RF 0x8000 /* reserved fragment flag */
#define IP_DF 0x4000 /* dont fragment flag */
#define IP_MF 0x2000 /* more fragments flag */
#define IP_OFFMASK 0x1fff /* mask for fragmenting bits */
u_char ip_ttl; /* time to live */
u_char ip_p; /* protocol */
u_short ip_sum; /* checksum */
struct in_addr ip_src,ip_dst; /* source and dest address */
};
그래서 PPP 인터페이스에서 패킷을 캡처해야 하는 경우 헤더 구조를 정의하는 방법은 무엇입니까?
이 경우 헤더의 길이가 32바이트라는 것을 알았습니다.
참조 솔루션
방법 1:
If, when you capture on the PPP device with libpcap, the pcap_datalink()
routine returns DLT_PPP
, then you define the header in the fashion indicated by the entry for LINKTYPE_PPP
/DLT_PPP
in the tcpdump.org link‑layer header types page:
PPP, as per RFC 1661 and RFC 1662; if the first 2 bytes are 0xff and 0x03, it's PPP in HDLC‑like framing, with the PPP header following those two bytes, otherwise it's PPP without framing, and the packet begins with the PPP header.
(by why、user862787)