netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: bind() fix error return on wrong address family
@ 2011-07-04 11:30 Marcus Meissner
  2011-07-05  4:38 ` David Miller
  0 siblings, 1 reply; 2+ messages in thread
From: Marcus Meissner @ 2011-07-04 11:30 UTC (permalink / raw)
  To: davem, kuznet, pekkas, jmorris, yoshfuji, kaber, netdev,
	linux-kernel
  Cc: Marcus Meissner, Marcus Meissner, Reinhard Max

Hi,

Reinhard Max also pointed out that the error should EAFNOSUPPORT according
to POSIX.

The Linux manpages have it as EINVAL, some other OSes (Minix, HPUX, perhaps BSD) use
EAFNOSUPPORT. Windows uses WSAEFAULT according to MSDN.

Other protocols error values in their af bind() methods in current mainline git as far
as a brief look shows:
	EAFNOSUPPORT: atm, appletalk, l2tp, llc, phonet, rxrpc
	EINVAL: ax25, bluetooth, decnet, econet, ieee802154, iucv, netlink, netrom, packet, rds, rose, unix, x25, 
	No check?: can/raw, ipv6/raw, irda, l2tp/l2tp_ip

Ciao, Marcus

Signed-off-by: Marcus Meissner <meissner@suse.de>
Cc: Reinhard Max <max@suse.de>
---
 net/ipv4/af_inet.c  |    4 +++-
 net/ipv6/af_inet6.c |    2 +-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
index eae1f67..ef1528a 100644
--- a/net/ipv4/af_inet.c
+++ b/net/ipv4/af_inet.c
@@ -465,8 +465,10 @@ int inet_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
 	if (addr_len < sizeof(struct sockaddr_in))
 		goto out;
 
-	if (addr->sin_family != AF_INET)
+	if (addr->sin_family != AF_INET) {
+		err = -EAFNOSUPPORT;
 		goto out;
+	}
 
 	chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
 
diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
index d450a2f..3b5669a 100644
--- a/net/ipv6/af_inet6.c
+++ b/net/ipv6/af_inet6.c
@@ -274,7 +274,7 @@ int inet6_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
 		return -EINVAL;
 
 	if (addr->sin6_family != AF_INET6)
-		return -EINVAL;
+		return -EAFNOSUPPORT;
 
 	addr_type = ipv6_addr_type(&addr->sin6_addr);
 	if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
-- 
1.7.5.4

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

* Re: [PATCH] net: bind() fix error return on wrong address family
  2011-07-04 11:30 [PATCH] net: bind() fix error return on wrong address family Marcus Meissner
@ 2011-07-05  4:38 ` David Miller
  0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2011-07-05  4:38 UTC (permalink / raw)
  To: meissner
  Cc: kuznet, pekkas, jmorris, yoshfuji, kaber, netdev, linux-kernel,
	meissner, max

From: Marcus Meissner <meissner@novell.com>
Date: Mon,  4 Jul 2011 13:30:29 +0200

> Reinhard Max also pointed out that the error should EAFNOSUPPORT according
> to POSIX.
> 
> The Linux manpages have it as EINVAL, some other OSes (Minix, HPUX, perhaps BSD) use
> EAFNOSUPPORT. Windows uses WSAEFAULT according to MSDN.
> 
> Other protocols error values in their af bind() methods in current mainline git as far
> as a brief look shows:
> 	EAFNOSUPPORT: atm, appletalk, l2tp, llc, phonet, rxrpc
> 	EINVAL: ax25, bluetooth, decnet, econet, ieee802154, iucv, netlink, netrom, packet, rds, rose, unix, x25, 
> 	No check?: can/raw, ipv6/raw, irda, l2tp/l2tp_ip
> 
> Signed-off-by: Marcus Meissner <meissner@suse.de>
> Cc: Reinhard Max <max@suse.de>

Applied to net-2.6, thanks.

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

end of thread, other threads:[~2011-07-05  4:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-07-04 11:30 [PATCH] net: bind() fix error return on wrong address family Marcus Meissner
2011-07-05  4:38 ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).