Ajout de la prise en compte d'interface pour le multicast
This commit is contained in:
@@ -3,6 +3,7 @@ package network
|
||||
import (
|
||||
"StoreBackEnd/pkg/protocol/repository"
|
||||
"StoreBackEnd/pkg/protocol/rules/writers"
|
||||
"StoreBackEnd/pkg/utils"
|
||||
"fmt"
|
||||
"net"
|
||||
"time"
|
||||
@@ -48,6 +49,7 @@ func (client ClientMulticast) Run() {
|
||||
// Resolve interface addr
|
||||
lAddr, failedRIA := ResolveInterfaceAddr(client.netInter)
|
||||
if failedRIA {
|
||||
println("Error : No IPv4 found in interface")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -81,21 +83,18 @@ func (client ClientMulticast) ResolveAddr() (*net.UDPAddr, bool) {
|
||||
|
||||
// ResolveInterfaceAddr Resolves the network interface address.
|
||||
func ResolveInterfaceAddr(inter string) (*net.UDPAddr, bool) {
|
||||
//ief, _ := net.InterfaceByName(inter)
|
||||
//addrs, _ := ief.Addrs()
|
||||
//for _, addr := range addrs {
|
||||
// if utils.IsIPv4(addr.String()) {
|
||||
// println("Selected IP", addr.String())
|
||||
// lAddr, _ := net.ResolveUDPAddr("udp", "127.0.0.1:15502")
|
||||
// return lAddr, false
|
||||
// }
|
||||
//}
|
||||
return nil, false
|
||||
ip, err := utils.RetrieveIPv4FromInterface(inter)
|
||||
if err != nil {
|
||||
println("Error : " + err.Error())
|
||||
return nil, true
|
||||
}
|
||||
println("Selected IP : " + ip.String())
|
||||
return &net.UDPAddr{IP: ip}, false
|
||||
}
|
||||
|
||||
// DialUdp Ouvre une connection UDP
|
||||
func (client ClientMulticast) DialUdp(lAddr *net.UDPAddr, rAddr *net.UDPAddr) (*net.UDPConn, bool) {
|
||||
con, errDial := net.DialUDP("udp", nil, rAddr)
|
||||
con, errDial := net.DialUDP("udp", lAddr, rAddr)
|
||||
if errDial != nil {
|
||||
println(errDial.Error())
|
||||
return nil, true
|
||||
|
||||
Reference in New Issue
Block a user