EETimes

Embedded Systems September 2000 Vol13_10

Issue link: http://dc.ee.ubm-us.com/i/71837

Contents of this Issue

Navigation

Page 73 of 229

CONNECTING ..• #define IP __ VER __ HLEN Ox45 #define IP __ HEADER __ LEN sizeofCNetlpHdr) #define IP __ DATA __ LEN I* * IP Packet *I typedef struct { NetlpHdr unsigned char } ipHdr; data[!P_pATA __ LENJ; CMTU - IP __ HEADER __ LEN) suppo rted , le t ' fo r a lot of applica ti o ns, my imple- me nta tion of th e IP layer includes o n ly a so rt of ba re-minimum o [ fun c tio na li ty to sa tisfy IPv4-style communicati ons. Most comme rcial TCP / IP stacks fo r sale in the em bed- ded sys tems ma rke tplace are more comple te. To ge t a feel fo r wha t is and isn ' t look a t the da ta LISTING int NetlpSndCNetlpPkt * plpPkt, INT16U len) { INT16U ident; I* * Assign a unique ID to the outgoing packet . *I II Enter critical section here. ident = gNextPacketiD++; II Leave critical section here. I* * Fill in the rema1n1ng IP header fields. * (Some fields were pre-filled by the UDP Layer.) *I plpPkt->ipHdr.ver-Plen plpPkt->ipHdr.service plpPkt->ipHdr.Length plpPkt->ipHdr.ident = IP __ VER __ HLEN; = OxOO; = htonsC Len); = htonsCident); plpPkt->ipHdr.fragment = OxOO; plpPkt->ipHdr.timetolive = Ox10; I* plpPkt->ipHdr.checksum = NetlpChecksumCCINT16U *) plpPkt, IP __ HEADER __ LEN); I* * Compute and fill in the IP header checksum. *I * Forward the IP packet to the network interface driver. *I return (NetPhySndChtonsCPROTO __ IP), (unsigned char *) plpPkt, Len)); } 'A funct1on to send an IP packet . ···. .· · · . . · ·:,;t:;.f£~~ structures and co nstants defined in Listing I. Of pa rticular note here is tha t the NetlpHdr structure defin es a header of a fixed size. In truth, the length of this header may be extended in 32-bit increments to support some less common ly used IP feature . However, pC/ Net never uses any of the special features that these exten- sions allow. So variable length IP headers are not generated by the stack and it will rej ect any incoming IP pack- ets that have a header of length other than 20 bytes. The first field in any IP header, ver __ hlen, gives the protocol version (4 for IPv4) in the first nibble and head- er length (five 32-bit words for th e fixed size header) in the second ni b- ble. Al l of the IP packets sent by pC/ Net will , the refore, have this field set to the constant value Ox45. Similarly, it is a requirement that all packets received by the stack have that same value in ver __ h len. In add ition to this restri ction, seve ra l o the r features of IP a re e ithe r unsupported by pC/ Net o r the suppo rt is significantly caled back. The on ly one of these tha t is li kely to affect you is th eir lack of support fo r fragme ntation and reassembly. Fragmentation and reassembly Etherne t fram es have a defin ed max- imum size payload of 1,500 bytes each. This is termed th e maximum transmission uni t, or MTU, of the physical network. Included with in that payload are the contents o f the IP heade r, the UDP (or TCP) heade r, and th e actual data. If all of the pack- 72 SEPTEMBER 2000 Embedded Syst ems Programming

Articles in this issue

Archives of this issue

view archives of EETimes - Embedded Systems September 2000 Vol13_10