25.03.2013 Views

Cracking the Coding Interview - Fooo

Cracking the Coding Interview - Fooo

Cracking the Coding Interview - Fooo

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Solutions to Chapter 17 | Networking<br />

17 4 What is a network / subnet mask? Explain how host A sends a message / packet to<br />

host B when: (a) both are on same network and (b) both are on different networks<br />

Explain which layer makes <strong>the</strong> routing decision and how<br />

SOLUTION<br />

CareerCup com<br />

pg 84<br />

A mask is a bit pattern used to identify <strong>the</strong> network/subnet address The IP address consists<br />

of two components: <strong>the</strong> network address and <strong>the</strong> host address<br />

The IP addresses are categorized into different classes which are used to identify <strong>the</strong> network<br />

address<br />

Example: Consider IP address 152 210 011 002 This address belongs to Class B, so:<br />

Network Mask: 11111111.11111111.00000000.00000000<br />

Given Address: 10011000.11010101.00001011.00000010<br />

By ANDing Network Mask and IP Address, we get <strong>the</strong> following network address:<br />

10011000.11010101.00000000.00000000 (152.210.0.0)<br />

Host address: 00001011.00000010<br />

Similarly, a network administrator can divide any network into sub-networks by using subnet<br />

mask To do this, we fur<strong>the</strong>r divide <strong>the</strong> host address into two or more subnets<br />

For example, if <strong>the</strong> above network is divided into 18 subnets (requiring a minimum of 5 bits<br />

to represent 18 subnets), <strong>the</strong> first 5 bits will be used to identify <strong>the</strong> subnet address<br />

Subnet Mask: 11111111 11111111 11111000 00000000 (255 255 248 0)<br />

Given Address: 10011000 11010101 00001011 00000010<br />

So, by ANDing <strong>the</strong> subnet mask and <strong>the</strong> given address, we get <strong>the</strong> following subnet address:<br />

10011000 11010101 00001000 00000000 (152 210 1 0)<br />

How Host A sends a message/packet to Host B:<br />

When both are on same network: <strong>the</strong> host address bits are used to identify <strong>the</strong> host within<br />

<strong>the</strong> network<br />

Both are on different networks: <strong>the</strong> router uses <strong>the</strong> network mask to identify <strong>the</strong> network and<br />

route <strong>the</strong> packet The host can be identified using <strong>the</strong> network host address<br />

The network layer is responsible for making routing decisions A routing table is used to<br />

store <strong>the</strong> path information and <strong>the</strong> cost involved with that path, while a routing algorithm<br />

uses <strong>the</strong> routing table to decide <strong>the</strong> path on which to route <strong>the</strong> packets<br />

Routing is broadly classified into Static and Dynamic Routing based on whe<strong>the</strong>r <strong>the</strong> table is<br />

fixed or it changes based on <strong>the</strong> current network condition<br />

2 5 4

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!