Networking Forums

Networking Forums > Computer Networking > Linux Networking > strange bind(2) behavior

Reply
Thread Tools Display Modes

strange bind(2) behavior

 
 
Mischa Diehm
Guest
Posts: n/a

 
      05-11-2004, 04:39 PM
Hi,

I was very suprised when I found out that it is possible to create a
socket for AF_INET, build a sockaddr struct for a v6 address (take
getaddrinfo for example) and give all that to bind.

<code>
...
n = getaddrinfo("2::2", "4321", &hints, &res);
socketfd = socket(PF_INET, SOCK_STREAM, 6);
if(bind(socketfd, res->ai_addr, res->ai_addrlen)) {
exit(1);
}
....
</code>

What I expected was that the kernel returns with an error but what I got
was an IPv4 socket listening on 0.0.0.0:4321. The problem is that the
sockaddr_in and sockaddr_in6 structures first differ in sin_addr(v4) and
flowinfo (v6). As flowinfo is exactly 32bit and set to zero the kernel
doesn't care and takes the v6 struct as a v4 struct. I think bind should
exactly check if the length of the given parameter is correct. This little
patch would go for a more precise check:

/usr/src/linux/net/ipv4/af_inet.c

486c486
< if (addr_len != sizeof(struct sockaddr_in))
---
> if (addr_len < sizeof(struct sockaddr_in))


I don't know why there is a '<' comparison? Maybe someone of you can give me
a hint.

Thanks

Mischa

--
"Mit seinem Geld begnuegt sich keiner, mit seinem Verstand jeder."
(Quelle: Unbekannt)
 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
strange behavior when the client bind its UDP socket to a local address Christophe Lohr Linux Networking 14 01-23-2009 01:03 PM
Strange VPN behavior Bjarni Windows Networking 1 07-03-2006 05:09 PM
Strange VPN Behavior JamFan Windows Networking 3 02-28-2006 01:39 AM
Strange behavior Dennis P. Smith Windows Networking 5 05-18-2005 07:48 PM
Strange VPN behavior =?Utf-8?B?QnJ1Y2UgQnJvd24=?= Broadband Hardware 3 02-26-2005 03:24 AM



1 2 3 4 5 6 7 8 9 10 11