Created
November 16, 2017 01:35
-
-
Save picatz/22e8678b9e39966b45b8bd14055af043 to your computer and use it in GitHub Desktop.
Using pcap_open_live
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# previous code ... | |
err = LibPcap::PCAP_ERRBUF_SIZE.dup | |
cap = LibPcap.pcap_open_live("en0", 65535, 0, 1, pointerof(err)) | |
raise Exception.new("An error happened: #{String.new(err)}") if cap.null? | |
loop do | |
result = LibPcap.pcap_next_ex(cap, out pkt_header, out pkt_data) | |
case result | |
when 1 # success | |
puts pkt_data.to_slice(pkt_header.value.caplen).hexdump | |
when 0 # timeout | |
next | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment