net: bind() fix error return on wrong address family
authorMarcus Meissner <meissner@novell.com>
Mon, 4 Jul 2011 01:30:29 +0000 (01:30 +0000)
committerDavid S. Miller <davem@davemloft.net>
Tue, 5 Jul 2011 04:37:41 +0000 (21:37 -0700)
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>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/ipv4/af_inet.c
net/ipv6/af_inet6.c

index eae1f676f870a8e219bcb3ee4a28453961604def..ef1528af7abf0f9dadb567f4156f4e10da360828 100644 (file)
@@ -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);
 
index d450a2f9fc0645b7addef3fcbf2d586e89d86da7..3b5669a2582df03c1f1b896991fba664e137d62e 100644 (file)
@@ -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)
This page took 0.077952 seconds and 5 git commands to generate.