read
Prototype:
#include <unistd.h>
int read(int fd, char *buffer, int buf_len);
General Description: Read buf_len bytes from the fd file descriptor into the buffer. You can use this system call for sockets as well as files. However , this call does not provide as much control as the recv() system call.
Return Value: The number of bytes actually read.
Parameters
fd File (or socket) descriptor.
buffer The memory buffer to accept the read data.
buf_len The number of bytes to read and the number of legal bytes in the buffer.
Possible Errors
EINTR The call was interrupted by a signal before any data was read.
EAGAIN Non-blocking I/O has been selected using O_NONBLOCK and no data was immediately available for reading.
EIO I/O error. This will happen for example when the process is in a background process group, tries to read from its controlling tty, and either it is ignoring or blocking SIGTTIN or its process group is orphaned. It may also occur when there is a low-level I/O error while reading from a disk or tape.
EISDIR fd refers to a directory.
EBADF fd is not a valid file descriptor or is not open for reading.
EINVAL fd is attached to an object which is unsuitable for reading.
EFAULT buf is outside your accessible address space.
Examples
int sockfd;
int bytes_read;
char buffer[1024];
/*---create socket & connect to server---*/
if ( (bytes_read = read(sockfd, buffer, sizeof(buffer))) < 0 )
    perror("read");