Network Programming in C Lecture Flashcards

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/20

flashcard set

Earn XP

Description and Tags

Flashcards covering the fundamentals of network programming in C, including byte ordering, IP address handling, and the client-server system call sequences.

Last updated 12:37 AM on 6/18/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

21 Terms

1
New cards

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.

2
New cards

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.

3
New cards

What is the size and type of an Internet address at the bottom level?

It is a 3232-bit unsigned integer.

4
New cards

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.

5
New cards

What functions convert a long int (3232 bits) and short int (1616 bits) from host to network byte order?

htonl()htonl() for a long int and htons()htons() for a short int.

6
New cards

Why should the inet_addr function be avoided for string-to-integer conversion?

If given an invalid string, it returns 1-1, which is the same binary representation as the valid broadcast address 255.255.255.255255.255.255.255, making error detection impossible.

7
New cards

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.

8
New cards

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.

9
New cards

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 44 and IP version 66.

10
New cards

What are the common system calls used in a network client sequence?

socketsocket, connectconnect, read/writeread/write (or send/receivesend/receive), and closeclose.

11
New cards

Which system calls are specific to setting up a server that is not found in a standard client sequence?

bindbind, listenlisten, and acceptaccept.

12
New cards

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.

13
New cards

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.

14
New cards

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.

15
New cards

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.

16
New cards

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.

17
New cards

What happens if a server specifies port number 00 in a bind call?

The operating system chooses an arbitrary random free port for the server.

18
New cards

Which library call is used to discover the port number assigned to a socket after binding to port 00?

getsocknamegetsockname.

19
New cards

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.

20
New cards

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?

SigPipeSigPipe.

21
New cards

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 selectselect and pollpoll.