2

I have written a script to send a UDP packet over IPv6 link local IP. Both source and destination are IPv6 link local IP.

#!/usr/bin/perl
use IO::Socket::INET6;
use Socket6;

my ($socket,$data);

$socket = new IO::Socket::INET6(
    LocalAddr   => 'fe80::21b:21ff:fe39:8cce',
    LocalPort   => '547',
    PeerAddr   => 'fe80::240:43ff:feb9:2f44',
    PeerPort   => '546',
    Proto        => 'udp',
) or die "ERROR in Socket Creation : $@\n";

for (my $i=1; $i <= 1; $i++) {
    $data =pack('H*',"123455550");

    $socket->send($data);

}

$socket->close();

After executing this above script I am getting below error:

ERROR in Socket Creation : IO::Socket::INET6: bind: Invalid argument

Any one please help me on this .

chicks
  • 2,393
  • 3
  • 24
  • 40
  • are you running this as `root`? otherwise you should pick a [non-privileged port](http://stackoverflow.com/questions/10182798/why-are-ports-below-1024-privileged) above 1024. – chicks Aug 17 '15 at 17:17

2 Answers2

0

I have a feeling this is failing because you're using link-local, but don't specify the interface in your LocalAddr string. The following seems to work for me:

LocalAddr  => "fe80::a00:27ff:fe49:51ce%eth0",
PeerAddr   => "fe80::a00:27ff:fe49:51ce",
PeerPort   => 22,
Proto      => 'tcp',
stevieb
  • 9,065
  • 3
  • 26
  • 36
  • I don't see anything in the docs about this, but if others can confirm this behaviour, I'll be glad to write a patch for the docs. – stevieb Aug 17 '15 at 14:20
  • Because the same network (fe80::/10) is used for the link-local network on all interfaces, you must specify the zone (interface) when using link-local addresses. If you had more than one interface, each would use the link-local network, so the only way the OS has to determine which interface to use is with the zone designation on the end of the address. Different OSes have different zone identifiers (%eth0, %2, etc.). – Ron Maupin Aug 17 '15 at 17:44
0

You also don't want to be using Socket6 or IO::Socket::INET6, as both are very old "transition" things written very early on in IPv6, before core's Socket supported 'v6 natively. Now it does that fine, you should stick to regular Socket and IO::Socket::IP.

(Via the disclaimer: I'm the maintainer of both)

LeoNerd
  • 8,344
  • 1
  • 29
  • 36