dev > perl > modules > related_modules
document updated 15 years ago, on Sep 30, 2007

Mucking about with DNS mapping

Sometimes a DNS name won't resolve. Sure, you can specify an IP to connect to, but then the HTTP Host: header doesn't get sent.

The solution? Hack IO::Socket::INET::_get_addr()... this works for both LWP::Simple as well as the normal LWP::UserAgent.

    use IO::Socket::INET;   # this must be explicitely loaded, or our change won't have an effect, because LWP will load the module later, over us

    # Hack at LWP's DNS resolution
    my $orig_get_addr = \&IO::Socket::INET::_get_addr;
    *IO::Socket::INET::_get_addr = sub {
        #print Dumper \@_;
        if ($_[1] =~ /^(.*\.)libsyn\.com$/si) {
            #die "Fark!";
            $_[1] = '';
        my @ret = $orig_get_addr->(@_);
        #print Dumper \@ret;
        return @ret;