summaryrefslogtreecommitdiff
path: root/src/lib/net/ip.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2008-09-17 13:49:23 -0700
committerRuss Cox <rsc@golang.org>2008-09-17 13:49:23 -0700
commitda2d685fc7d809f4aa8a4cd3e225aefca6e7fafb (patch)
tree3ffedc8f443bc3d02505140c254c839cf5ce73da /src/lib/net/ip.go
parent19004d3557dc1cdaef43e76c30e752857a6b826e (diff)
downloadgolang-da2d685fc7d809f4aa8a4cd3e225aefca6e7fafb.tar.gz
add network listening & tests
R=r,presotto OCL=15410 CL=15440
Diffstat (limited to 'src/lib/net/ip.go')
-rw-r--r--src/lib/net/ip.go12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/lib/net/ip.go b/src/lib/net/ip.go
index ddb5114c5..a96ae6709 100644
--- a/src/lib/net/ip.go
+++ b/src/lib/net/ip.go
@@ -336,6 +336,10 @@ func ParseIPv6(s string) *[]byte {
if len(s) >= 2 && s[0] == ':' && s[1] == ':' {
ellipsis = 0;
i = 2
+ // Might be only ellipsis
+ if i == len(s) {
+ return p
+ }
}
// Loop, parsing hex numbers followed by colon.
@@ -343,12 +347,12 @@ func ParseIPv6(s string) *[]byte {
L: for j < IPv6len {
// Hex number.
n, i1, ok := xtoi(s, i)
- if !ok || n >= 0xFFFF {
+ if !ok || n > 0xFFFF {
return nil
}
// If followed by dot, might be in trailing IPv4.
- if s[i1] == '.' {
+ if i1 < len(s) && s[i1] == '.' {
if ellipsis < 0 && j != IPv6len - IPv4len {
// Not the right place.
return nil
@@ -389,7 +393,7 @@ L: for j < IPv6len {
i++
// Look for ellipsis.
- if s[i+1] == ':' {
+ if s[i] == ':' {
if ellipsis >= 0 { // already have one
return nil
}
@@ -411,7 +415,7 @@ L: for j < IPv6len {
return nil
}
n := IPv6len - j
- for k := j; k >= ellipsis; k-- {
+ for k := j-1; k >= ellipsis; k-- {
p[k+n] = p[k]
}
for k := ellipsis+n-1; k>=ellipsis; k-- {