public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andi Kleen <ak@suse.de>
To: unlisted-recipients:; (no To-header on input)@localhost.localdomain
Cc: linux-kernel@vger.kernel.org, davem@redhat.com
Subject: Re: recvfrom and sockaddr_in.sin_port
Date: 08 Jul 2001 21:28:27 +0200	[thread overview]
Message-ID: <ouppubbfcf8.fsf@pigdrop.muc.suse.de> (raw)
In-Reply-To: Adam's message of "8 Jul 2001 18:23:35 +0200"

Adam <adam@eax.com> writes:
> 
> 	and as show in above example and other repeated test, the port
> 	part is always set to 0. Shouldn't that be set to port number?

SOCK_RAW has no ports, so no.

> 
> 	on similar token the "padding" part after the IP is always set
> 	to the same pattern. Shouldn't it rather be zeroed, or be
> 	some random data?

It should stay at the old value or alternatively be zeroed. That's a 
kernel bug.

Here is a patch that implements the first alternative. David, please consider
applying.

diff -burp linux/include/linux/in.h linux-work/include/linux/in.h
--- linux/include/linux/in.h	Thu Jul  5 13:18:27 2001
+++ linux-work/include/linux/in.h	Sun Jul  8 19:05:30 2001
@@ -109,6 +109,10 @@ struct in_pktinfo
 };
 
 /* Structure describing an Internet (IP) socket address. */
+/* Note here and in others places is the assumption made that there
+   are no holes in in this structure. This is ok for all architectures
+   which layout structures members at worst to their natural
+   alignment. -AK */
 #define __SOCK_SIZE__	16		/* sizeof(struct sockaddr)	*/
 struct sockaddr_in {
   sa_family_t		sin_family;	/* Address family		*/
@@ -119,7 +123,7 @@ struct sockaddr_in {
   unsigned char		__pad[__SOCK_SIZE__ - sizeof(short int) -
 			sizeof(unsigned short int) - sizeof(struct in_addr)];
 };
-#define sin_zero	__pad		/* for BSD UNIX comp. -FvK	*/
+#define sin_zero	__pad
 
 
 /*
diff -burp linux/net/ipv4/af_inet.c linux-work/net/ipv4/af_inet.c
--- linux/net/ipv4/af_inet.c	Wed Jul  4 17:21:32 2001
+++ linux-work/net/ipv4/af_inet.c	Sun Jul  8 19:05:31 2001
@@ -729,7 +729,7 @@ static int inet_getname(struct socket *s
 		sin->sin_port = sk->sport;
 		sin->sin_addr.s_addr = addr;
 	}
-	*uaddr_len = sizeof(*sin);
+	*uaddr_len = sizeof(offsetof(struct sockaddr_in, sin_zero));
 	return(0);
 }
 
diff -burp linux/net/ipv4/raw.c linux-work/net/ipv4/raw.c
--- linux/net/ipv4/raw.c	Wed Jul  4 17:21:32 2001
+++ linux-work/net/ipv4/raw.c	Sun Jul  8 19:06:10 2001
@@ -493,7 +493,7 @@ int raw_recvmsg(struct sock *sk, struct 
 		goto out;
 
 	if (addr_len)
-		*addr_len = sizeof(*sin);
+		*addr_len = offsetof(struct sockaddr_in, sin_zero);
 
 	if (flags & MSG_ERRQUEUE) {
 		err = ip_recv_error(sk, msg, len);
diff -burp linux/net/ipv4/udp.c linux-work/net/ipv4/udp.c
--- linux/net/ipv4/udp.c	Thu Apr 12 21:11:39 2001
+++ linux-work/net/ipv4/udp.c	Sun Jul  8 19:05:31 2001
@@ -635,7 +635,7 @@ int udp_recvmsg(struct sock *sk, struct 
 	 *	Check any passed addresses
 	 */
 	if (addr_len)
-		*addr_len=sizeof(*sin);
+		*addr_len=offsetof(struct sockaddr_in, sin_zero);
 
 	if (flags & MSG_ERRQUEUE)
 		return ip_recv_error(sk, msg, len);


-Andi

             reply	other threads:[~2001-07-08 19:28 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-07-08 19:28 Andi Kleen [this message]
  -- strict thread matches above, loose matches on Subject: below --
2001-07-08 17:14 recvfrom and sockaddr_in.sin_port Adam
2001-07-08 17:05 ` Chris Wedgwood
2001-07-08 18:08   ` Adam
2001-07-08 17:21     ` Chris Wedgwood
2001-07-08 18:42       ` Adam
2001-07-08 18:31         ` Chris Wedgwood

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ouppubbfcf8.fsf@pigdrop.muc.suse.de \
    --to=ak@suse.de \
    --cc=davem@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox