[C-prog-lang-l] Extra task - parsing IPv4 header

VladimĂ­r Kotal vlada at kotalovi.cz
Mon Mar 24 22:15:42 CET 2025


Hi all,

Here's the promised extra task from today:

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 IPv4 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. For more details and verification of the results you can peruse the following base64 encoded pcap file which contains the packet capture and can be opened e.g. in Wireshark or tcpdump.

1MOyoQIABAAAAAAAAAAAAAAABAABAAAAnksXZIlGDQCyAgAAsgIAAEgq41sHW/zs2kbPrQgARQACpJbS
QAAyBuRAA366ZgoAA10Bu6IapdiviH2dpvCAGAAITIAAAAEBCApSxIVdmcTYphcDAwJrtzrYaKLHiTD4
wgj3UE3RqNxJPAa7BSeA3P0dmRgcetM/eIeWo9eUT48v2G+pUwUxmbkjknA9slgp+ijsuqdSkDTC4Qyr
MDEADxA7qxAyIX5taF0JqutL00V3oxh+RpMSZCQkp0B7CIz0ow7j0Y+fI5ZSRZQo6kVT5cNMftmo0JOZ
jQGMBV9MDuqG4C89wUEwJuYunMrr4AJMT5iD9vPdwtNcjkmym6My30HnP9uQfJFl2cB++TBpi/bB+bpZ
8osWcsXCObRYcgHEG3cV3Bv6UVfnF3Pm3gUx8Ru5q9H7HMAMTkYsA3UME/vFk3NsVW098hJmAEvAbChG
Bl+g6sZG3+367JKxEJaNx+DeUkSC2OJv2JeH2XW/hgOEbVQ6swZL0DLm/taRByUni6/eWiiMjxaC7So1
2kIc/TlH1d9zsKOarQTi+utvb/Bj/kIrW6GQkj5vBxBR2Q/DCoTbsdaTnbFnWdArJ4CGfhM1B+2LJdU0
xUH6SxJoBShYavZu1Ra1/6Dv7cPy7yY1teLkK6YYTfBcMzB1M+SmmGe5hcCuSxYTWFwELO/GsO9SILwv
pStmmpIF5cTsuyCz/Qw/+0A/Zhlt05LvqtdMfjnEYn4+rABgcrhXBUTYPsEEVIqn5jaiJ4o9f0IuFZiX
pttTs4DOIxtDS4Gt8kUezp9mEZGuBZ6QGsW91FMTjvRPvO70yeDCRQVx9twogTO93TjGmvthMZO/4OrL
VhFR++9baNhRt0QZKDq2umPg21oIUUygMZYb2jCv1qqkoLjVyTPrqVOCoJQm54WBWLUKZfvKL/fecd86
MrBuNtjv4YuhUA==

Best regards,


V. Kotal
-------------- next part --------------
HTML attachment scrubbed and removed


More information about the c-prog-lang-l mailing list