public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [patch] allow write() on SOCK_PACKET sockets
@ 2004-10-11 17:18 Stas Sergeev
  2004-10-11 21:34 ` Herbert Xu
  0 siblings, 1 reply; 6+ messages in thread
From: Stas Sergeev @ 2004-10-11 17:18 UTC (permalink / raw)
  To: Linux kernel; +Cc: linux-net

[-- Attachment #1: Type: text/plain, Size: 428 bytes --]

Hello.

Unless I am really missing something, there
seem to be no reason why the SOCK_PACKET code
does not allow to use write() or send() when
the socket was bound, and insists on using
sendto(). SOCK_RAW code, in comparison, allows
write() after bind().
Attached patch allows write() for the SOCK_PACKET
sockets when they are bound.
Can this be applied, or am I missing the point?

Signed-off-by: Stas Sergeev <stsp@aknet.ru>


[-- Attachment #2: pkt_send.diff --]
[-- Type: text/x-patch, Size: 916 bytes --]

--- linux/net/packet/af_packet.c	2004-06-26 15:20:54.000000000 +0400
+++ linux/net/packet/af_packet.c	2004-10-10 02:25:41.000000000 +0400
@@ -322,16 +322,23 @@
 			return(-EINVAL);
 		if (msg->msg_namelen==sizeof(struct sockaddr_pkt))
 			proto=saddr->spkt_protocol;
+		/*
+		 *	Find the device first to size check it 
+		 */
+
+		saddr->spkt_device[13] = 0;
+		dev = dev_get_by_name(saddr->spkt_device);
 	}
 	else
-		return(-ENOTCONN);	/* SOCK_PACKET must be sent giving an address */
-
-	/*
-	 *	Find the device first to size check it 
-	 */
+	{
+		struct packet_opt *po = pkt_sk(sk);
+		if (!po->running || !po->prot_hook.dev)
+			return -ENOTCONN;	/* SOCK_PACKET must be sent giving an address */
+		proto = po->prot_hook.type;
+		dev = po->prot_hook.dev;
+		dev_hold(dev);
+	}
 
-	saddr->spkt_device[13] = 0;
-	dev = dev_get_by_name(saddr->spkt_device);
 	err = -ENODEV;
 	if (dev == NULL)
 		goto out_unlock;

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2004-10-14  8:26 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-10-11 17:18 [patch] allow write() on SOCK_PACKET sockets Stas Sergeev
2004-10-11 21:34 ` Herbert Xu
2004-10-12  3:33   ` Stas Sergeev
2004-10-14  2:12     ` Herbert Xu
2004-10-14  3:45       ` Stas Sergeev
2004-10-14  8:26         ` Herbert Xu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox