diff options
| author | Donald Sharp <sharpd@cumulusnetworks.com> | 2017-02-09 13:47:42 -0500 |
|---|---|---|
| committer | Donald Sharp <sharpd@cumulusnetworks.com> | 2017-02-24 10:03:40 -0500 |
| commit | 70ce34ae66184d4b456f45e6544c5fc0c350f2e5 (patch) | |
| tree | f70a9c99c048b7445648e47b40f0955c865ea4d4 /pimd/pim_msg.c | |
| parent | 09778298e231208c5862c62ca0096c9f0101e446 (diff) | |
pimd: Add 'struct pim_msg_header' packed data structure.
Add the 'struct pim_msg_header' and convert
all places that encoded/decoded the message header
to use it.
Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
Diffstat (limited to 'pimd/pim_msg.c')
| -rw-r--r-- | pimd/pim_msg.c | 19 |
1 files changed, 7 insertions, 12 deletions
diff --git a/pimd/pim_msg.c b/pimd/pim_msg.c index e8b1b5a622..97b9688aff 100644 --- a/pimd/pim_msg.c +++ b/pimd/pim_msg.c @@ -40,32 +40,27 @@ void pim_msg_build_header(uint8_t *pim_msg, int pim_msg_size, uint8_t pim_msg_type) { - uint16_t checksum; + struct pim_msg_header *header = (struct pim_msg_header *)pim_msg; zassert(pim_msg_size >= PIM_PIM_MIN_LEN); /* * Write header */ + header->ver = PIM_PROTO_VERSION; + header->type = pim_msg_type; + header->reserved = 0; - *(uint8_t *) PIM_MSG_HDR_OFFSET_VERSION(pim_msg) = (PIM_PROTO_VERSION << 4) | pim_msg_type; - *(uint8_t *) PIM_MSG_HDR_OFFSET_RESERVED(pim_msg) = 0; - /* - * Compute checksum - */ - - *(uint16_t *) PIM_MSG_HDR_OFFSET_CHECKSUM (pim_msg) = 0; + header->checksum = 0; /* * The checksum for Registers is done only on the first 8 bytes of the packet, * including the PIM header and the next 4 bytes, excluding the data packet portion */ if (pim_msg_type == PIM_MSG_TYPE_REGISTER) - checksum = in_cksum (pim_msg, PIM_MSG_REGISTER_LEN); + header->checksum = in_cksum (pim_msg, PIM_MSG_REGISTER_LEN); else - checksum = in_cksum (pim_msg, pim_msg_size); - - *(uint16_t *) PIM_MSG_HDR_OFFSET_CHECKSUM(pim_msg) = checksum; + header->checksum = in_cksum (pim_msg, pim_msg_size); } uint8_t *pim_msg_addr_encode_ipv4_ucast(uint8_t *buf, |
