Download as pdf
Download as pdf
You are on page 1of 9
Toudv Stuy HELPer OONIAZ Sumit POONA UBLICATIONS Course Code : BCSL-056 Course Title : Network Programming and Administration Lab Assignment Number : BCA(V)/L-056/Assignment/2023-24 ry, Maximum Marks : 100 fey Weightage : 25% wwrw.ignousite.com ‘Gems Last Date of Submission : 31st October, 2023 (for July 2023 sessi 30th April, 2024 (for January 2024 session) ‘Note: Ths assignment only for students, not forsell or re-uplaad any medi or website Alright reserve to TGNOU Stacy Helper" Its Mega ta share or reupload ff anything like this Is found, then appropriate action wil do taken and apply Copyright ACT te you. You willbe responsible for llegal work. SO con't share and upload on any media, 1. (2) Write a UDP client and UDP server program in C language on Unix/Linux, where client program interact with the Server as given below: 1. The client will send.a string tothe client. 2. Server program send an acknowledgement for receiving the string. 3. Sever program will find the length of the sting and send it to respective client. 4. Client will seni the acknowledgement for receiving the response to the server. ‘Ans. UDP client and UDP server program in C for Unix/Linux that follows the interaction steps you've described! UDP Server: server.c include Hinclude include include include define SERVER_PORT 12345, fidefine BUFFER SIZE 1024 int main() { int sockfd; struct sockaddr_in server_addr, client_addr; socklen_t client_len =sizeof{client_addr); char buffer[BUFFER_SIZE}; int bytes_received; 1/ Create UDP socket if (sockfd = socket(AF_INET, SOCK_DGRAM, 0) perror("Socket creation failed"); exit(1); ' 1 Contigure server address memset(&server_addf, 0, sizeofiserver_addr)); server_addr.sin_family = AF_INET; server_addr-sin_port = htons(SERVER_PORT); Ignou Study Helper-Sunil Poonia Page 1 OONIAZ e Teno Stvby HeLree UBLICATIONS. aa# SUMIL POONA ‘server_addr.sin_addrs_addr=INADDR_ANY; 1/ Bind socket to server address if (bind{sockfd, (struct sockaddr *)8&server_addr, sizeof(server_addr| perror("Bind failed”); exit(1); ' aye printi("Server waiting for data...\n" while (1) { J/ Receive data from client bytes_received = reevfrom|sockfd, buffer, sizeof{buffer), 0, (struct sockaddr *)8.cliont_adidr, &client_len); if (bytes_received ==-1) { perror("Recvfrom failed") exit); f ext 4 Naot bufferfoytes_received] =‘\0' // Nulkterminate the received string print(*Recelved string from clint: s\n, buffer); // Send acknowledgement: if (sendto(socktd, "String received", 15, 0, (struct sockaddr *)Rclient_addr, client_len) ==-1) { perror("Sendto failed"); exit{t); } 11 Calculate and send string length int length = strlen(buffer}; if sendto[soekfd, length, sizeofint), 0, (struct sockaddr *)&client_addr,client_len} perror("Sendto failed"); exit); 1 printf("Sent string leneth tovclient: %d\n", length); J/ Receive acknowledgement for response bytes_received = reevfram|sackfd, buffer, sizeof(buffer), 0, (struct sackaddr *)&client_addr, &client_len): if (bytes_received ==-1) { perror("Recvfrom failed"); exit{l); t butferfoytes_ received] = \o'; // Null-terminate the received string printf("Received response acknowledgement from client: %s\n", buffer}; Page 2 OONIAZ UBLICATIONS lose(sockfa); return 0; ) Output: eee ae eel CT Sent string length to client: 2 Received response acknowledgement from client: Hel a fess Tontu Sry Heveee # SUNIL POONA UDP Client: client.c ome include include include include Wintude sunistali fidefine SERVER_P "127.0.0.1" fidefine SERVER_PORT 12345, fidefine BUFFER_SIZE 1024 int main(){ int sockfd; struct sockaddr_in server_addr, socklen_t server_len = sizeof{server_addr); char buffee(BUFFFR_SI7F int bytes_sent, bytes received I? Create UDP socket If ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) perror("Socket creation failed"); exit(1); “tf 11 Configure server address memset{&server_addr, 0, sizeof{server_addr)); server_addr.sin_family = AF_INET; server_addr-sin_port = htons(SERVER_PORT); if (inet_pton(AF_INET, SERVER_IP, &server_addr sin_add) <= 0) { perror("Invalid address"); exit(1); ) 1//Send string to server Ignou Study Helper-S junil Poonia Page 3 JOONIAZ eqs Ton Sty Henvee UBLICATIONG EY SUMIL POONA char messagef] = "Hello, server!"; bytes_sent = sendtosockfd, message, strien(message}, 0, (struct sockaddr *)&server_addr, server_len); if (oytes_sent ==-1) { perror("Sendto failed); exit(1); printf{"Sent string to server: %s\n", message); 1/ Receive acknowledgement from server bytes_received = recvfrom(sockfd, buffer, sizeof(buffer), 0, (struct sockaddr *)&server_addr, &server_len); if (bytes received ==-1) { perror(”Recvfrom failed”); enit(); ) bufferlbytes_received! = '\0'; // Null-terminate the received string printf("Received acknowledgement from server: s\n", buffer); 1/ Receive string length from server int length; bytes received = recvfrom(sockfd, &leneth, sizeat(int), 0, (struct sockaddr *)&server_addir, &server_len); if (bytes_received == -1) ( perror("Recvfrom failed"); exit(a); } printi(*Received string length from server: 9si\n", length), 1/ Send acknowledgement for response if (sendto{sockfd, "Response received”, 17, 0, (strict sockaddr *)Rserver addr, Sérver_len) perror("Sendto failed"); exit(a); printf("Sent response acknowledgement to server\n"); lose(sockfa): return 0; fey e server: Hello, server! Oe eect nae Ignou Study Helper-S OONIAZ UBLICATIONG ; Qi. (b) Write the steps to install network monitor application on Unix/Linux. Demonstrate the use of capture filter and display filter with the help of examples for each. ‘Ans. Installing a network monitor application, such as Wireshark, on Unix/Linux involves a few steps. In this example, I'll demonstrate how to install Wireshark and provide examples of using capture filters and display filters. Step 1: Install Wireshark 1. Open a terminal on your Unix/Linux system, 2. Update the package repository: sudo apt update # For Ubuntu/Debian-based systems 3. Install Wireshark: sudo apt install wireshark During installation, you might be prompted to allow nor-superusers to capture packets. Choose 'Yes!if you want to run Wireshark as a non-root user. Step 2: Capture Filter Example A capture filter is used to filter packets at the time of capture. It helps you capture only the specific network traffic you're interested in. For example, capturing only HTTP traffic. sruoy. To capture HTTP traffic using a capture filter: Nd 1, Open a terminal revert 2. Run Wireshark with root privileges to.capture packets: sudo wireshark 3. Inthe Wireshark GUI, select your network interface and start capturing. 4. Inthe "Capture Filter” field, enter the filter expression to capture only HTTP traffic: tcp port 80 ‘This filter captures only TCP packets on port 80 (HTTP). 5. Click the "Start® button to begin capturing. Step 3: Display Filter Example A display filter is used to analyze and display captured packets based on specific criteria. it helps you focus on specific packets in the captured data. 1. After capturing packets with Wireshark, you can apply @ display filter. 2. Inthe Wireshark GUI, in the "Display Filter” field, enter a filter expression to display only packets related to a specific protocol or condition, For example, to display only HTTP GET requests: Ger http.requestmetho Ignou Study Helper-Sunil Poonia Page S JOONIAZ ges ys Ton Sty HeLeee usLicaTion® “EY Sumi. Pooma ‘To cisplay only packets with a specific source IP address: ipste == 192.168.1.1 To display only TCP packets with a specific source and destination port: 443 Display titers are applied after capturing, and they do not affect which packets are captured. They only affect which packets are displayed. 2, (2) Run the following Linux commands on your machine and show the output "cat © sort © ping © more Ans. cat: This command is used to concatenate and display the contents of one or more files, Example usage: cat ignoustudyhelper. txt om f eye (Output (assuming "ignoustudyhelper.txt® contains some text): sort: The sort command is used to sort the lines of text files in ascending order. Example usage: sort filetxt Input (assuming "file.txt” contains unsorted numbers): Output: Ignou Study Helper-Sunil Poonia Page 6 JOONIAZ ges ys Ton Sty HeLeee usLicaTion® “EY Sumi PooMma ing? The ping command is used to test the reachability of a host on a network by sending ICMP echo requests and receiving ICMP echo replies. Example usage ping google.com Output: PE Mu a eR EL more: he more command is used to display the contents of a text file one screen at a time Example usage: more longfitestit Deo tons sy, Output (displays @ portion ofthe file and waits for user input} ‘er ager 2. (b) Configure the DHCP server on the Linux operating system. Write all the steps and also, sort each column of the table and show the result. Ans. Configuring a/DHCP (Dynamic Host Configuration Protocol) server on a Linux operating system involves several steps. Here's a general outline ofthe process along with the commands you can use. Note that the exact steps may vary depending on your Linux distribution, Step 1: Install DHCP Server 1. Open a terminal 2. Update your package repository: sudo apt update (for Debian/Ubuntu} sudo yum update (for CentOS/Red Hat) 3. Install the DHCP server package: sudo apt install isc-dhep-server (for Debian/Ubuntu) sudo yum install dhep (for CentOS/Red Hat) Step 2: Configure DHCP Server 1. Edit the DHCP configuration file using a text editor (e.g., nano, vim): Ignou Study Helper-Sunil Poonia Page JOONIAZ fyi Touou ‘Stuy HELPER UBLIEATIONS \ (= Sumit POONA sudo nano /etc/dhep/dhcpd.cont 2. Add or modify the DHCP configuration settings as needed. For example: subnet 192,168.1.0 netmask 255,255.255.0 { range 192.168.1.10 192.168.1.50; ‘option routers 192.168.1.1; option domasin-name-servers 88.2.8, 2.8.4.4; Step 3: Start and Enable DHCP Server 1. Start the DHCP service: sudo systernet| start ise-dhep-server (for Debian/Ubuntu) sudo systernet! start dhepd (for CentOS/Red Hat) 2. Enable the DHCP service to start at boot. sudo systemetl enable isc-dhep-server (for Debian/Ubuntu) sudo systemetl enable dhcpd (For CentOS/Red Hat) Step 4: Verify DHCP Server Status 1. Check the status of the DHCP service: sudo systemet! status isc-dhcp-server (for Debian/Ubuntu) sudo systemetl status dhepd (for CentOS/Red Hat) Sorting Columns ina Table: Ifyou have a table in a text file that you want to sort, you can use the sort command. For example, let's say you have a file named "data.txt" With the following content: s100y cers Cameco eCCet me ‘You can sort the table by a specific column using the sort command. For example, to sort by the "Name" column: sort -k1 data.txt FCPSTE RUE E Tiere TI EPR RPM neelnaaiag Ignou Study Helper-Sunil Poonia Page B Similarly, you can sort by other columns. For instance, to sort by the "IP Address" column: Output: as eres Coe PPO Reena Host 192,168.1.3011:22:33:44:55:65 Ignou Study Helper-Sunil Poonia Page 9

You might also like