From: Waldemar Kozaczuk <jwkozac...@gmail.com>
Committer: Waldemar Kozaczuk <jwkozac...@gmail.com>
Branch: master

golang: add simple app to verify network and IP enumration works on OSv

Signed-off-by: Waldemar Kozaczuk <jwkozac...@gmail.com>

---
diff --git a/golang-net-iterate/Makefile b/golang-net-iterate/Makefile
--- a/golang-net-iterate/Makefile
+++ b/golang-net-iterate/Makefile
@@ -0,0 +1,9 @@
+.PHONY: module
+module: net_iterate.so
+       echo '/net_iterate.so: $${MODULE_DIR}/net_iterate.so' > usr.manifest
+
+net_iterate.so: net_iterate.go
+       go build -buildmode=pie -ldflags "-linkmode external" -o net_iterate.so 
net_iterate.go
+
+clean:
+       rm -f net_iterate*.so usr.manifest
diff --git a/golang-net-iterate/README.md b/golang-net-iterate/README.md
--- a/golang-net-iterate/README.md
+++ b/golang-net-iterate/README.md
@@ -0,0 +1,3 @@
+This is a simple golang app that tests if OSv correctly
+supports enumating network interfaces and IPs using netlink
+interface.
diff --git a/golang-net-iterate/module.py b/golang-net-iterate/module.py
--- a/golang-net-iterate/module.py
+++ b/golang-net-iterate/module.py
@@ -0,0 +1,3 @@
+from osv.modules import api
+
+default = api.run(cmdline="/net_iterate.so")
diff --git a/golang-net-iterate/net_iterate.go 
b/golang-net-iterate/net_iterate.go
--- a/golang-net-iterate/net_iterate.go
+++ b/golang-net-iterate/net_iterate.go
@@ -0,0 +1,44 @@
+package main
+
+import (
+        "fmt"
+        "net"
+)
+
+func main() {
+       addrs, err := net.InterfaceAddrs()
+       if err != nil {
+               fmt.Println("Error: %s\n", err);
+       }
+
+       for _, addr := range addrs {
+               fmt.Println("-----------------");
+               fmt.Println("Addr: ", addr.String());
+               var ip net.IP
+               switch v := addr.(type) {
+               case *net.IPNet:
+                       ip = v.IP
+               case *net.IPAddr:
+                       ip = v.IP
+               }
+               if ip == nil || ip.IsLoopback() || ip.IsUnspecified() {
+                       continue
+               }
+               ip = ip.To4()
+               if ip == nil {
+                       continue // not an ipv4 address
+               }
+               fmt.Println("IP 4 Addr: ", ip.String());
+       }
+
+       fmt.Println("\n\n Interfaces...")
+       ints, err := net.Interfaces()
+       if err != nil {
+               fmt.Println("Error: %s\n", err);
+       }
+
+       for _, intf := range ints {
+               fmt.Println("-----------------");
+               fmt.Println("Interface: ", intf.Name);
+        }
+}

-- 
You received this message because you are subscribed to the Google Groups "OSv 
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to osv-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/osv-dev/0000000000003fbbae05e0c84f81%40google.com.

Reply via email to