Computer networks lab da 4 22bce0411
Computer networks lab da 4 22bce0411
Lab assignment 4
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
You are asked to divide this network into 4 subnets and include a point-to-point link.
• 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 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:
2. Subnet 2:
3. Subnet 3:
4. Subnet 4:
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
• Broadcast: 192.168.10.67
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <arpa/inet.h>
void server_mode();
void client_mode();
int main() {
int choice;
printf("Choose mode:\n");
printf("1. Server\n");
printf("2. Client\n");
scanf("%d", &choice);
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];
// Create socket
exit(EXIT_FAILURE);
server_addr.sin_addr.s_addr = INADDR_ANY;
server_addr.sin_port = htons(PORT);
perror("Bind failed");
close(sockfd);
exit(EXIT_FAILURE);
buffer[BUF_SIZE - 1] = '\0';
printf("Server: ");
close(sockfd);
void client_mode() {
int sockfd;
char buffer[BUF_SIZE];
// Create socket
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) {
printf("Client: ");
buffer[BUF_SIZE - 1] = '\0';
close(sockfd);