Browse Source

move definition of Link to link.h

Fabian Peter Hammerle 7 years ago
parent
commit
37f991b52d
2 changed files with 31 additions and 19 deletions
  1. 28 0
      link.h
  2. 3 19
      main.cpp

+ 28 - 0
link.h

@@ -0,0 +1,28 @@
+#ifndef _IPYML_LINK_H
+#define _IPYML_LINK_H
+
+#include "hardware_address.h"
+#include "yaml.h"
+
+#include <ostream>
+#include <string>
+
+class Link : public YamlObject {
+public:
+  std::string ifname;
+  HardwareAddress hwaddr, broadcast;
+
+  void write_yaml(std::ostream &stream,
+                  const yaml_indent_level_t indent_level = 0) const {
+    const std::string indent(indent_level, ' ');
+    stream << "ifname: " + ifname + "\n";
+    stream << indent + "hwaddr: ";
+    hwaddr.write_yaml(stream);
+    stream << "\n";
+    stream << indent + "broadcast: ";
+    broadcast.write_yaml(stream);
+    stream << "\n";
+  }
+};
+
+#endif

+ 3 - 19
main.cpp

@@ -1,33 +1,17 @@
 #include "hardware_address.h"
+#include "link.h"
 #include "vector.h"
-#include "yaml.h"
 
 #include <assert.h>
 #include <iostream>
 #include <libmnl/libmnl.h>
-#include <linux/if.h>
+#include <linux/if_link.h>
+#include <linux/netlink.h>
 #include <linux/rtnetlink.h>
 #include <string>
 
 // https://netfilter.org/projects/libmnl/doxygen/html/modules.html
 
-struct Link : public YamlObject {
-  std::string ifname;
-  HardwareAddress hwaddr, broadcast;
-
-  void write_yaml(std::ostream &stream,
-                  const yaml_indent_level_t indent_level = 0) const {
-    const std::string indent(indent_level, ' ');
-    stream << "ifname: " + ifname + "\n";
-    stream << indent + "hwaddr: ";
-    hwaddr.write_yaml(stream);
-    stream << "\n";
-    stream << indent + "broadcast: ";
-    broadcast.write_yaml(stream);
-    stream << "\n";
-  }
-};
-
 static int link_attr_cb(const nlattr *attr, void *data) {
   Link *link = (Link *)data;
   // /usr/include/linux/if_link.h