• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/16

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

16 Cards in this Set

  • Front
  • Back
What function creates a socket, and what is its signature?
int socket(int domain, int type, int protocol);
What are the arguments to the function socket, and what do they represent?
- domain specifies the communication domain, the protocol family to be used for communication (e.g., AF_INET. AF_UNIX, etc.). The families are defined in <sys/socket.h>

- type specifies the communication semantics (e.g., SOCK_STREAM, SOCK_DGRAM

- protocol specifies a particular protocol to be used with the socket. Normally only a single protocol exists to support a particular socket, in which case protocol can be specified as 0.
What does the function socket return?
A file descriptor for the new socket. On error, -1 is returned, and errno is set appropriately.
What errors can be returned by socket?
- EACCES - Permission to create a socket of the specified type and/or protocol is denied.

- EAFNOSUPPORT - The implementation does not support the specified address family.

- EINVAL - Unknown protocol, or protocol family not available. Invalid flags are in type.

- EMFILE - Process file table overflow.

- ENFILE - The system limit on the total number of open files has been reached.

- ENOBUFS or ENOMEM - Insufficient memory is available. The socket cannot be created until sufficient resources are freed.

- EPROTONOSUPPORT - The protocol type or the specified protocol is not supported within this domain.
What data type is used to specify a server's IP address and port?
A struct sockaddr_in.
What fields of the struct sockaddr_in must be filled in?
struct sockaddr_in servaddr;
servaddr.sin_family
servaddr.sin_port
servaddr.sin_addr
What type of function needs to be called when setting the numeric fields of the struct sockaddr_in?
hton*

The host to network byte ordering functions.
What function must be called to convert an IP address string?
inet_pton - a new function with IPv6 that replaced the inet_addr function.
What function is used to establish a connection with a server, and what is its signature?
int connect(int sockfd, const struct sockaddr* addr, socklen_t addrlen);
What is the return value from connect?
If the connection or binding succeeds, 0 is returned. On error, -1 is returned, and errno is set appropriately.
What are the possible (general) error codes for a failed call to the function connect?
- EACCES - Write permission is denied on the socket file, or search permission is denied for one of the directories in the path prefix.

- EACCES, EPERM - The user tried to connect to a broadcast address without having the socket broadcast flag enabled or the connection request failed because of a local firewall rule.

- EADDRINUSE - Local address is already in use.

EAFNOSUPPORT - The passed address didn't have the correct address family in its sa_family field.

- EAGAIN - No more free local ports or insufficient entries in the routing cache.

- EALREADY - The socket is nonblocking and a previous connection attempt has not yet been completed.

- EBADF - The file descriptor is not a valid index in the descriptor table.

- ECONNREFUSED - No-one listening on the remote address.

- EFAULT - The socket structure address is outside the user's address space.

- EINPROGRESS - The socket is nonblocking and the connection cannot ne completed immediately. It is possible to select or poll for completion by selecting the socket for writing. After select indicates writability, use getsockopt to read the SO_ERROR option at level SOL_SOCKET to determine whether connect() completed successfully (SO_ERROR is zero) or unsuccessfully (SO_ERROR is one of the usual error codes, explaining the reason for the failure).

- EINTR - The system call was interrupted by a signal that was caught; see signal(7).

- EISCONN - The socket is already connected.

- ENETUNREACH - Network is unreachable.

- ENOTSOCK - The file descriptor is not associated with a socket.

- ETIMEDOUT - Timeout while attempting connection. The server may be too busy to accept new connections.
What does the function read return when the other end closed the connection? What kind of value is returned in case of an error?
0 for connection closed.

Negative number for error condition.
What happens if a socket is not closed before a program exits?
UNIX always closes all open descriptors when a process terminates.
What data structure (and its fields) is used with IPv6?
struct sockaddr_in6 servaddr;
servaddr.sin6_family
servaddr.sin6_port
servaddr.sin6_addr
What sequence of functions is typically called by a TCP server?
- socket
- bind
- listen
- accept
What function is used by a server to handle client requests? What is its signature?
int accept(int sockfd, struct sockaddr* addr, socklen_t* addrlen);

Returns a new file descriptor referring to the new cocket. The new socket is not in the listening state.