getpeername

Jump to: navigation, search

Table of Contents >> Programmer's Reference


#include <trsocket.h>


int getpeername (
int socketDescriptor,
struct sockaddr * fromAddressPtr,
int * addressLengthPtr
);


Function Description

This function returns the IP address/port number of the remote system to which the socket is connected.


Parameters

  • socketDescriptor
    The socket descriptor to assign a name (port number) to.
  • fromAddressPtr
    The pointer to the structure containing the address to connect to for TCP. For UDP, this is the default address to send packets to and the only address to receive from.
  • addressLengthPtr
    The length of the address structure.


Returns

  • TM_ENOERROR
    Success
  • TM_SOCKET_ERROR
    Failure


Note Note: TM_SOCKET_ERROR means that this socket call has failed and the errorCode has been set on the socket itself.

To retrieve the socket error the user must call tfGetSocketError(socketDescriptor).


Possible socket errors

  • TM_EBADF
    The socket descriptor is invalid.
  • TM_ENOTCONN
    The socket is not connected.
  • TM_EINVAL
    One of the parameters is invalid.


Table of Contents >> Programmer's Reference