How to set the socket type and the protocol of a socket using create_connection?

2012-08-20 Thread Guillaume Comte
Hello everyone, I want to use socket.create_connection(...) to set a source address in a ping implementation in python. But how can I then set the type and the protocol? Because, before, I did: icmp = socket.getprotobyname("icmp") my_socket = socket.socket(socket.AF_INET, socket.SOCK_RAW, icmp)

Re: How to set the socket type and the protocol of a socket using create_connection?

2012-08-20 Thread Guillaume Comte
In fact, socket.create_connection is for TCP only so I cannot use it for a ping implementation. Does anyone have an idea about how to be able to set a source address for ICMP messages? -- http://mail.python.org/mailman/listinfo/python-list

Re: How to set the socket type and the protocol of a socket using create_connection?

2012-08-20 Thread Guillaume Comte
Le lundi 20 août 2012 15:38:14 UTC+2, Hans Mulder a écrit : > On 20/08/12 14:36:58, Guillaume Comte wrote: > > > In fact, socket.create_connection is for TCP only so I cannot use it for a > > ping implementation. > > > > Why are you trying to reimplement ping

Re: How to set the socket type and the protocol of a socket using create_connection?

2012-08-21 Thread Guillaume Comte
Unfortunatly, my_socket.bind((src_addr, 1)) doesn't work. I get the error message: "socket.error: [Errno 49] Can't assign requested address"... I've tried to change the protocol to IPPROTO_RAW. Here is a simple example of the code: import socket import os import struct import time import sele

Re: How to set the socket type and the protocol of a socket using create_connection?

2012-08-22 Thread Guillaume Comte
Le mercredi 22 août 2012 04:10:43 UTC+2, Dennis Lee Bieber a écrit : > On Tue, 21 Aug 2012 10:00:28 -0700 (PDT), Guillaume Comte > > declaimed the following in > > gmane.comp.python.general: > > > > A later follow-up > > > Unfortunatly, my_socket

Re: How to set the socket type and the protocol of a socket using create_connection?

2012-08-22 Thread Guillaume Comte
I've managed to build the IP header. I've put the source and destination addresses in this header but it doesn't change the real source address... I'm trying to read the ping source code but I'm lost... -- http://mail.python.org/mailman/listinfo/python-list

Re: How to set the socket type and the protocol of a socket using create_connection?

2012-08-22 Thread Guillaume Comte
Le mercredi 22 août 2012 11:03:11 UTC+2, Hans Mulder a écrit : > > On my laptop, 0 appears to be the only port number that bind accepts > > for a raw socket. Other numbers I tried all raise "socket.error: > > [Errno 49] Can't assign requested address". > > > > But this might depend on your