in reply to variable not passing

You need to call inet_aton on your string first. See Socket.

Replies are listed 'Best First'.
Re^2: variable not passing
by Anonymous Monk on Dec 07, 2004 at 18:51 UTC
    Thanks I tried this and still no luck:
    use Socket; use strict; my $addy = shift || die "Enter a IP address"; my $port = getservbyname('smtp', 'tcp'); my $sin = sockaddr_in($port,inet_aton($addy)); my $client = gethostbyaddr($sin, AF_INET); # get name if ($client) { print $client, "\n\a"; } else { print "no\n"; }
      You don't need this sin stuff here. Try your original code, but with the following replacement:

      # this: my $client = gethostbyaddr(inet_aton($addy), AF_INET); # get name # instead of: my $client = gethostbyaddr($addy, AF_INET); # get name

      It worked for you with the variable not received from the user because you weren't using quote marks, and you were getting a v-string (a deprecated feature, actually). Your luck was that a v-string is a lot like an inet_aton()-ed string :)

      Incidentally, why are you using Socket? Unless you want to use low-level stuff for learning or fine control, you are probably better off using IO::Socket. See perlipc, also.

        Thanks!!