Programming Perl

Programming PerlSearch this book
Previous: 3.2.66 getserventChapter 3
Functions
Next: 3.2.68 getsockopt
 

3.2.67 getsockname

getsockname SOCKET

This function returns the packed sockaddr address of this end of the SOCKET connection. (And why wouldn't you know your own address already? Because you might have bound an address containing wildcards to the generic socket before doing an accept. Or because you might have been passed a socket by your parent process - for example, inetd.)

use Socket;
$mysockaddr = getsockname(SOCK);
($port, $myaddr) = unpack_sockaddr_in($mysockaddr);


Previous: 3.2.66 getserventProgramming PerlNext: 3.2.68 getsockopt
3.2.66 getserventBook Index3.2.68 getsockopt