I wrote client which sending packets to a server and now I need create an adversary which listens (on localhost) to the connection between the client and the server, and prints the packet contents, the adversary is not a part of the connection. I am having some problems with that I know I need to use raw socket but I don't know why i can't do this.
server:
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
server_address = ('localhost', 12321)
print >> sys.stderr, 'starting up on localhost port 12321'
sock.bind(server_address)
while True:
data, address = sock.recvfrom(100)
if data:
sent = sock.sendto(data, address)
print >> sys.stderr, 'sent %s bytes back to %s' % (sent, address)
client:
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
server_address = ('localhost', 12321)
i = 0
while True:
f = open("poem.txt", "r")
for line in f:
time.sleep(3)
i += 1
sent = sock.sendto(line, server_address)
data, server = sock.recvfrom(100)
f.close()
print >>sys.stderr, 'closing socket'
sock.close()
adversary:
s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_UDP)
s.bind(("localhost", 1))
s.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)
s.ioctl(socket.SIO_RCVALL, socket.RCVALL_ON)
while True:
print s.recvfrom(12321)
in the adversary I get all kind of messages but not those the client send (the client sent a song). please help...