Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Wernet Protocol (IP) address is a unique number that allows computers to network together. Computers communicate similar to how sletter in the mail in the
Wernet Protocol (IP) address is a unique number that allows computers to network together. Computers communicate similar to how sletter in the mail in the virtual world, the letter is called a packet. In the real world, a letter has a message (the pead in the virtual world wrapped in an envelope (the header in the virtual world, and contains the source and destination addresses (typicaly IP addresses in the virtual world). The mail courier knows where each addresses on the map so that they can deliver the letter in the virtual world, a computer knows where each IP address is located in a network in the same way that a courier knows where each address les on the map Esch address may have its own name ZIP code, citystate, country, etc. The IP address is also divided into several subnetworks, niso called Sub Nets An IPv4 address has 4 bytes in the format bytel.bytez. byte3.byted, eg. 192.168.1.1, where each byte ranges from 0 to 255. A Computer may store an IP address as a wint32_t which specifies a four byte (or 32 bit) unsignedInteger, which preserves it's size (four bytes) across machines. This is just a fancy way of saying "four byte, unsigned variable that has a range from 0 to 4294967296 In this is you wilt convert a uint32_t to a readable IP address using bit shift ) and bitwie AND (6) operators, along with a mask ONPT, generate a Sublet mask to extract the first three bytes of the IP address and use the subNet mask to extract the network address Below is an example of how to use a mask Notein C, you can represent hexadecimal numbers by starting the number with Ox and you can represent a binary number by starting the number with Ob For instance OP in hexadecimalis 11111111 in binary and 255 in decimal. uint32IPads - Ox12345678, lastByteMask - Ox0000ODY; // declares and initialize to wint32 VLADs using hexadecimal numbers inttiTourth byte tuin", IPaddr lantaytamaskirt inter and is the bitwise AND Operator is a format specifier for an unained Executing this code will print Tourth byte is: 120" (120-078), which is the last byte of the IP address. IPAdde's bits may also be shifted and masked to obtain a different tyte's value as shown below This print "Thard byte is: 86" (860x56), the third byte of the IP address Youchis the following the template, assign the correct values to byte1 byte2 byte) byte4 using the bit shift and bitwise AND operators combined with the lastlytexask. 2. Then, generate a Suber mask by using the lastByteMask and the bitwise NOT operator and store it in the variable subnetMask This will result in a SubNet mask of OxFFFFFFO for this problem. Please note that bitwise NOT is a unary operator that takes a single argument 3. Using the AND (6) operator and the SubNet mask, extract the subnet addresses (ie the first three bytes) for IPAddr and localAddress and store the results in variables networkAddress1 and networkAddress2 4. Using the network addresses, bitwise XOR (*) operator, and if /else, determine if the packet came from the local network. If the XOR of the two network addresses is print 'The packet is from the local network. In otherwise, print the packet is not from the local network. In Example output Please input the IP Address: 2130706433 Subnet mask: Oxfretrron The IP address is: 127.0.0.1 The packet is not from the local network main.c Land default template include
Step 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