Re: [patch] allow write() on SOCK_PACKET sockets
From: Herbert Xu
Date: Wed Oct 13 2004 - 21:16:32 EST
Stas Sergeev <stsp@xxxxxxxx> wrote:
>
> I claim that SOCK_RAW allows write() after bind()
> because a few days ago I changed dosemu code
> to use SOCK_RAW instead of SOCK_PACKET and write()
Well I just checked net/ipv4/raw.c and it's pretty clear that it does
err = -EDESTADDRREQ;
if (sk->sk_state != TCP_ESTABLISHED)
goto out;
So you need to connect before you can write. I'm intrigued that
you can write before connecting on a raw socket. Could you please
write up a minimal program that I can play with?
> SOCK_PACKET. And btw, I can use read() quite
> happily even with SOCK_PACKET, so why not
> write()...
Well read() is different. It returns all packets received on
the socket, regardless of where they came from. So for a
connectionless socket it makes perfect sense to read() before
you've called connect().
OTOH, write() and send() needs to know where the message is going
to. That's exactly what connect() provides. So it makes no sense
to write()/send() before you've called connect().
Cheers,
--
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <herbert@xxxxxxxxxxxxxxxxxxx>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/