Gets the name of the peer socket.
#include <sys/types.h> #include <sys/socket.h> #include <sys/ndd_var.h> /*Needed for AF_NDD address family only*/ #include <sys/atmsock.h> /*Needed for SOCK_CONN_DGRAM socket type only*/ int getpeername (Socket, Name, NameLength) int Socket; struct sockaddr *Name; size_t *NameLength;
The getpeername subroutine retrieves the Name parameter from the peer socket connected to the specified socket. The Name parameter contains the address of the peer socket upon successful completion.
A process created by another process can inherit open sockets. The created process may need to identify the addresses of the sockets it has inherited. The getpeername subroutine allows a process to retrieve the address of the peer socket at the remote end of the socket connection.
Note: The getpeername subroutine operates only on connected sockets.
A process can use the getsockname subroutine to retrieve the local address of a socket.
Upon successful completion, a value of 0 is returned and the Name parameter holds the address of the peer socket.
If the getpeername subroutine is unsuccessful, the system handler performs the following functions:
The getpeername subroutine is unsuccessful if any of the following errors occurs:
The following program fragment illustrates the use of the getpeername subroutine to return the address of the peer connected on the other end of the socket:
struct sockaddr_in name; int namelen = sizeof(name); . . . if(getpeername(0,(struct sockaddr*)&name, &namelen)<0){ syslog(LOG_ERR,"getpeername: %m"); exit(1); } else syslog(LOG_INFO,"Connection from %s",inet_ntoa(name.sin_addr)); . . .
The getpeername subroutine is part of Base Operating System (BOS) Runtime.
All applications containing the getpeername subroutine must be compiled with _BSD set to a specific value. Acceptable values are 43 and 44. In addition, all socket applications must include the BSD libbsd.a library.
The accept subroutine, bind subroutine, getsockname subroutine, socket subroutine.
Sockets Overview in AIX Version 4.3 Communications Programming Concepts.