address.h 817 B

12345678910111213141516171819202122232425262728293031323334
  1. #ifndef _IPYML_ADDRESS_H
  2. #define _IPYML_ADDRESS_H
  3. #include "inet_address.h"
  4. #include "yaml.h"
  5. #include <libmnl/libmnl.h>
  6. #include <linux/if_addr.h>
  7. #include <linux/netlink.h>
  8. #include <ostream>
  9. class Address : public YamlObject {
  10. InetAddress inet_addr;
  11. public:
  12. // typedef int (*mnl_attr_cb_t)(const struct nlattr *attr, void *data);
  13. static int mnl_attr_cb(const nlattr *attr, void *data) {
  14. Address *addr = (Address *)data;
  15. // /usr/include/linux/if_addr.h
  16. switch (mnl_attr_get_type(attr)) {
  17. case IFA_ADDRESS:
  18. addr->inet_addr = attr;
  19. break;
  20. }
  21. }
  22. void write_yaml(std::ostream &stream,
  23. const yaml_indent_level_t indent_level = 0) const {
  24. // const std::string indent(indent_level, ' ');
  25. inet_addr.write_yaml(stream, indent_level + 2);
  26. }
  27. };
  28. #endif