20.01.2014 Views

Lectures notes for 2010 - KTH

Lectures notes for 2010 - KTH

Lectures notes for 2010 - KTH

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

packetsize+=ip->ihlcheck=0; /* ignore UDP checksum */<br />

packetsize+=sizeof(struct udphdr);<br />

/* end of udp header */<br />

/* add data to UDP payload if you want: */<br />

<strong>for</strong> (datasize=0;datasizelen=htons(sizeof(struct udphdr)+datasize);<br />

ip->tot_len=htons(packetsize);<br />

if (sendto(s, (char *)outpack, packetsize, 0, &addrto, sizeof(struct sockaddr))==-1)<br />

{perror("sendto"); exit(2);}<br />

}<br />

printf("packet sent !\n");<br />

close(s);<br />

exit(0);<br />

Maguire Building a UDP packet from scratch 4: 26 of 74<br />

maguire@kth.se <strong>2010</strong>.03.21 Internetworking/Internetteknik

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

Saved successfully!

Ooh no, something went wrong!