Python raw sockets on freebsd

A

Anonymous

Guest
socket.error (49, "can't assign requested address")

Code:
import socket

HOST = "127.0.0.1"

s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_IP)

s.bind((HOST, 8080))

s.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)

s.listen(1)

print s.recvfrom(65565)
 
On BSD systems you can't read UDP/TCP packets with raw sockets like you can on linux. So I am not sure just how useful raw socket interface is for you as its mostly limited to intercepting ICMP packets. If thats what you want you should pass IPPROTO_ICMP as protocol type.
 
What I'm trying to do is listen on port 53/UDP for DNS requests and then process the headers of the request. When I use a SOCK_DGRAM socket though the output of listnening on the socket just produces something like "xgooglecom" for a DNS query of google.com, no headers. How do programs like tcpdump and wirshark get the full packet headers?
 
Thanks expl, that's what I was looking for.
 
Back
Top