40 lines
1.7 KiB
Plaintext
40 lines
1.7 KiB
Plaintext
|
|
Answer the following questions to describe your code submission. Please keep
|
||
|
|
all lines to a maximum of 80 characters wide.
|
||
|
|
|
||
|
|
1 - Your implementation must send an array of bytes to the server. Explain the
|
||
|
|
meaning of these bytes and how the server interprets them.
|
||
|
|
|
||
|
|
The bytes we send form a complete DNS request, which is hardcoded. The first
|
||
|
|
12 bytes make up the DNS header, which includes a transaction ID, flags, and
|
||
|
|
counts of questions, answers, authority, and additional records. After the
|
||
|
|
header, we include the question section, which specifies the domain name
|
||
|
|
(which is a 0 length label which mean root server), the record type (A = IPv4),
|
||
|
|
and the class (IN = Internet). The server interprets these bytes as a query
|
||
|
|
asking for the IPv4 address of the root domain, and responds with the A
|
||
|
|
record containing the IP address of one of the root servers a.root-servers.net.
|
||
|
|
or b.root-servers.net.
|
||
|
|
|
||
|
|
|
||
|
|
2 - Show (in pseudocode) how you set up your socket to send your message,
|
||
|
|
including a description of how you specified the address and port number.
|
||
|
|
What would you have to change to send an HTTP message (which uses TCP) to
|
||
|
|
a server?
|
||
|
|
|
||
|
|
const char *hostname = "127.0.0.1";
|
||
|
|
const char *port = get_port ();
|
||
|
|
|
||
|
|
struct addrinfo *server_list
|
||
|
|
= get_server_list (hostname, port, false, false);
|
||
|
|
|
||
|
|
int sockfd = socket (server_list->ai_family, server_list->ai_socktype, 0);
|
||
|
|
|
||
|
|
We do this to specify the hostname and port.
|
||
|
|
To send an HTTP message to a server we would hardcode the port to be 80
|
||
|
|
and create the socket using SOCK_STREAM. We would have to call connect() to
|
||
|
|
establish the TCP handshake and then use send() to send the query and recv()
|
||
|
|
to get the response.
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|