how to use socket to get packet which destination ip is not local?

H

Hans

Hi,

Maybe it's a very simple question. I'm trying to write a dhcpclient
code with python. The dhcpclient does not have ip address at the very
beginning, it sends out dhcpdiscover and then server sends back
dhcpoffer. the dhcpoffer will use assigned ip as destination ip, but
that ip is not client's local ip yet. How can I make my socket to
receive that packet?

I tried socket bind to 0.0.0.0, but it only binds to any local ip, not
any ip which may not be local. therefore the socket cannot get that
dhcp offer packet even I can use wireshark to see that packet did come
to this pc.

How to solve it? Thanks in advance.

Rgds,

Hans
 
M

MRAB

Hi,

Maybe it's a very simple question. I'm trying to write a dhcpclient
code with python. The dhcpclient does not have ip address at the very
beginning, it sends out dhcpdiscover and then server sends back
dhcpoffer. the dhcpoffer will use assigned ip as destination ip, but
that ip is not client's local ip yet. How can I make my socket to
receive that packet?

I tried socket bind to 0.0.0.0, but it only binds to any local ip, not
any ip which may not be local. therefore the socket cannot get that
dhcp offer packet even I can use wireshark to see that packet did come
to this pc.

How to solve it? Thanks in advance.
Have you read this:

http://en.wikipedia.org/wiki/Dynamic_Host_Configuration_Protocol
 
H

Hans


Thanks for the response. Yes, I read it. it tells me how dhcp works.
But I cannot find answer for my question, dhcp response may be unicast
or broadcast depends on the flag in request. my question is how to use
socket to read that response. In my test, sniffer already shows server
sends back an offer response(unicast in my case), but because the dst-
ip in response is not local ip, then my socket cannot read it.

Can you help? thank you very much!
 
D

Dennis Lee Bieber

Thanks for the response. Yes, I read it. it tells me how dhcp works.
But I cannot find answer for my question, dhcp response may be unicast
or broadcast depends on the flag in request. my question is how to use
socket to read that response. In my test, sniffer already shows server
sends back an offer response(unicast in my case), but because the dst-
ip in response is not local ip, then my socket cannot read it.
Does http://support.microsoft.com/kb/197511 offer any hints (granted
it's for WinNT)

I presume you don't have local firewall that may be blocking inbound
broadcast UDP packets.

(Just wild guesses -- I can't find anything in Google)
 
M

Mark Wooding

Hans said:
I tried socket bind to 0.0.0.0, but it only binds to any local ip, not
any ip which may not be local. therefore the socket cannot get that
dhcp offer packet even I can use wireshark to see that packet did come
to this pc.

You must use a raw socket for this. Raw sockets are fiddly, not very
portable, and require privilege. Sorry.

-- [mdw]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top