Tutorials Point


  Perl Home

  PERL Functions

© 2013 TutorialsPoint.COM


  Home     References     About TP     Advertising  

PERL getpeername Function



Advertisements

Syntax

getpeername SOCKET


Definition and Usage

Returns the packed socket address of the remote host attached to SOCKET.

Return Value

  • In scalar context undef on error otherwise packed socket address

Example

Usage Example: Here SOCK is the socket ID of the peer socket. This is the piece of program to use getpeername().
#!/usr/bin/perl

use Socket;

$hersockaddr    = getpeername(SOCK);
($port, $iaddr) = sockaddr_in($hersockaddr);
$herhostname    = gethostbyaddr($iaddr, AF_INET);
$herstraddr     = inet_ntoa($iaddr);



Advertisements


  

Advertisements