🎓 BookMCQ
← Back to 27. Network Management

📝 ASN.1 Language Basics (10 MCQs)

Modules, Identifiers and Definition Boundaries

ASN.1 specifications are organized into modules containing definitions of types, values and related information. Each module has a name and may import definitions from another module. The notation provides a language-neutral way to describe data structures used by protocols, allowing different systems to construct and interpret equivalent information. This organization makes complex message definitions easier to reuse and maintain over time.

Type Assignments and Value Assignments

A type assignment gives a name to a type, while a value assignment associates a value with a type. Primitive types include INTEGER, BOOLEAN and OCTET STRING; constructed types include SEQUENCE and SET. SEQUENCE OF represents an ordered collection, and CHOICE selects one alternative from several permitted types. These distinctions are central when reading formal protocol definitions.

Sequence, Choice and Primitive Components

A specification declares the structure first, then implementations create values that satisfy it. A SEQUENCE value supplies components in the defined order, whereas a CHOICE value contains one selected alternative. Constraints may restrict an integer range or the size of a string, improving validation before encoding and transmission. The receiver validates the decoded value against the same declaration.

Example: Defining a Simple Device Record

A DeviceRecord type could be described as a SEQUENCE containing a device name as an OCTET STRING and a status as an INTEGER. A value then supplies one name and one permitted status number. The declaration defines the fields and their types; it does not itself contain the live status of a device.

Reusing Types Through Imports and Constraints

ASN.1 modules can import standard type definitions and reuse them rather than redefining common structures. In SNMP, SMI adapts ASN.1 constructs and adds management-specific macros and restrictions. Encoding rules such as BER operate after a value has been created, converting the defined structure into a transfer representation. This avoids inconsistent duplicate definitions in related modules.

Avoiding Confusion Between Types and Values

'A type assignment stores a live measurement' confuses a schema with a value. 'SEQUENCE and SET always preserve the same order' is incorrect because SEQUENCE is ordered while SET is not. 'CHOICE includes every alternative at once' is false; one alternative is selected for a particular value. The syntax defines structure, while each value supplies actual content.

Reading ASN.1 Declarations in Examination Questions

In code-reading questions, identify module names, type assignments, value assignments, primitive types and constructed types. Be able to explain SEQUENCE, SET, SEQUENCE OF and CHOICE, interpret a simple constraint, and distinguish the ASN.1 declaration from the BER bytes later generated from a value. Identify where each type is declared and how a value conforms to its components.

ASN.1 Module and Type Definition Terms

  • Module - Named unit containing ASN.1 definitions.
  • Type assignment - Declaration giving a name to a type.
  • Value assignment - Declaration associating a value with a type.
  • SEQUENCE - Ordered collection of typed components.
  • CHOICE - Type selecting one alternative component.
  • Constraint - Rule limiting permitted values or sizes.
3
Easy
4
Medium
3
Hard

📝 All ASN.1 Language Basics MCQs

Q1. If the server calls listen() before accept(), what is the most likely outcome when accept() is never executed?

A.The server will immediately close the listening socket.
B.Clients will receive a connection reset error.
C.The server will remain in a listening state, queuing incoming connection requests. ✅
D.All pending connections will be dropped instantly.
💡 Difficulty: easy | ✅ Correct: C

📖 Explanation: When listen() is called, the kernel starts queuing incoming SYN packets. If accept() is never invoked, those queued connections remain pending, and the listening socket stays open. The server does not actively close the socket, nor does it send resets; it simply continues to listen, awaiting accept() calls.

Q2. The variable len is incremented by the number of bytes received in each loop iteration. How could an incorrectly sized buffer cause a logical error in this program?

A.If len exceeds the allocated buffer size, subsequent send() calls may read beyond memory, leading to undefined behavior. ✅
B.The program would stop receiving data after the first packet.
C.The socket would automatically resize the buffer, preventing overflow.
D.len would reset to zero after each iteration.
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: The buffer is allocated once, but len can grow larger than that allocation if many bytes are read. When send() uses len that surpasses the real buffer size, it reads memory beyond the intended region, potentially transmitting garbage data or causing a segmentation fault, which is a classic buffer‑overflow logic error.

Q3. After sending the echoed data, the server executes close(s). What effect does this have on the client’s TCP connection state?

A.The client transitions to LISTEN state, ready to accept new connections.
B.The client experiences a timeout and must retry the connection.
C.The client’s socket enters FIN_WAIT_1, awaiting acknowledgment.
D.The client immediately receives a reset (RST) packet. ✅
💡 Difficulty: hard | ✅ Correct: D

📖 Explanation: Calling close() on the server side initiates a graceful TCP shutdown. The server sends a FIN segment, moving the client into FIN_WAIT_1 as it awaits the server’s FIN acknowledgment. The client does not get an immediate reset; instead, it follows the normal four‑way handshake to close the connection.

Q4. Which of the following best contrasts the reliability of a TCP echo server with a UDP echo server?

A.Both guarantee ordered delivery of messages.
B.TCP ensures reliable, ordered delivery while UDP provides best‑effort delivery without ordering. ✅
C.UDP guarantees delivery but not ordering, unlike TCP.
D.TCP and UDP have identical reliability characteristics.
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: TCP establishes a connection and uses acknowledgments, retransmissions, and sequencing to guarantee that every byte arrives intact and in order. UDP, by contrast, sends datagrams without acknowledgments or ordering guarantees, so packets may be lost, duplicated, or arrive out of sequence, making TCP the reliable choice for an echo service.

Q5. Why is it generally advisable to place the accept() call inside the server’s main loop rather than before the loop begins?

A.Placing accept() outside the loop reduces CPU usage.
B.Inside the loop allows the server to handle only one client forever.
C.It enables the server to handle multiple clients concurrently using threads.
D.It allows the server to accept a new client after each previous client has been served, supporting multiple sequential connections. ✅
💡 Difficulty: medium | ✅ Correct: D

📖 Explanation: Embedding accept() within the loop means that after each client is served and its socket is closed, the server returns to accept() to fetch the next pending connection. This pattern lets the server serve an arbitrary number of clients one after another, rather than being limited to a single connection established before the loop started.

Q6. When bind() fails, which of the following distinctions correctly identifies the cause between ‘address already in use’ and ‘permission denied’?

A.‘Address already in use’ occurs if another socket is bound to the same port; ‘permission denied’ occurs when the process lacks rights to bind to a privileged port (<1024). ✅
B.Both errors indicate the same underlying issue of insufficient memory.
C.‘Permission denied’ is returned only on Windows, while ‘address already in use’ is Unix‑specific.
D.‘Address already in use’ is only for UDP sockets, whereas ‘permission denied’ applies to TCP.
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: The bind() system call returns EADDRINUSE when the requested IP/port pair is already occupied by another socket, indicating a conflict. It returns EACCES (permission denied) when the caller tries to bind to a privileged port without appropriate privileges, such as ports below 1024 on Unix‑like systems. These distinct error codes help diagnose the exact failure reason.

Q7. What is the primary purpose of the call send(s, buffer, len, 0) in the echo server code?

A.To close the socket after communication ends.
B.To transmit the received data back to the client, echoing the original message. ✅
C.To allocate memory for the buffer.
D.To listen for new incoming connections.
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: The send() function takes the file descriptor s, the data stored in buffer, and the length len, then transmits that exact sequence of bytes to the peer socket. In an echo server, this operation mirrors the incoming data back to the client, fulfilling the “echo” behavior expected by the protocol.

Q8. How does the backlog parameter in the listen() function influence the server’s ability to handle simultaneous client connection attempts?

A.It determines the maximum size of the data buffer for each client.
B.It sets the timeout value for idle connections.
C.It specifies the maximum number of pending connections that can be queued before additional requests are refused. ✅
D.It controls the maximum number of bytes the server can send in a single operation.
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: When listen() is called, the backlog argument tells the kernel how many incomplete connection requests (SYN packets) to keep in the pending queue. If more clients attempt to connect than the backlog allows, the kernel will reject or drop the excess requests, causing connection failures for those clients.

Q9. If you wanted the echo server to handle multiple clients concurrently without blocking, which sequence of steps would correctly integrate fork() into the existing code?

A.After accept(), call fork(); in the child process close the listening socket and handle the client, while the parent closes the client socket and returns to accept(). ✅
B.Place fork() before listen(), creating separate processes for each possible client.
C.Replace send() with exec() to spawn a new process for each message.
D.Call fork() after close(s) to restart the server in a new process.
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: The typical pattern is: accept() returns a new client descriptor; fork() creates a child. The child closes the original listening descriptor (it doesn't need to accept more connections) and performs the echo handling on the client socket. The parent closes the client descriptor (its job is to accept new connections) and loops back to accept(). This design yields concurrent handling.

Q10. Which system call is used to create a new socket descriptor for TCP communication?

A.bind()
B.connect()
C.listen()
D.socket() ✅
💡 Difficulty: medium | ✅ Correct: D

📖 Explanation: The socket() system call allocates a new endpoint for communication, returning a file descriptor that can be configured for a specific protocol family (e.g., AF_INET) and type (e.g., SOCK_STREAM for TCP). After obtaining this descriptor, the program can bind, listen, accept, or connect as needed.

🔗 Related Topics (MCQs)