[C-prog-lang-l] task: IPv4 header parsing using pointer arithmetics
Vladimír Kotal
vlada at kotalovi.cz
Mon Mar 25 21:01:37 CET 2024
Hi all,
here's the extra task we did not have time for at the end of the lecture:
Consider this IPv4 packet (no options/padding, just a plain IPv4 packet):
`0000 45 00 00 34 65 6e 40 00 40 06 0a 15 0a 00 03 5d
0010 03 7e ba 66
`
Initialize an array with the individual bytes and then use pointer arithmetics, in particular pointer dereference and postfix increment or decrement, and print the source and destination IP address to standard output in the common dot notation form (a.b.c.d).
See RFC 791 <https://www.rfc-editor.org/rfc/rfc791> for the packet structure.
Sample output:
pkt_len (idx) = 20
src: 10.0.3.93
dst: 3.126.186.102
There is also another home task at the end of the lecture materials from today.
Best regards,
V. Kotal
-------------- next part --------------
HTML attachment scrubbed and removed
More information about the c-prog-lang-l
mailing list