#!/usr/bin/perl =head1 NAME config_me_localaddr =head1 DESCRIPTION Use the local address of the current connection to determine the local hostname ("me"). =head1 CONFIG Nothing to configure. Just load the plugin. =head1 BUGS None known. =head1 COPYRIGHT AND LICENSE Copyright (c) 2006 Peter J. Holzer This plugin is licensed under the same terms as the qpsmtpd package itself. Please see the LICENSE file included with qpsmtpd for details. =cut use warnings; use strict; use Socket; use Socket6; sub hook_config { my ($self, $transaction, $config) = @_; $self->log(LOGDEBUG, "config_me_localaddr called with $config"); return DECLINED unless $config eq 'me'; unless ($self->connection && $self->connection->local_ip) { $self->log(LOGNOTICE, "cannot determnine locak IP address of connection"); return DECLINED; } my $local_ip = $self->connection->local_ip; my $local_name; $self->log(LOGDEBUG, "local_ip $local_ip"); if ($local_ip =~ m/:/) { $self->log(LOGDEBUG, "looks like an IPv6 address"); my $naddr = inet_pton(AF_INET6(), $local_ip); my $sockaddr = pack_sockaddr_in6(25, $naddr); my ($host, $service) = getnameinfo($sockaddr); $local_name = $host; $self->log(LOGDEBUG, "resolved"); } else { $local_name = gethostbyaddr(inet_aton($local_ip), AF_INET); } $self->log(LOGINFO, "local name is $local_name"); return (OK, $local_name); }