Name
getsockname - gets socket name
Library
libc.lib
Synopsis
|
int
getsockname (int s, struct sockaddr * restrict name, socklen_t * restrict namelen);
|
Return values
The getsockname() function returns the value 0 if successful; otherwise
the value -1 is returned and the global variable errno is set to indicate
the error.
Detailed description
The
getsockname
system call
returns the current
name
for the specified socket.
The
namelen
argument should be initialized to indicate
the amount of space pointed to by
name.
On return it contains the actual size of the name
returned (in bytes).
Examples
#include <sys/socket.h>
#include <netinet/in.h>
#include <unistd.h>
TInt GetSockName()
{
int sock_fd;
struct sockaddr_in addr,ss;
unsigned int len;
sock_fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = htonl(INADDR_ANY);
addr.sin_port = htons(5000);
bind(sock_fd,(struct sockaddr*)&addr,sizeof(addr));
len=sizeof(ss);
getsockname(sock_fd,(struct sockaddr*)&ss,&len);
close(sock_fd);
}
Errors
The call succeeds unless:
[EBADF]
|
|
The argument
s
is not a valid descriptor.
|
[ECONNRESET]
|
|
The connection has been reset by the peer.
|
[ENOTSOCK]
|
|
The argument
s
is a file, not a socket.
|
[ENOBUFS]
|
|
Insufficient resources were available in the system
to perform the operation.
|
[EFAULT]
|
|
The
name
argument points to memory not in a valid part of the
process address space.
|
[EINVAL]
|
|
The
namelen
argument is not valid.
|
See also
bind,
getpeername,
socket
The
getsockname
system call appeared in
BSD 4.2.
Feedback
For additional information or queries on this page send feedback
© 2005-2007 Nokia
|
|