1/20
Flashcards covering the fundamentals of network programming in C, including byte ordering, IP address handling, and the client-server system call sequences.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
Why is handling IP addresses in C considered complicated for historical reasons?
It was designed before unions and generic pointers were part of the C programming language, requiring developers to cast pointers between different types of structures.
What is the function of the struct ADDRINFO in network programming?
It contains a pointer to a socket address and serves as the equivalent of a generic pointer to different types of structures, such as a sockaddressin.
What is the size and type of an Internet address at the bottom level?
It is a 32-bit unsigned integer.
What is the difference between Big Endian (network byte order) and Little Endian (host byte order)?
Big Endian stores the most significant bit at the lowest address in memory, whereas Little Endian stores the least significant bit first at the lowest address.
What functions convert a long int (32 bits) and short int (16 bits) from host to network byte order?
htonl() for a long int and htons() for a short int.
Why should the inet_addr function be avoided for string-to-integer conversion?
If given an invalid string, it returns −1, which is the same binary representation as the valid broadcast address 255.255.255.255, making error detection impossible.
What makes the inet_ntoa function lack thread safety?
It returns a pointer to statically allocated memory; if multiple threads call it, they will all receive the same pointer, and whichever thread wrote last will overwrite the data.
What does the 'P' stand for in functions like INET N2P and INET P2N?
Presentation, referring to the ASCII text representation shown to a user.
What is the advantage of using INET N2P over INET N2A?
It is thread-safe because the string output buffer is passed as an argument, and it handles both IP version 4 and IP version 6.
What are the common system calls used in a network client sequence?
socket, connect, read/write (or send/receive), and close.
Which system calls are specific to setting up a server that is not found in a standard client sequence?
bind, listen, and accept.
What is the purpose of the bind operation in a server application?
It associates the socket with a specific address and a particular port number.
In a Linux environment, what is the impact of SYN cookies on the backlog argument in the listen system call?
When SYN cookies are enabled, there is no logical maximum length for the queue of pending connections, and the backlog setting is ignored.
How does the accept system call facilitate handling multiple clients?
It returns a new 'connected' file descriptor for each connection, allowing the original 'listening' file descriptor to continue waiting for new connections.
What does the AI_PASSIVE flag signify when used with getaddrinfo and a NULL host name?
It instructs the server to listen on all available IP addresses for that particular host.
What is the utility of the SO_REUSEADDR socket option?
It allows a process to rapidly reuse a port number that was recently closed, avoiding the 'address already in use' error during development.
What happens if a server specifies port number 0 in a bind call?
The operating system chooses an arbitrary random free port for the server.
Which library call is used to discover the port number assigned to a socket after binding to port 0?
getsockname.
Why is it necessary to call flush when using fprintf to write to a network connection?
Network connections are block buffered rather than new line buffered, so data will not be transmitted until the buffer is flushed or the connection is closed.
What signal is sent by the kernel if a process attempts to write to a pipe or network connection where the other side has disconnected?
SigPipe.
What are three methods to enable a server to handle multiple clients simultaneously?
Forking a child process, creating a thread for each connection, or using non-blocking calls like select and poll.