Here is an excerpt of a post on the OpenView Forum list.  It's related
to our neverending discussions of how hosts make forwarding decisions,
when they forward packets to their gateway, and when they send ARP
requests.  I've never seen it presented quite this way and thought it
was interesting to look at.  (Thanks to Fred Reimer on the OVForum list
for this.)



I find that it helps to understand the way NNM works, and networks in
general in fact, if one has a certain amount of programming
experience.  What better way to explain subnet masking, for instance,
than a chunk of code such as:

IPAddr myIPAddr = ipbystring("10.1.1.2");
IPAddr myMask = ipbystring("255.255.255.0");
IPAddr mygwAddr = ipbystring("10.1.1.1");
MACAddr gwMAC;

int sendpacket(IpPacket *p, IPAddr *destIPAddr)
{
        IPAddr mySubnet;
        IPAddr destSubnet;
        MACAddr destMAC;
        int ret;
        Frame *frame;

        if ((frame = malloc(sizeof(Frame)) == NULL) {
                return -1;
        }

        mySubnet = myIPAddr & myMask;
        destSubnet = destIPAddr & myMask;

        if (mySubnet == destSubnet) {
                /* on same subnet */
                destMAC = ARPforMAC(destIPAddr);
                setFrameDest(destMac);
        } else {
                /* on different subnet */
                gwMAC = ARPforMAC(mygwAddr);
                setFrameDest(gwMAC);
        }
        setFramePayload(frame, p);
        ret = sendFrame(frame);
        free(frame);
        return ret;
}

It's not exactly C, but it should get the point across.  Granted, no
production IP stacks probably don't look like this at all, but
the certainly would follow the same logic.  If you can understand this
then you shouldn't have any problem understanding subnet
masks. 






Message Posted at:
http://www.groupstudy.com/form/read.php?f=7&i=21580&t=21580
--------------------------------------------------
FAQ, list archives, and subscription info: http://www.groupstudy.com/list/cisco.html
Report misconduct and Nondisclosure violations to [EMAIL PROTECTED]

Reply via email to