libbgp  0.6
A C++ BGP Library.
bgp-bad-message.cc
Go to the documentation of this file.
1 
11 #include "bgp-bad-message.h"
12 #include "bgp-errcode.h"
13 #include <unistd.h>
14 
15 namespace libbgp {
16 
23 BgpBadMessage::BgpBadMessage(BgpLogHandler *logger, uint8_t type) : BgpMessage(logger) {
24  this->type = type;
25 }
26 
27 ssize_t BgpBadMessage::parse(__attribute__((unused)) const uint8_t *from, __attribute__((unused)) size_t msg_sz) {
28  logger->log(ERROR, "BgpBadMessage::parse: unknow message type %d\n", type);
29  setError(E_HEADER, E_TYPE, &type, 1);
30  return -1;
31 }
32 
33 ssize_t BgpBadMessage::write(__attribute__((unused)) uint8_t *to, __attribute__((unused)) size_t msg_sz) const {
34  logger->log(ERROR, "BgpBadMessage::write: you can't write a bad message\n");
35  return -1;
36 }
37 
38 ssize_t BgpBadMessage::doPrint(__attribute__((unused)) size_t indent, uint8_t **to, __attribute__((unused)) size_t *buf_sz) const {
39  return _print(indent, to, buf_sz, "InvalidMessage { }\n");
40 }
41 
42 }
ssize_t write(uint8_t *to, size_t buf_sz) const
Serialize a BGP message body.
static ssize_t _print(size_t indent, uint8_t **to, size_t *buf_left, const char *format,...)
Print helper.
BgpBadMessage(BgpLogHandler *logger, uint8_t type)
Construct a new Bgp Bad Message:: Bgp Bad Message object.
Container for invalid BGP message.
void log(LogLevel level, const char *format_str,...)
Log a message. Consider using LIBBGP_LOG if logging the message needs a lot of computing power...
ssize_t parse(const uint8_t *from, size_t msg_sz)
Deserialize a BGP message body.
The BgpMessage base class.
Definition: bgp-message.h:35
void setError(uint8_t err, uint8_t suberr, const uint8_t *data, size_t data_len)
Set the error information.
Definition: serializable.cc:61
Definition: bgp-afi.h:14
The BgpLogHandler class.
BGP error codes.
ssize_t doPrint(size_t indent, uint8_t **to, size_t *buf_sz) const
Print implementation.