Ajout de la prise en compte d'interface pour le multicast

This commit is contained in:
2022-03-14 11:40:23 +01:00
parent a0f17fefe1
commit 3edaf6728f
3 changed files with 31 additions and 19 deletions

View File

@@ -44,11 +44,3 @@ func copyFile(currentSize int, fileSize int, reader *bufio.Reader, buffer []byte
}
return false, false
}
func fileExists(filename string) bool {
info, err := os.Stat(filename)
if os.IsNotExist(err) {
return false
}
return !info.IsDir()
}

View File

@@ -1,6 +1,7 @@
package utils
import (
"errors"
"fmt"
"net"
"strings"
@@ -29,6 +30,26 @@ func NetworkLister() {
print("\n")
}
// RetrieveIPv4FromInterface Retrieve the first IPv4 from an interface.
func RetrieveIPv4FromInterface(inter string) (net.IP, error) {
ief, err := net.InterfaceByName(inter)
addrs, err := ief.Addrs()
if err != nil {
return nil, err
}
for _, addr := range addrs {
switch v := addr.(type) {
case *net.IPNet:
//if !v.IP.IsLoopback() {
if v.IP.To4() != nil { //Verify if IP is IPV4
return v.IP, nil
}
//}
}
}
return nil, errors.New("no IPv4 found")
}
// IsIPv4 Check if the ip is a v4 or v6 ip
func IsIPv4(addr string) bool {
return strings.Count(addr, ":") < 2