Answered step by step
Verified Expert Solution
Question
1 Approved Answer
PROBLEM IS IN C Problem 4: IP address In today's world, we are all connected through our devices. Internet Protocol (IP) is at the heart
PROBLEM IS IN C
Problem 4: IP address In today's world, we are all connected through our devices. Internet Protocol (IP) is at the heart of Internet where it specifies an address for every device that is connected to the network. In general, Internet is a big network of connected subnetworks (subnets) and the addresses follow a hierarchy based on the subnets. In this problem you are given two IP addresses and a Network Mask and you have to determine whether those two IP addresses belong to the same subnet or not. An IP address is written as four numbers between 0 and 255 separated by a dot character. For instance 192.168.1.1 or 254.178.3.51 are valid IP addresses but 284.120.12.230 (285 is greater than 255) or 123.123..1 (third number is not given) are not. Each number can be represented with 8 bits and hence a byte (unsigned). So, we can put these 4 bytes together and store them in an integer variable that has 4 bytes (one byte per number that is separated by a dot). For instance, 254.23.10.1 can be broken down into 23 >00010111 10->00001010 1- 00000001 So, the corresponding 32 bit integer is 11111110000101110000101000000001 which when seen as an unsigned integer in decimal (base 10) is 4,262,922,753 A network mask is a number that is used to mask the exact address of the device and instead show the subnet address. Typically, because of the Internet's hierarchy, this number when represented in binary, has its N most significant bits set to 1. For instance, 11111111100000000000000000000000 (or in decimal 4,286,578,688) is a valid subnet mask (note that because of equivalence of IP address in their dot notation to integer numbers we can also write a subnet mask in the IP format. For instance, the subnet mask above can be written as 255.128.0.0 - but you don't need this conversion for this problem) When you bitwise and the IP address and the subnet mask, it extracts the most significant bits of the given IP address. It is usually known as the subnet address. Two IPs belong to the same subnet if they have the same subnet address In this problem, you are given two IP addresses in dot notation and a number N corresponding to the number of bits that are set to 1 in the subnet mask. Print 1 if they belong to the same subnet and 0 otherwise Sample input 192.168.1.10 192.172.23.144 Sample output: 13 10.10.20.20 11.10.20.20 10.10.20.20 11.10.20.20 Problem 4: IP address In today's world, we are all connected through our devices. Internet Protocol (IP) is at the heart of Internet where it specifies an address for every device that is connected to the network. In general, Internet is a big network of connected subnetworks (subnets) and the addresses follow a hierarchy based on the subnets. In this problem you are given two IP addresses and a Network Mask and you have to determine whether those two IP addresses belong to the same subnet or not. An IP address is written as four numbers between 0 and 255 separated by a dot character. For instance 192.168.1.1 or 254.178.3.51 are valid IP addresses but 284.120.12.230 (285 is greater than 255) or 123.123..1 (third number is not given) are not. Each number can be represented with 8 bits and hence a byte (unsigned). So, we can put these 4 bytes together and store them in an integer variable that has 4 bytes (one byte per number that is separated by a dot). For instance, 254.23.10.1 can be broken down into 23 >00010111 10->00001010 1- 00000001 So, the corresponding 32 bit integer is 11111110000101110000101000000001 which when seen as an unsigned integer in decimal (base 10) is 4,262,922,753 A network mask is a number that is used to mask the exact address of the device and instead show the subnet address. Typically, because of the Internet's hierarchy, this number when represented in binary, has its N most significant bits set to 1. For instance, 11111111100000000000000000000000 (or in decimal 4,286,578,688) is a valid subnet mask (note that because of equivalence of IP address in their dot notation to integer numbers we can also write a subnet mask in the IP format. For instance, the subnet mask above can be written as 255.128.0.0 - but you don't need this conversion for this problem) When you bitwise and the IP address and the subnet mask, it extracts the most significant bits of the given IP address. It is usually known as the subnet address. Two IPs belong to the same subnet if they have the same subnet address In this problem, you are given two IP addresses in dot notation and a number N corresponding to the number of bits that are set to 1 in the subnet mask. Print 1 if they belong to the same subnet and 0 otherwise Sample input 192.168.1.10 192.172.23.144 Sample output: 13 10.10.20.20 11.10.20.20 10.10.20.20 11.10.20.20Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started