-
Notifications
You must be signed in to change notification settings - Fork 234
Bug 104714: implement HasIPConnected on Darwin #42
Conversation
@@ -62,8 +64,104 @@ func HasSeenMac(val string) (found bool, elements []element, err error) { | |||
return | |||
} | |||
|
|||
func parseEndpointString(str string) (ip net.IP, port int) { | |||
re, err := regexp.Compile("^(.*?)(%[a-z0-9]+)?\\.(\\*|[0-9]+)$") |
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.
It'd be nice to not re-compile this regexp every time -- tips?
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 define it as a global variable, since the regexp is static:
package main
import (
"fmt"
"regexp"
)
var re = regexp.MustCompile("^$")
func main() {
if re.MatchString("test") {
fmt.Println("test doesn't match")
}
if re.MatchString("") {
fmt.Println("empty string matches")
}
}
@jvehent pointed out http://stackoverflow.com/questions/5390164/getting-routing-table-on-macosx-programmatically -- not sure that's worth the effort.. |
func parseEndpointString(str string) (ip net.IP, port int) { | ||
re, err := regexp.Compile("^(.*?)(%[a-z0-9]+)?\\.(\\*|[0-9]+)$") | ||
if err != nil { | ||
panic(err) |
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 would recommend not panicking directly, but instead return an error value here, or panic and recover.
Looks good. Just a couple minors. |
OK, those should be fixed up - let me know what you think |
Looks good. r+ |
Bug 104714: implement HasIPConnected on Darwin
I tested this by hand on OS X 10.8.
I did run into some trouble, indicated by the comments inline, where netstat produces a truncated ipv6 address. I don't have any idea how to fix that, or if it's even possible.