[SEBA-882] add Sadis server
Change-Id: I2c973a940ccf1398b1c122908769e806eaa1dd14
diff --git a/internal/common/helpers.go b/internal/common/helpers.go
index 4e1997b..c1bf936 100644
--- a/internal/common/helpers.go
+++ b/internal/common/helpers.go
@@ -17,8 +17,10 @@
package common
import (
- "github.com/opencord/voltha-protos/v2/go/openolt"
+ "net"
"strconv"
+
+ "github.com/opencord/voltha-protos/v2/go/openolt"
)
func OnuSnToString(sn *openolt.SerialNumber) string {
@@ -28,3 +30,31 @@
}
return s
}
+
+// GetIPAddr returns the IPv4 address of an interface. 0.0.0.0 is returned if the IP cannot be determined.
+func GetIPAddr(ifname string) (string, error) {
+ ip := "0.0.0.0"
+
+ intf, err := net.InterfaceByName(ifname)
+ if err != nil {
+ return ip, err
+ }
+
+ addrs, err := intf.Addrs()
+ if err != nil {
+ return ip, err
+ }
+
+ for _, addr := range addrs {
+ // get first IPv4 address
+ switch v := addr.(type) {
+ case *net.IPNet:
+ if v.IP.To4() != nil {
+ ip = v.IP.String()
+ break
+ }
+ }
+ }
+
+ return ip, nil
+}