-
Notifications
You must be signed in to change notification settings - Fork 120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support binding specified IP #51
Conversation
main.go
Outdated
@@ -24,7 +24,8 @@ import ( | |||
|
|||
func main() { | |||
var serverAddr = flag.String("s", stun.DefaultServerAddr, "STUN server address") | |||
var localPort = flag.Int("p", 0, "The port on which to bind requests, set to 0 to pick a random port") | |||
var localPort = flag.Int("p", 0, "The ip on which to bind requests, set to empty will keep default") | |||
var localIP = flag.String("i", "", "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not have one addreess that takes an address with a port?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because in some cases you only need to specify the port, not the IP?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could still do "192.168.0.10:0" or ":5738" or both etc.
stun/client.go
Outdated
if c.localPort != 0 { | ||
laddr, err = net.ResolveUDPAddr("udp", fmt.Sprintf(":%d", c.localPort)) | ||
address += strconv.Itoa(c.localPort) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think we need a :
between ip and port
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you're right, I forgot about this
stun/client.go
Outdated
address += strconv.Itoa(c.localPort) | ||
} | ||
|
||
if c.localPort != 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we not put the two if c.localPort != 0 {
together?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've taken care of it and look better now
f107d31
to
4095b02
Compare
stun/client.go
Outdated
laddr, err = net.ResolveUDPAddr("udp", fmt.Sprintf(":%d", c.localPort)) | ||
|
||
if c.localPort != 0 || c.localIP != "" { | ||
var address = c.localIP + ":" + strconv.Itoa(c.localPort) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var address = c.localIP + ":" + strconv.Itoa(c.localPort) | |
var address = fmt.Sprintf("%s:%d", c.localIP, c.localPort) |
stun/client.go
Outdated
if c.localPort != 0 { | ||
laddr, err = net.ResolveUDPAddr("udp", fmt.Sprintf(":%d", c.localPort)) | ||
if c.localPort != 0 || c.localIP != "" { | ||
var address = c.localIP + ":" + strconv.Itoa(c.localPort) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
lgtm after fixing the above minor issues |
What about ipv6 addresses? |
ipv6 doesn't have NAT |
merge ? |
No description provided.