Professional Documents
Culture Documents
120CS0150 Test
120CS0150 Test
b. Examine the DNS query message. What “Type” of DNS query is it? Does the
query message contain any “answers”?
Ans:
It is a query message of type “PTR”.
It doesnt contain any answers.
c. Examine the DNS response message. What MIT name servers does the response
message provide?
Ans:
The nameservers are:
1. W20NS.MIT.EDU
2. BITSY.MIT.EDU
3. STRAWB.MIT.EDU
d. Does this response message also provide the IP addresses of
the MIT name servers?
Ans:
Yes, they do provide the IP addresses of the MIT nameservers
2. Write a TCP socket program to divide the two numbers using command line
arguments (The IP address of the server should be entered along with the execution
command for executing the program of client machine). Use all the appropriate
socket functions.
Example:
$. /client 127.0.0.1
Input at client : 32 8
Output at server: 4
Ans:
Client:
#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include<unistd.h>
int main(int argc, char *argv[])
{
int client_socket;
struct sockaddr_in server;
int num1, num2, result;
client_socket = socket(AF_INET, SOCK_STREAM, 0);
if (client_socket == -1)
{
printf("Could not create socket");
return 1;
}
server.sin_addr.s_addr = inet_addr("127.0.0.1");
server.sin_family = AF_INET;
server.sin_port = htons(7000);
if (connect(client_socket, (struct sockaddr *)&server, sizeof(server)) < 0)
{
printf("Connect failed");
return 1;
}
printf("Enter first number: ");
scanf("%d", &num1);
printf("Enter second number: ");
scanf("%d", &num2);
num1 = htonl(num1);
num2 = htonl(num2);
send(client_socket, &num1, sizeof(num1), 0);
send(client_socket, &num2, sizeof(num2), 0);
recv(client_socket, &result, sizeof(result), 0);
// result = result;
printf("Result: %d\n", result);
close(client_socket);
return 0;
}
Server:
#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include<unistd.h>
int res(int n1, int n2)
{
if(n1<0 && n2<0) return n1/n2;
//else if((n1<0 && n2<0) || (n1>0 && n2<0)) return (-n1/n2);
else if((n1!=0 && n2!=0 && (n1<n2)) || (n1==0)) return 0;
else if(n1!=0 && n2==0) return 0;
else
return n1/n2;
}
Server:
Client: