0

Based on Reverse DNS lookup in perl i tried to create a variable in NGINX so I can use in order to identify search engines but I got alot of errors like this:

2016/06/16 21:10:33 [error] 25853#0: *519 call_sv("sub { return scalar gethostbyaddr(inet_aton($remote_addr), AF_INET); }") failed: "Undefined subroutine &main::inet_aton called at (eval 3) line 1."

Added into my http block:

perl_require Socket.pm;
perl_set $test_rdns "sub { return scalar gethostbyaddr(inet_aton($remote_addr), AF_INET); }";

Please help, I can't find the key of solving this matter.

Community
  • 1
  • 1
user3405598
  • 85
  • 1
  • 7

1 Answers1

0

I don't know exactly what perl_require does, but I reckon it has something to do with Perl's require function, and a thing to be wary of when you use require is that it does not call the package's import method and does not load the default exported functions and symbols into the calling package.

The upshot is you would have to use qualified symbol names in your Perl call

perl_set $test_rdns "sub { return scalar gethostbyaddr(Socket::inet_aton($remote_addr), \
                                                       Socket::AF_INET); }";

or you will have to call Socket's import method

perl_set $test_rdns "sub { use Socket; return scalar \
                gethostbyaddr(inet_aton($remote_addr), AF_INET); }";

(This second suggestion is not tested, and may not work depending on what nginx does with perl's library directories and search path)

mob
  • 117,087
  • 18
  • 149
  • 283