25.02.2013 Views

TCP/IP Tutorial and Technical Overview - IBM Redbooks

TCP/IP Tutorial and Technical Overview - IBM Redbooks

TCP/IP Tutorial and Technical Overview - IBM Redbooks

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.

► Send <strong>and</strong> receive data on a socket<br />

Format:<br />

sendmsg(sockfd, data, datalength, flags)<br />

recvmsg(sockfd, data, datalength, flags)<br />

Definition of fields:<br />

sockfd This is the socket across which the data will be sent or read.<br />

data This is the data to be sent, or the buffer into which the read<br />

data will be placed.<br />

datalength When writing data, this is the length of the data to be written.<br />

When reading data, this is the amount of data to be read<br />

from the socket.<br />

flags This field, which is in many implementations optional,<br />

provides any specific information to <strong>TCP</strong>/<strong>IP</strong> regarding any<br />

special actions to be taken on the socket when sending or<br />

receiving the data.<br />

Note: Other variations of sendmsg() <strong>and</strong> recv() can be as follows:<br />

sendmsg(): send(), sendto(), write()<br />

recvmsg(): recv(), recvfrom(), read()<br />

RFC 3493 does not specifically discuss the fields passed on the sendmsg()<br />

function. The fields discussed earlier are drawn from those typically used<br />

by most implementations.<br />

► Close a socket<br />

Format:<br />

close(sockfd)<br />

Definition of fields:<br />

sockfd This is the socket which is to be closed.<br />

Chapter 11. Application structure <strong>and</strong> programming interfaces 413

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

Saved successfully!

Ooh no, something went wrong!