06.08.2013 Views

pSOSystem System Calls - Read

pSOSystem System Calls - Read

pSOSystem System Calls - Read

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

pNA+ <strong>System</strong> <strong>Calls</strong> getsockname<br />

getsockname Gets the address that is bound to a socket.<br />

#include <br />

long getsockname(<br />

int s, /* socket descriptor */<br />

struct sockaddr_in *addr, /* socket attributes */<br />

int *addrlen /* size of sockaddr_in */<br />

)<br />

Description<br />

Arguments<br />

Return Value<br />

The getsockname() call obtains the address bound to the specified socket.<br />

s Specifies the socket.<br />

addr Points to a sockaddr_in structure in which<br />

getsockname() stores the address bound to the socket.<br />

The sockaddr_in structure is defined as follows:<br />

struct sockaddr_in {<br />

short sin_family; /* must be AF_INET */<br />

unsigned short sin_port; /* 16-bit port number */<br />

struct in_addr sin_addr; /* 32-bit IP address */<br />

char sin_zero[8]; /* must be 0 */<br />

};<br />

This structure cannot be packed.<br />

addrlen Points to an integer equal to 16, which is the size in bytes of<br />

the sockaddr_in structure.<br />

This system call returns 0 if successful, otherwise it returns -1.<br />

<strong>pSO<strong>System</strong></strong> <strong>System</strong> <strong>Calls</strong> 4-15<br />

4

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!