I've hit the wall trying to receive some data from a socket and hope potential cross posting won't upset too many of you. In summary, I'm playing with a DHCP client written in python just to get a feel for it before getting down to serious work (see the PS for more info)
This segment of code sends a packet, using tcpdump i can see a response coming from server running on another PC but i never see any data back from socket.recvfrom() - it just blocks: <snip> sock = socket.socket( socket.AF_INET, socket.SOCK_DGRAM ) sock.bind( (socket.gethostname(), CLI_PORT) ) sock.setsockopt( socket.SOL_SOCKET, socket.SO_BROADCAST, 1) cSent = sock.sendto( data, 0, ( '<broadcast>', SRV_PORT ) ) print 'sent: ', cSent, ', from', sock.getsockname() print 'status:', sock.getsockopt( socket.SOL_SOCKET, socket.SO_ERROR ) (rcvd, add) = sock.recvfrom( 512 ) print 'Got', len( rcvd ), 'bytes back' <snip> netstat tells me that the socket is still there - as long as the script is running. BTW the script runs with root privileges - the ports used are 67 and 68. The server response that i see with tcpdump looks healthy. My suspicion is that the protocol stack never passes the packet up to the socket but don't know why (the normal DHCP client daemon isn't running on this machine). Is there a way to turn on some debugging with sockets? Calling sock.setsockopt( socket.SOL_SOCKET, socket.SO_DEBUG, 1) didn't do much for me. Any pointers appreciated. TIA PS For the curious, the DHCP client is really meant to be implemented in C/C++ on a networked embedded device (needless to say, running a proprietary OS); there'll be lots of them and configuring IP address, netmask, gateway etc manually is a pain. So the python code is just a proof of concept. _______________________________________________ Tutor maillist - [email protected] http://mail.python.org/mailman/listinfo/tutor
