chiark / gitweb /
sd-dhcp: checksum - make endianess-neutral
authorTom Gundersen <teg@jklm.no>
Mon, 16 Jun 2014 13:24:28 +0000 (15:24 +0200)
committerTom Gundersen <teg@jklm.no>
Tue, 17 Jun 2014 07:17:07 +0000 (09:17 +0200)
commit0bbc2c1f3b8f01eac7826dab1a3e1e073f63da8a
tree9d9d4b65918390369b38d95f34947c2a20a89842
parent735a1a2ea5fb849e797c956bddf445a2a5bdf3d3
sd-dhcp: checksum - make endianess-neutral

For efficiency, we group bytes together before adding them up. This
is guaranteed to always work (regardless of the byte order) as long
as the i-th byte in each group lign up with the i-th byte in each
other group.

On big-endian machines this broke when handling the trailing few bytes
which did not make up a full group of 4 bytes. This patch fixes the
problem by explicitly creating a 4 byte zero-padded group out of the
trailing bytes.

Reported and tested by Thomas Ritter <th.ritter@gmx.at>.
src/libsystemd-network/dhcp-internal.h
src/libsystemd-network/dhcp-packet.c
src/libsystemd-network/test-dhcp-client.c