Sponsored Content
Full Discussion: getsockname
Top Forums Programming getsockname Post 86096 by ramneek on Tuesday 11th of October 2005 05:26:51 AM
Old 10-11-2005
getsockname

int getPeerIP(int remoteConnFd )
{

char *sIPAddr;
sockaddr_in theirAddr;
int sin_size = sizeof(sockaddr_in);
int nRetVal = getsockname(remoteConnFd, (sockaddr *)&theirAddr, (socklen_t *)&sin_size);


if(nRetVal == -1)
{
printf("\n THERE IS ERROR IN HANDLING THE MEESAGE \n");
}
else
strcpy(sIPAddr,inet_ntoa(theirAddr.sin_addr));


printf("\n THE GETPEERIP IS RETURNING THE VALUE %s \n",sIPAddr);

return 0;
}



THIS IS THE FUNCTION I AM USING
MY PROBLEM IS if i print sIPAddr i get 127.0.0.1

I HAVE MADE THE CLIENT AND SERVER ON THE SAME TERMINAL

PLEASE TELL ME WHAT IS THIS FUNCTION FOR AND HOW IT IS DIFFERENT FROM GETPEERNAME

IF POSSIBLE THEN WITH EXAMPLE
 
getsockname(3SOCKET)					     Sockets Library Functions					      getsockname(3SOCKET)

NAME
getsockname - get socket name SYNOPSIS
cc [ flag ... ] file ... -lsocket -lnsl [ library ... ] #include <sys/types.h> #include <sys/socket.h> int getsockname(int s, struct sockaddr *name, socklen_t *namelen); DESCRIPTION
getsockname() returns the current name for socket s. The namelen parameter should be initialized to indicate the amount of space pointed to by name. On return it contains the actual size in bytes of the name returned. RETURN VALUES
If successful, getsockname() returns 0; otherwise it returns -1 and sets errno to indicate the error. ERRORS
The call succeeds unless: EBADF The argument s is not a valid file descriptor. ENOMEM There was insufficient memory available for the operation to complete. ENOSR There were insufficient STREAMS resources available for the operation to complete. ENOTSOCK The argument s is not a socket. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |MT-Level |Safe | +-----------------------------+-----------------------------+ SEE ALSO
bind(3SOCKET), getpeername(3SOCKET), socket(3SOCKET), attributes(5) SunOS 5.11 12 Dec 1997 getsockname(3SOCKET)
All times are GMT -4. The time now is 06:59 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy