static void eth_serialize(struct proto_info const *info_, uint8_t **buf) { struct eth_proto_info const *info = DOWNCAST(info_, info, eth_proto_info); proto_info_serialize(info_, buf); serialize_3(buf, info->vlan_id); // 16 bits for vlan itself, +we need to handle -1 for UNSET serialize_n(buf, info->addr[0], ETH_ADDR_LEN); serialize_n(buf, info->addr[1], ETH_ADDR_LEN); serialize_2(buf, info->protocol); }
static void dhcp_serialize(struct proto_info const *info_, uint8_t **buf) { struct dhcp_proto_info const *info = DOWNCAST(info_, info, dhcp_proto_info); proto_info_serialize(info_, buf); serialize_1(buf, info->hw_addr_is_eth + (info->opcode << 1U)); serialize_4(buf, info->xid); serialize_1(buf, info->set_values); if (info->set_values & DHCP_CLIENT_SET) ip_addr_serialize(&info->client, buf); serialize_n(buf, info->client_mac, sizeof(info->client_mac)); serialize_str(buf, info->server_name); }
void ip_addr_serialize(struct ip_addr const *addr, uint8_t **buf) { if (addr->family == AF_INET) { serialize_1(buf, 4); serialize_4(buf, addr->u.v4.s_addr); } else if (addr->family == AF_INET6) { serialize_1(buf, 6); serialize_n(buf, &addr->u.v6, sizeof(addr->u.v6)); } else { SLOG(LOG_ERR, "Cannot serialize ip_addr of unknown type"); } }