[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

(usagi-users 03471) Re: IPv6 Multicast question - connect fails



On Wed, 2005-08-10 at 11:51 +0200, Jeroen Massar wrote:
> On Tue, 2005-08-09 at 17:01 +0200, Bas Vermeulen wrote:
> > On Tue, 2005-08-09 at 13:54 +0200, Jeroen Massar wrote:
> > > On Mon, 2005-08-08 at 15:58 +0200, Bas Vermeulen wrote:
> <SNIP>
> > > You definitely should be using getaddrinfo() See google(eva ipv6) =
> > > gsyc.escet.urjc.es/~eva/IPv6-web/ipv6.html for the details.
> > 
> > Right. I've changed the code slightly to use getaddrinfo(). I still get
> > the same result. What I do now:
> 
> Making a getaddr() function, copying that the structure you get from it
> and reusing it with the wrong lenghts is a bad idea, treat it as a big
> black box and don't touch/care about the contents.
> 
> This line:
> > if (bind(s, &addr6, sizeof(addr6)
> fails simply because sizeof(addr6) != res->ai_addrlen...
> adding a variable to store the length of res->ai_addrlen in and then
> passing this to bind might work though.

The bind actually works though.

> Another reason why the bind() might fail is because you bind to it,
> close it, and then rebind it, the OS might not have cleansed the bind,
> using additionally REUSEPORT helps a bit here, then again, the OS
> probably nicely closes it and you didn't specify a local port in the
> first place... hmm...
> 
> Also, when doing this, check that res->ai_addrlen < sizeof(struct
> sockaddr_storage) just in case it ever becomes to big, which it should
> not do, but still.
> 
> The other thing is that you are bind()'ing and connect()'ing to the same
> address, the OS will refuse to do that I hope.


> That all said, find attached a 'working' version:
> 
> jeroen@firenze:~$ ./mcast ff80::1 5060 fe80::202:55ff:fee6:21e8%eth0
> 1234
> Trying to connect to [ff80::1]:5060
> Binding local socket to [fe80::202:55ff:fee6:21e8%eth0]:1234
> Trying [fe80::202:55ff:fee6:21e8%eth0]:1234 OK
> Connecting to [ff80::1]:5060... OK
> All went fine
> Shutting down
> 
> jeroen@firenze:~$ ./mcast ff80::1
> 5060                                   
> Trying to connect to [ff80::1]:5060
> Connecting to [ff80::1]:5060... OK
> All went fine
> Shutting down
> 
> (Tested on a debianized Linux 2.6.10-1-686, thus basically stock kernel)

Well, semi-working. The following is from a stock 2.6.13-ac6:

eth0      Link encap:Ethernet  HWaddr 00:08:74:96:18:ED
          inet addr:192.168.218.67  Bcast:192.168.218.255
Mask:255.255.255.0
          inet6 addr: fe80::208:74ff:fe96:18ed/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:107026 errors:0 dropped:0 overruns:2 frame:0
          TX packets:84360 errors:0 dropped:0 overruns:0 carrier:1
          collisions:803 txqueuelen:1000
          RX bytes:37137640 (35.4 MiB)  TX bytes:7531636 (7.1 MiB)
          Interrupt:11 Base address:0xec80

[bvermeul@laptop ~]$ ./mcast ff01::1 5060
Trying to connect to [ff01::1]:5060
Connecting to [ff01::1]:5060... OK
All went fine
Shutting down
[bvermeul@laptop ~]$

[bvermeul@laptop ~]$ ./mcast ff80::1 5060
Trying to connect to [ff80::1]:5060
Connecting to [ff80::1]:5060... FAIL!
[bvermeul@laptop ~]$

[bvermeul@laptop ~]$ ./mcast ff35::1 5060
Trying to connect to [ff35::1]:5060
Connecting to [ff35::1]:5060... FAIL!
[bvermeul@laptop ~]$ 

Which is about the same as my code does. I'm trying to understand the
difference between your setup and mine, so I can actually get it
working. I'm pretty sure it's not the bind() that's causing problems,
the connect() is giving an error, perhaps because it can't get a route
out to the right scope.

> (btw using goto's ????)

I'm a kernel programmer, and am not opposed to goto's. :) This is
basically just a quick and dirty approach, and the goto was an easy way
to get the right error reporting.

-- 
Bas Vermeulen <bvermeul@xxxxxxxxxxxx>