mludvig / smtp-cli

The ultimate command line SMTP client
http://smtp-cli.logix.cz
187 stars 32 forks source link

option --ipv4 kicks IO::Socket::INET6 #12

Closed doekia closed 6 years ago

doekia commented 6 years ago

Despite passing --ipv4 at command line, the code tries to initiate ipv6 socket.

By changing line 409: if ($addr_family == AF_INET6) {

The code works as expected

mludvig commented 6 years ago

Hi, That's interesting, even without your fix it works for me as expected. What mail server are you trying it against and what's your OS and Perl version?

doekia commented 6 years ago

This is perl 5, version 14, subversion 2 (v5.14.2) built for x86_64-linux-gnu-thread-multi Debian 8


Original code says on line 199: my $socket6 = eval { require IO::Socket::INET6; require Socket6; 1; }; Which set $socket6 to 1 if the library is present and original code line 409: if ($socket6) { $connect_args{'Domain'} = $addr_family; $sock = IO::Socket::INET6->new(%connect_args) or die ("Connect failed: $@\n"); } else { $sock = IO::Socket::INET->new(%connect_args) or die ("Connect failed: $@\n"); } Hence the socket is created using IO::Socket::INET6

mludvig commented 6 years ago

It's using IO::Socket::INET6 but should set address family to IPv4. What behaviour did you observe? Did it make IPv6 connections when --ipv4 was set? Or what was the problem?

doekia commented 6 years ago

The problem was that the IPv6 layer on the host was misconfigured. The socket creation failed.

By forcing the code to create IO::Socket::INET rather than IO::Socket::INET6, I nailed down the root cause of the problem to be at the INET6 layer. And fixed it. To me a flag forcing ipv4 should not try ipv6 even if the ipv6 normally fallback properly.

However, great code I use it from time to time to identify weird issues with mailer.

mludvig commented 6 years ago

I couldn't reproduce it but I guess it's no harm to force using IO::Socket::INET instead of INET6 when --ipv4 is requested. It's in Version 3.9 just released.