Network programming question
Andrew Falanga
af300wsm at gmail.com
Fri Mar 14 15:24:01 UTC 2008
On Thu, Mar 13, 2008 at 11:57 PM, Patrick Mahan <mahan at mahan.org> wrote:
>
>
>
> inet_pton() clobbered the fields you pointed out. In fact the sin_family
> field was being set to 0x01 which caused your initial EADDRNOTSUPPORT error
> you were seeing. You quick change fixed that problem. However, (depending
> on how sockaddr_in structure is actually allocated) the sin_addr field was
> 0.0.0.0. This is actually an accepted form of the broadcast address for UDP
> packets. I forget exactly who the culprit was (Sun comes to mind) but there
> was a need to allow broadcasts to 0.0.0.0 (which is also know as INADDR_ANY).
> So, therefore, sendto() succeeded, just not in the way you expected. Looking
> at in_pcbconnect_setup() in the kernel shows that actually the packet is sent
> to the local primary interface address.
>
> Let's look at what really happen to that packet -
>
> "192.168.0.1" after being mangled by inet_pton() gives
> the field sin_addr.s_addr of 0x0100A8C0. This should make
> your sockaddr_in structure look like -
>
> sa.sin_len = 0x01
> sa.sin_family = 0x00
> sa.sin_port = 0xA8C0 (which is port 49320)
> sa.sin_addr.s_addr = 0x00000000
>
> So the sendto() call was sending a packet to your local interface for port 49320.
> And since UDP is a connectionless protocol, you don't have a way (unless it is
> builtin to your application protocol) to determine an error. For example, TFTP
> sends back notification for every dgram received.
>
> I hope this helps with your understanding. I highly recommend if you are going
> to do more network programming that you obtain at least some books on the subject.
>
>
> Patrick
>
Thanks much for this explanation. Books would be good, yes. I guys
got to learn somehow. Thanks for taking the time to explain it.
That's interesting that a broadcast may be sent to 0.0.0.0. I knew
that 0.0.0.0 is equal to INADDR_ANY. However, I thought it wasn't
possible to send to that address, only to bind to it locally for a
server application.
Andy
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
More information about the freebsd-questions
mailing list