Home |
Function getpeername |
Function getpeernameGet port number and IP address of the remote host that the socket is connected to. int getpeername(SOCKET socket, struct sockaddr * addr, int * addrlen); ParameterssocketSocket returned by socket or accept. addrReturns address of remote host (port number and IP address are in network byte order). This parameter has type struct sockaddr * for historical reasons. Use type struct sockaddr_in * instead. addrlenSize of buffer pointed to by addr. return valueReturns 0 if successful, otherwise SOCKET_ERROR. If an error occurred, call xn_getlasterror and xn_geterror_string to return the error value. Section Error Codes further describes each error. Possible values for this function are:
This function extracts the IP address and port number of host connected to the socket and stores it in addr. Upon entry, addrlen should contain the size of the addr structure. getpeername sets addrlen to the size of the valid data that it has stored in addr. The socket (TCP, UDP, RAW) must be connected.
|