Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Undefined address for Socket::pack_sockaddr_in

by WithABeard (Sexton)
on Jun 20, 2024 at 11:40 UTC ( [id://11160129]=perlquestion: print w/replies, xml ) Need Help??

WithABeard has asked for the wisdom of the Perl Monks concerning the following question:

I am using Firefox::Marionette, and it works great (normally), but is now giving this error:

% perl -MFirefox::Marionette -e 'my $f=Firefox::Marionette->new()' Undefined address for Socket::pack_sockaddr_in at /Users/<user>/perl5/ +lib/perl5/Firefox/Marionette.pm line 7134.

The line in question is this one:

$sock_addr = Socket::pack_sockaddr_in( $port, Socket::inet_aton($host) );

So I'm guessing that Socket::inet_aton($host) is the culprit

metacpan.org/pod/Socket tells us that:

...If passed a hostname that cannot be resolved, returns undef.

From this I'll assume that the hostname cannot be resolved, but we're not even opening a url yet...

Testing Socket yields predictable results:

% perl -MSocket -e'defined (my $a=inet_aton("garbage")) or die"dead"; +print unpack "V", $a;' dead at -e line 1. % perl -MSocket -e'defined (my $a=inet_aton("127.0.0.1")) or die"dead" +; print unpack "V", $a;' 16777343

It seems to do its job when passed something sensible

I usually work from home, but today I went in to the office, and got the error.
Could this be caused by a change in the network?
I'll know later today if it works at home.

System details:

MacOS 14.5
Apple M2
perl ver. 5.34.2

I tried flushing cache with sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder, but this made no difference

I also tried changing the perl version (using plenv), but then I have to install Firefox::Marionette for the new version, and surprise-surprise; installation fails with the same error :p

Is this the right way to flush DNS on MacOS 14.5?

How can I find out what is actually passed to inet_aton when it fails?

What else can I do to debug this?

Replies are listed 'Best First'.
Re: Undefined address for Socket::pack_sockaddr_in
by Corion (Patriarch) on Jun 20, 2024 at 11:45 UTC

    Walking up the call chain, it tries to resolve _DEFAULT_HOST(), which is localhost. Maybe localhost does not resolve to a good name for the chosen protocol? Maybe things work better if you explicitly supply a hostname, or a fixed IP address?

    my $ff = Firefox::Marionette->new( host => '127.0.0.1', #host => 'localhost', #host => '::1', #host => 'hostname-of-the-machine', );

    Maybe localhost only resolves for IPv4 (or IPv6) and pack_sockaddr_in tries to pack an address for IPv6 (or IPv4)...

      You are right, "localhost" does not resolve:

      % perl -MSocket -e'defined inet_aton("localhost") or die;' Died at -e line 1.

      I forgot that I meddled with /etc/hosts trying to resolve a different issue, and I guess I didn't restore it

      Now that I have restored it, the error is gone.
      Strange that I did not get this problem until now, as it has been days since this meddling...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11160129]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2024-07-18 06:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.