http://www.perlmonks.org?node_id=642335


in reply to Re: Perl network programming
in thread Perl network programming

Thank you all for the reply.

Actually i read a configuration file for the IP address. I have tried running the same code inside a private LAN (all machines having private IPs) where it worked fine. But when i try it using public IPs it shows this error.

Is that scenario causing this error, or is it faulting in reading the config file.

Replies are listed 'Best First'.
Re^3: Perl network programming
by jbert (Priest) on Oct 03, 2007 at 09:27 UTC
    My money's on the config file. Perhaps a permissions problem?

    If so, the script could probably benefit from better error detection. If an IP address is required (as it seems to be) the code should validate that it has an IP address early on, and give a more informative error message.

    Some tools for chasing down the problem:

    • use 'strace' to see what the script does when it runs. If it fails to open() a config file, you'll see an error code (e.g. EPERM) which tells you why. The output of strace is voluminous, but you can send it to a file and grep it.
    • add some debugging to your script. log the value of the ip address at different stages of the processing.
    • make sure your script is handling errors correctly (a good way is to just 'die' if an unrecoverable problem occurs. e.g:
      my $cfg_file = "/my/config/file"; open(my $fh, "<", $cfg_file) or die "can't read config file [$cfg_file] for reading: $!";
      Note that we putting $! in your error handling gives you the reason why the open failed, which may help you track down the problem.
    As others have noted, I'm speculating wildly because we can't see your code. On the other hand, if your script is large it may not be useful to see all of it.

    If you can try reducing your script to the minimum amount which reproduces the problem that would be useful. You'll also often find that doing that helps you find the problem yourself.

    Good luck.

      $cfile = $ENV{'OCONFFILE'};
      open( CFILE, $cfile ) || return "FAIL0:No such file: $cfile!\n";

      The code given above is the actual part tht gets the config file path & opens the file for read.

      As u said the code is huge for me to post it. Anyway i got around the issue, it was with setting the global variable OCONFFILE to correct path.

      jbert, thanks once again
Re^3: Perl network programming
by erroneousBollock (Curate) on Oct 03, 2007 at 08:18 UTC
    It might be caused by the phase of the moon... we don't know without seeing some code.

    -David