Skip to content

Commit

Permalink
Add IPv6 ClientConfig flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Stergios Hetelekides authored and hetelek committed Jun 4, 2022
1 parent a4f7706 commit 801873f
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type ClientConfig struct {
Conn net.PacketConn // Listening socket (net.PacketConn)
LoggerFactory logging.LoggerFactory
Net *vnet.Net
IPv6 bool
}

// Client is a STUN server client
Expand Down Expand Up @@ -88,11 +89,18 @@ func NewClient(config *ClientConfig) (*Client, error) {
}

var stunServ, turnServ net.Addr
var stunServStr, turnServStr string
var stunServStr, turnServStr, network string
var err error

if config.IPv6 {
network = "udp6"
} else {
network = "udp4"
}

if len(config.STUNServerAddr) > 0 {
log.Debugf("resolving %s", config.STUNServerAddr)
stunServ, err = config.Net.ResolveUDPAddr("udp4", config.STUNServerAddr)
stunServ, err = config.Net.ResolveUDPAddr(network, config.STUNServerAddr)
if err != nil {
return nil, err
}
Expand All @@ -101,7 +109,7 @@ func NewClient(config *ClientConfig) (*Client, error) {
}
if len(config.TURNServerAddr) > 0 {
log.Debugf("resolving %s", config.TURNServerAddr)
turnServ, err = config.Net.ResolveUDPAddr("udp4", config.TURNServerAddr)
turnServ, err = config.Net.ResolveUDPAddr(network, config.TURNServerAddr)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 801873f

Please sign in to comment.