0% found this document useful (0 votes)
218 views9 pages

Computer networks lab da 4 22bce0411

Uploaded by

swastik raj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
218 views9 pages

Computer networks lab da 4 22bce0411

Uploaded by

swastik raj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Computer networks

Lab assignment 4

Name:- Swastik raj


Register no. :- 22BCE0411
Branch:- Computer science and engineering
core
Faculty name:- Dr. A Suresh
Slot:- L5 + L6
1. Subnetting Scheme (Part A)

You are given an IP address range: 192.168.10.0/26. The /26 means that the first 26 bits are used for
the network portion, leaving 6 bits for host addresses.

• IP Range:

o 192.168.10.0/26

o Subnet Mask: 255.255.255.192


o The total number of available IP addresses is 26=642^6 = 6426=64 per subnet, but
two addresses are reserved (network and broadcast), leaving 62 usable IP addresses.

You are asked to divide this network into 4 subnets and include a point-to-point link.

Step 1: Determine the number of subnets required

You need 4 subnets, each with an equal number of hosts.

• You can split the network further by borrowing additional bits from the host portion of the
address. To create 4 subnets, you need at least 2 more bits.

• Extending the network prefix from /26 to /28 gives us the following:

o Subnet Mask: 255.255.255.240

o Number of IPs per subnet: 24=162^4 = 1624=16 total, but 14 usable addresses (after
reserving 1 for network and 1 for broadcast).

Step 2: Calculate the network, first usable, last usable, and broadcast addresses for each subnet

1. Subnet 1:

o Network Address: 192.168.10.0/28

o First Usable IP: 192.168.10.1

o Last Usable IP: 192.168.10.14

o Broadcast Address: 192.168.10.15

2. Subnet 2:

o Network Address: 192.168.10.16/28

o First Usable IP: 192.168.10.17

o Last Usable IP: 192.168.10.30

o Broadcast Address: 192.168.10.31

3. Subnet 3:

o Network Address: 192.168.10.32/28

o First Usable IP: 192.168.10.33

o Last Usable IP: 192.168.10.46

o Broadcast Address: 192.168.10.47

4. Subnet 4:

o Network Address: 192.168.10.48/28

o First Usable IP: 192.168.10.49

o Last Usable IP: 192.168.10.62

o Broadcast Address: 192.168.10.63


Point-to-Point Link:

For the point-to-point link between the routers, you can allocate a separate /30 subnet (2 usable IPs).

• Network: 192.168.10.64/30

• Usable IPs: 192.168.10.65 and 192.168.10.66

• Broadcast: 192.168.10.67
#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <unistd.h>

#include <arpa/inet.h>

#define PORT 8080

#define BUF_SIZE 1024

void server_mode();

void client_mode();

int main() {

int choice;

printf("Choose mode:\n");

printf("1. Server\n");

printf("2. Client\n");

printf("Enter choice: ");

scanf("%d", &choice);

getchar(); // To consume newline left by scanf()

if (choice == 1) {

server_mode();

} else if (choice == 2) {

client_mode();

} else {
printf("Invalid choice.\n");

return 0;

void server_mode() {

int sockfd;

char buffer[BUF_SIZE];

struct sockaddr_in server_addr, client_addr;

socklen_t addr_len = sizeof(client_addr);

// Create socket

if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {

perror("Socket creation failed");

exit(EXIT_FAILURE);

// Fill server information

server_addr.sin_family = AF_INET; // IPv4

server_addr.sin_addr.s_addr = INADDR_ANY;

server_addr.sin_port = htons(PORT);

// Bind the socket with the server address

if (bind(sockfd, (const struct sockaddr *)&server_addr, sizeof(server_addr)) < 0) {

perror("Bind failed");

close(sockfd);

exit(EXIT_FAILURE);

printf("Server is up, waiting for messages...\n");


while (1) {

// Receive message from client

recvfrom(sockfd, buffer, BUF_SIZE, 0, (struct sockaddr *)&client_addr, &addr_len);

buffer[BUF_SIZE - 1] = '\0';

printf("Client: %s", buffer);

// Send response back to client

printf("Server: ");

fgets(buffer, BUF_SIZE, stdin);

sendto(sockfd, buffer, strlen(buffer), 0, (struct sockaddr *)&client_addr, addr_len);

close(sockfd);

void client_mode() {

int sockfd;

char buffer[BUF_SIZE];

struct sockaddr_in server_addr;

// Create socket

if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {

perror("Socket creation failed");

exit(EXIT_FAILURE);

// Server information

server_addr.sin_family = AF_INET;

server_addr.sin_port = htons(PORT);

server_addr.sin_addr.s_addr = INADDR_ANY;
while (1) {

// Send message to server

printf("Client: ");

fgets(buffer, BUF_SIZE, stdin);

sendto(sockfd, buffer, strlen(buffer), 0, (struct sockaddr *)&server_addr, sizeof(server_addr));

// Receive response from server

recvfrom(sockfd, buffer, BUF_SIZE, 0, NULL, NULL);

buffer[BUF_SIZE - 1] = '\0';

printf("Server: %s", buffer);

close(sockfd);

You might also like