mIRC Homepage

Udp socket and ipv6

Posted By: Wims

Udp socket and ipv6 - 02/10/21 05:36 PM

Probably a bug but I'm posting here just in case.
I have a game which works with udp, so far the server was only running on an ipv4 connection, For a while now I have been connected via my phone acting as wifi... which gives me ipv6.
With 7.67 just released I ran the game to see if it worked on that new version, but it didn't work. I had hardcoded for connecting a client locally when you were the server, so I fixed that to be based on $iptype($ip), which solved the issue for tcp ( the game also use tcp; if it's ipv6 I changed the loopback address to ::1 (or 0:0:0:0:0:0:0:1))
Now for udp, I can't get anything to work, using ::1 or 0:0:0:0:0:0:0:1 as the ip address there does not work at all, the server is created with
/sockudp -k udpserversocketname <port>
where <port> is any valid port. And here is an associated on udpread event:
on *:udpread:udpserversocketname:{
  echo -sg received info from $sock($sockname).saddr $sock($sockname).sport

With a simple client being like:
/sockudp tempclient 0:0:0:0:0:0:0:1 <port> some data

Can anyone get udp socket to work with ipv6 connectivity?
Posted By: Khaled

Re: Udp socket and ipv6 - 03/10/21 09:15 AM

You will need to use -d to bind the listening socket to an IPv6 address, otherwise it will default to IPv4.
Posted By: Wims

Re: Udp socket and ipv6 - 03/10/21 11:47 AM

Ah ok, thanks for the reply.

May I ask, why did you choose to support ipv6 with -d binding? Because it seems to me that ip version and binding are unrelated, more importantly it means that one cannot send an udp packet on a given adapter/network card using ipv6, because that's what the binding is for, technically, isn't it? Could this be changed so that we can pass an ipv6 just like an ipv4, preserving the binding feature regardless of the ip version? I have never seen anyone use udp, so coupled with ipv6 it must be even more rare, aka I don't think that would break any script.

Edit: /sockopen does not behave like this and accept either version of ip without -d switch, which I hope is a strong argument.
Posted By: Khaled

Re: Udp socket and ipv6 - 03/10/21 12:35 PM

May I ask, why did you choose to support ipv6 with -d binding?

I didn't. It just happens that the -d switch allows you to bind to an address and this in turn allows you to choose an IPv4 or IPv6 address. Since your script is trying to connect to an IPv6 server, you need to set up an IPv6 listening socket.

/sockopen, as a client command, requires an IP address to connect to. If you specify an IPv4/IPv6 address, it will bind using the appropriate protocol for the IP address type.

/socklisten and /sockudp, when listening for an incoming connection, do not require an IP address. But specifying one with the -d switch will allow you to specify the IP protocol type.
Posted By: Wims

Re: Udp socket and ipv6 - 03/10/21 01:09 PM

That makes sense, somehow I thought the binding had to be done when sending the data, not when creating the 'listening' socket, sorry for the misunderstanding, it works.
© 2021 mIRC Discussion Forums