Deserializing and serializing BGP message with BgpPacket.
#include <libbgp/bgp-packet.h>
#include <libbgp/bgp-update-message.h>
#include <libbgp/bgp-open-message.h>
#include <arpa/inet.h>
#include <stdio.h>
int main (void) {
const uint8_t *update_msg_buffer = (const uint8_t *) "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x1c\x02\x00\x05\x1c\x8d\xc1\x15\x10\x00\x00";
ssize_t deserializer_ret = deserializer.
parse(update_msg_buffer, 28);
if (deserializer_ret < 0) {
fprintf(stderr, "failed to deserialize.\n");
return 1;
}
char message_visualized[4096];
deserializer.
print((uint8_t *) message_visualized, 4096);
printf("%s", message_visualized);
printf(
"Size of withdrawn routes: %li\n", update_msg->
withdrawn_routes.size());
uint32_t bgp_id = 0;
inet_pton(AF_INET, "172.30.0.1", &bgp_id);
uint8_t message_serialized[4096];
ssize_t serializer_ret = serializer.
write(message_serialized, 4096);
if (serializer_ret < 0) {
fprintf(stderr, "failed to serialize.\n");
return 1;
}
serializer.
print((uint8_t *) message_visualized, 4096);
printf("%s", message_visualized);
return 0;
}