update Go tree to use new syscall package.

R=r
DELTA=713  (109 added, 386 deleted, 218 changed)
OCL=29707
CL=29722
diff --git a/src/lib/net/Makefile b/src/lib/net/Makefile
index efd6b3e..0bbc4a0 100644
--- a/src/lib/net/Makefile
+++ b/src/lib/net/Makefile
@@ -3,7 +3,7 @@
 # license that can be found in the LICENSE file.
 
 # DO NOT EDIT.  Automatically generated by gobuild.
-# gobuild -m dnsclient.go dnsconfig.go dnsmsg.go fd.go fd_${GOOS}.go ip.go net.go net_${GOOS}.go parse.go port.go >Makefile
+# gobuild -m dnsclient.go dnsconfig.go dnsmsg.go fd.go fd_${GOOS}.go ip.go net.go parse.go port.go >Makefile
 
 D=
 
@@ -51,7 +51,6 @@
 O3=\
 	dnsconfig.$O\
 	fd.$O\
-	net_$(GOOS).$O\
 
 O4=\
 	net.$O\
@@ -72,7 +71,7 @@
 	rm -f $(O2)
 
 a3: $(O3)
-	$(AR) grc _obj$D/net.a dnsconfig.$O fd.$O net_$(GOOS).$O
+	$(AR) grc _obj$D/net.a dnsconfig.$O fd.$O
 	rm -f $(O3)
 
 a4: $(O4)
diff --git a/src/lib/net/fd.go b/src/lib/net/fd.go
index ddfed67..9404ed0 100644
--- a/src/lib/net/fd.go
+++ b/src/lib/net/fd.go
@@ -17,7 +17,7 @@
 // Network file descriptor.
 type netFD struct {
 	// immutable until Close
-	fd int64;
+	fd int;
 	file *os.File;
 	cr chan *netFD;
 	cw chan *netFD;
@@ -37,28 +37,6 @@
 	ncr, ncw int;
 }
 
-// Make reads and writes on fd return EAGAIN instead of blocking.
-func setNonblock(fd int64) os.Error {
-	flags, e := syscall.Fcntl(fd, syscall.F_GETFL, 0);
-	if e != 0 {
-		return os.ErrnoToError(e)
-	}
-	flags, e = syscall.Fcntl(fd, syscall.F_SETFL, flags | syscall.O_NONBLOCK);
-	if e != 0 {
-		return os.ErrnoToError(e)
-	}
-	return nil
-}
-
-// Make reads/writes blocking; last gasp, so no error checking.
-func setBlock(fd int64) {
-	flags, e := syscall.Fcntl(fd, syscall.F_GETFL, 0);
-	if e != 0 {
-		return;
-	}
-	syscall.Fcntl(fd, syscall.F_SETFL, flags & ^syscall.O_NONBLOCK);
-}
-
 // A pollServer helps FDs determine when to retry a non-blocking
 // read or write after they get EAGAIN.  When an FD needs to wait,
 // send the fd on s.cr (for a read) or s.cw (for a write) to pass the
@@ -91,7 +69,7 @@
 type pollServer struct {
 	cr, cw chan *netFD;	// buffered >= 1
 	pr, pw *os.File;
-	pending map[int64] *netFD;
+	pending map[int] *netFD;
 	poll *pollster;	// low-level OS hooks
 	deadline int64;	// next deadline (nsec since 1970)
 }
@@ -104,23 +82,26 @@
 	if s.pr, s.pw, err = os.Pipe(); err != nil {
 		return nil, err
 	}
-	if err = setNonblock(s.pr.Fd()); err != nil {
+	var e int;
+	if e = syscall.SetNonblock(s.pr.Fd(), true); e != 0 {
+	Errno:
+		err = os.ErrnoToError(e);
 	Error:
 		s.pr.Close();
 		s.pw.Close();
-		return nil, err
+		return nil, err;
 	}
-	if err = setNonblock(s.pw.Fd()); err != nil {
-		goto Error
+	if e = syscall.SetNonblock(s.pw.Fd(), true); e != 0 {
+		goto Errno;
 	}
 	if s.poll, err = newpollster(); err != nil {
-		goto Error
+		goto Error;
 	}
 	if err = s.poll.AddFD(s.pr.Fd(), 'r', true); err != nil {
 		s.poll.Close();
 		goto Error
 	}
-	s.pending = make(map[int64] *netFD);
+	s.pending = make(map[int] *netFD);
 	go s.Run();
 	return s, nil
 }
@@ -168,7 +149,7 @@
 	}
 }
 
-func (s *pollServer) LookupFD(fd int64, mode int) *netFD {
+func (s *pollServer) LookupFD(fd int, mode int) *netFD {
 	key := fd << 1;
 	if mode == 'w' {
 		key++;
@@ -318,12 +299,12 @@
 	pollserver = p
 }
 
-func newFD(fd int64, net, laddr, raddr string) (f *netFD, err os.Error) {
+func newFD(fd int, net, laddr, raddr string) (f *netFD, err os.Error) {
 	if pollserver == nil {
 		once.Do(_StartServer);
 	}
-	if err = setNonblock(fd); err != nil {
-		return nil, err
+	if e := syscall.SetNonblock(fd, true); e != 0 {
+		return nil, os.ErrnoToError(e);
 	}
 	f = new(netFD);
 	f.fd = fd;
@@ -347,7 +328,7 @@
 	// we can handle the extra OS processes.
 	// Otherwise we'll need to use the pollserver
 	// for Close too.  Sigh.
-	setBlock(fd.file.Fd());
+	syscall.SetNonblock(fd.file.Fd(), false);
 
 	e := fd.file.Close();
 	fd.file = nil;
@@ -406,9 +387,9 @@
 	return nn, err
 }
 
-func sockaddrToHostPort(sa *syscall.Sockaddr) (hostport string, err os.Error)
+func sockaddrToString(sa syscall.Sockaddr) (name string, err os.Error)
 
-func (fd *netFD) Accept(sa *syscall.Sockaddr) (nfd *netFD, err os.Error) {
+func (fd *netFD) accept() (nfd *netFD, err os.Error) {
 	if fd == nil || fd.file == nil {
 		return nil, os.EINVAL
 	}
@@ -417,9 +398,10 @@
 	// It is okay to hold the lock across syscall.Accept
 	// because we have put fd.fd into non-blocking mode.
 	syscall.ForkLock.RLock();
-	var s, e int64;
+	var s, e int;
+	var sa syscall.Sockaddr;
 	for {
-		s, e = syscall.Accept(fd.fd, sa);
+		s, sa, e = syscall.Accept(fd.fd);
 		if e != syscall.EAGAIN {
 			break;
 		}
@@ -434,7 +416,7 @@
 	syscall.CloseOnExec(s);
 	syscall.ForkLock.RUnlock();
 
-	raddr, err1 := sockaddrToHostPort(sa);
+	raddr, err1 := sockaddrToString(sa);
 	if err1 != nil {
 		raddr = "invalid-address";
 	}
diff --git a/src/lib/net/fd_darwin.go b/src/lib/net/fd_darwin.go
index cfc873f..3d1025d 100644
--- a/src/lib/net/fd_darwin.go
+++ b/src/lib/net/fd_darwin.go
@@ -15,14 +15,14 @@
 var kqueuePhaseError = &Error{"kqueue phase error"}
 
 type pollster struct {
-	kq int64;
+	kq int;
 	eventbuf [10]syscall.Kevent_t;
 	events []syscall.Kevent_t;
 }
 
 func newpollster() (p *pollster, err os.Error) {
 	p = new(pollster);
-	var e int64;
+	var e int;
 	if p.kq, e = syscall.Kqueue(); e != 0 {
 		return nil, os.ErrnoToError(e)
 	}
@@ -30,7 +30,7 @@
 	return p, nil
 }
 
-func (p *pollster) AddFD(fd int64, mode int, repeat bool) os.Error {
+func (p *pollster) AddFD(fd int, mode int, repeat bool) os.Error {
 	var kmode int16;
 	if mode == 'r' {
 		kmode = syscall.EVFILT_READ
@@ -39,7 +39,7 @@
 	}
 	var events [1]syscall.Kevent_t;
 	ev := &events[0];
-	ev.Ident = fd;
+	ev.Ident = uint64(fd);
 	ev.Filter = kmode;
 
 	// EV_ADD - add event to kqueue list
@@ -55,16 +55,16 @@
 	if e != 0 {
 		return os.ErrnoToError(e)
 	}
-	if n != 1 || (ev.Flags & syscall.EV_ERROR) == 0 || ev.Ident != fd || ev.Filter != kmode {
+	if n != 1 || (ev.Flags & syscall.EV_ERROR) == 0 || ev.Ident != uint64(fd) || ev.Filter != kmode {
 		return kqueuePhaseError
 	}
 	if ev.Data != 0 {
-		return os.ErrnoToError(ev.Data)
+		return os.ErrnoToError(int(ev.Data))
 	}
 	return nil
 }
 
-func (p *pollster) DelFD(fd int64, mode int) {
+func (p *pollster) DelFD(fd int, mode int) {
 	var kmode int16;
 	if mode == 'r' {
 		kmode = syscall.EVFILT_READ
@@ -73,7 +73,7 @@
 	}
 	var events [1]syscall.Kevent_t;
 	ev := &events[0];
-	ev.Ident = fd;
+	ev.Ident = uint64(fd);
 	ev.Filter = kmode;
 
 	// EV_DELETE - delete event from kqueue list
@@ -83,7 +83,7 @@
 	syscall.Kevent(p.kq, &events, &events, nil);
 }
 
-func (p *pollster) WaitFD(nsec int64) (fd int64, mode int, err os.Error) {
+func (p *pollster) WaitFD(nsec int64) (fd int, mode int, err os.Error) {
 	var t *syscall.Timespec;
 	for len(p.events) == 0 {
 		if nsec > 0 {
@@ -91,7 +91,8 @@
 				t = new(syscall.Timespec);
 			}
 			t.Sec = nsec / 1e9;
-			t.Nsec = uint64(nsec % 1e9);
+			t.Nsec = int64(nsec % 1e9);
+//			*t = syscall.NsecToTimespec(nsec);
 		}
 		nn, e := syscall.Kevent(p.kq, nil, &p.eventbuf, t);
 		if e != 0 {
@@ -107,7 +108,7 @@
 	}
 	ev := &p.events[0];
 	p.events = p.events[1:len(p.events)];
-	fd = ev.Ident;
+	fd = int(ev.Ident);
 	if ev.Filter == syscall.EVFILT_READ {
 		mode = 'r'
 	} else {
@@ -117,6 +118,5 @@
 }
 
 func (p *pollster) Close() os.Error {
-	r, e := syscall.Close(p.kq);
-	return os.ErrnoToError(e)
+	return os.ErrnoToError(syscall.Close(p.kq))
 }
diff --git a/src/lib/net/fd_linux.go b/src/lib/net/fd_linux.go
index 78a1670..bd82258 100644
--- a/src/lib/net/fd_linux.go
+++ b/src/lib/net/fd_linux.go
@@ -18,27 +18,27 @@
 )
 
 type pollster struct {
-	epfd int64;
+	epfd int;
 
 	// Events we're already waiting for
-	events map[int64] uint32;
+	events map[int] uint32;
 }
 
 func newpollster() (p *pollster, err os.Error) {
 	p = new(pollster);
-	var e int64;
+	var e int;
 
 	// The arg to epoll_create is a hint to the kernel
 	// about the number of FDs we will care about.
 	// We don't know.
-	if p.epfd, e = syscall.Epoll_create(16); e != 0 {
+	if p.epfd, e = syscall.EpollCreate(16); e != 0 {
 		return nil, os.ErrnoToError(e)
 	}
-	p.events = make(map[int64] uint32);
+	p.events = make(map[int] uint32);
 	return p, nil
 }
 
-func (p *pollster) AddFD(fd int64, mode int, repeat bool) os.Error {
+func (p *pollster) AddFD(fd int, mode int, repeat bool) os.Error {
 	var ev syscall.EpollEvent;
 	var already bool;
 	ev.Fd = int32(fd);
@@ -52,20 +52,20 @@
 		ev.Events |= writeFlags;
 	}
 
-	var op int64;
+	var op int;
 	if already {
 		op = syscall.EPOLL_CTL_MOD;
 	} else {
 		op = syscall.EPOLL_CTL_ADD;
 	}
-	if e := syscall.Epoll_ctl(p.epfd, op, fd, &ev); e != 0 {
+	if e := syscall.EpollCtl(p.epfd, op, fd, &ev); e != 0 {
 		return os.ErrnoToError(e)
 	}
 	p.events[fd] = ev.Events;
 	return nil
 }
 
-func (p *pollster) StopWaiting(fd int64, bits uint) {
+func (p *pollster) StopWaiting(fd int, bits uint) {
 	events, already := p.events[fd];
 	if !already {
 		print("Epoll unexpected fd=", fd, "\n");
@@ -86,19 +86,19 @@
 		var ev syscall.EpollEvent;
 		ev.Fd = int32(fd);
 		ev.Events = events;
-		if e := syscall.Epoll_ctl(p.epfd, syscall.EPOLL_CTL_MOD, fd, &ev); e != 0 {
+		if e := syscall.EpollCtl(p.epfd, syscall.EPOLL_CTL_MOD, fd, &ev); e != 0 {
 			print("Epoll modify fd=", fd, ": ", os.ErrnoToError(e).String(), "\n");
 		}
 		p.events[fd] = events;
 	} else {
-		if e := syscall.Epoll_ctl(p.epfd, syscall.EPOLL_CTL_DEL, fd, nil); e != 0 {
+		if e := syscall.EpollCtl(p.epfd, syscall.EPOLL_CTL_DEL, fd, nil); e != 0 {
 			print("Epoll delete fd=", fd, ": ", os.ErrnoToError(e).String(), "\n");
 		}
 		p.events[fd] = 0, false;
 	}
 }
 
-func (p *pollster) DelFD(fd int64, mode int) {
+func (p *pollster) DelFD(fd int, mode int) {
 	if mode == 'r' {
 		p.StopWaiting(fd, readFlags);
 	} else {
@@ -106,17 +106,17 @@
 	}
 }
 
-func (p *pollster) WaitFD(nsec int64) (fd int64, mode int, err os.Error) {
+func (p *pollster) WaitFD(nsec int64) (fd int, mode int, err os.Error) {
 	// Get an event.
 	var evarray [1]syscall.EpollEvent;
 	ev := &evarray[0];
-	var msec int64 = -1;
+	var msec int = -1;
 	if nsec > 0 {
-		msec = (nsec + 1e6 - 1)/1e6;
+		msec = int((nsec + 1e6 - 1)/1e6);
 	}
-	n, e := syscall.Epoll_wait(p.epfd, &evarray, msec);
+	n, e := syscall.EpollWait(p.epfd, &evarray, msec);
 	for e == syscall.EAGAIN || e == syscall.EINTR {
-		n, e = syscall.Epoll_wait(p.epfd, &evarray, msec);
+		n, e = syscall.EpollWait(p.epfd, &evarray, msec);
 	}
 	if e != 0 {
 		return -1, 0, os.ErrnoToError(e);
@@ -124,7 +124,7 @@
 	if n == 0 {
 		return -1, 0, nil;
 	}
-	fd = int64(ev.Fd);
+	fd = int(ev.Fd);
 
 	if ev.Events & writeFlags != 0 {
 		p.StopWaiting(fd, writeFlags);
@@ -146,6 +146,5 @@
 }
 
 func (p *pollster) Close() os.Error {
-	r, e := syscall.Close(p.epfd);
-	return os.ErrnoToError(e);
+	return os.ErrnoToError(syscall.Close(p.epfd));
 }
diff --git a/src/lib/net/net.go b/src/lib/net/net.go
index d1000bf..5c442e6 100644
--- a/src/lib/net/net.go
+++ b/src/lib/net/net.go
@@ -113,6 +113,12 @@
 
 var preferIPv4 = !kernelSupportsIPv6()
 
+// TODO(rsc): if syscall.OS == "linux", we're supposd to read
+// /proc/sys/net/core/somaxconn,
+// to take advantage of kernels that have raised the limit.
+func listenBacklog() int {
+	return syscall.SOMAXCONN
+}
 
 func LookupHost(name string) (cname string, addrs []string, err os.Error)
 
@@ -212,20 +218,48 @@
 	return addr, p, nil
 }
 
-// Convert socket address into "host:port".
-func sockaddrToHostPort(sa *syscall.Sockaddr) (hostport string, err os.Error) {
-	switch sa.Family {
-	case syscall.AF_INET, syscall.AF_INET6:
-		addr, port, e := sockaddrToIP(sa);
-		if e != nil {
-			return "", e
-		}
-		host := addr.String();
-		return joinHostPort(host, strconv.Itoa(port)), nil;
-	default:
-		return "", UnknownSocketFamily
+func sockaddrToString(sa syscall.Sockaddr) (name string, err os.Error) {
+	switch a := sa.(type) {
+	case *syscall.SockaddrInet4:
+		return joinHostPort(IP(&a.Addr).String(), strconv.Itoa(a.Port)), nil;
+	case *syscall.SockaddrInet6:
+		return joinHostPort(IP(&a.Addr).String(), strconv.Itoa(a.Port)), nil;
+	case *syscall.SockaddrUnix:
+		return a.Name, nil;
 	}
-	return "", nil // not reached
+	return "", UnknownSocketFamily
+}
+
+func ipToSockaddr(family int, ip IP, port int) (syscall.Sockaddr, os.Error) {
+	switch family {
+	case syscall.AF_INET:
+		if ip = ip.To4(); ip == nil {
+			return nil, os.EINVAL
+		}
+		s := new(syscall.SockaddrInet4);
+		for i := 0; i < IPv4len; i++ {
+			s.Addr[i] = ip[i];
+		}
+		s.Port = port;
+		return s, nil;
+	case syscall.AF_INET6:
+		// IPv4 callers use 0.0.0.0 to mean "announce on any available address".
+		// In IPv6 mode, Linux treats that as meaning "announce on 0.0.0.0",
+		// which it refuses to do.  Rewrite to the IPv6 all zeros.
+		if p4 := ip.To4(); p4 != nil && p4[0] == 0 && p4[1] == 0 && p4[2] == 0 && p4[3] == 0 {
+			ip = IPzero;
+		}
+		if ip = ip.To16(); ip == nil {
+			return nil, os.EINVAL
+		}
+		s := new(syscall.SockaddrInet6);
+		for i := 0; i < IPv6len; i++ {
+			s.Addr[i] = ip[i];
+		}
+		s.Port = port;
+		return s, nil;
+	}
+	return nil, os.EINVAL;
 }
 
 // Boolean to int.
@@ -237,7 +271,7 @@
 }
 
 // Generic socket creation.
-func socket(net, laddr, raddr string, f, p, t int64, la, ra *syscall.Sockaddr) (fd *netFD, err os.Error) {
+func socket(net, laddr, raddr string, f, p, t int, la, ra syscall.Sockaddr) (fd *netFD, err os.Error) {
 	// See ../syscall/exec.go for description of ForkLock.
 	syscall.ForkLock.RLock();
 	s, e := syscall.Socket(f, p, t);
@@ -249,11 +283,11 @@
 	syscall.ForkLock.RUnlock();
 
 	// Allow reuse of recently-used addresses.
-	syscall.Setsockopt_int(s, syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1);
+	syscall.SetsockoptInt(s, syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1);
 
 	var r int64;
 	if la != nil {
-		r, e = syscall.Bind(s, la);
+		e = syscall.Bind(s, la);
 		if e != 0 {
 			syscall.Close(s);
 			return nil, os.ErrnoToError(e)
@@ -261,7 +295,7 @@
 	}
 
 	if ra != nil {
-		r, e = syscall.Connect(s, ra);
+		e = syscall.Connect(s, ra);
 		if e != 0 {
 			syscall.Close(s);
 			return nil, os.ErrnoToError(e)
@@ -291,7 +325,7 @@
 	return c.fd.file;
 }
 
-func (c *connBase) sysFD() int64 {
+func (c *connBase) sysFD() int {
 	if c == nil || c.fd == nil {
 		return -1;
 	}
@@ -335,20 +369,21 @@
 }
 
 
-func setsockopt_int(fd, level, opt int64, value int) os.Error {
-	return os.ErrnoToError(syscall.Setsockopt_int(fd, level, opt, value));
+func setsockoptInt(fd, level, opt int, value int) os.Error {
+	return os.ErrnoToError(syscall.SetsockoptInt(fd, level, opt, value));
 }
 
-func setsockopt_tv(fd, level, opt int64, nsec int64) os.Error {
-	return os.ErrnoToError(syscall.Setsockopt_tv(fd, level, opt, nsec));
+func setsockoptNsec(fd, level, opt int, nsec int64) os.Error {
+	var tv = syscall.NsecToTimeval(nsec);
+	return os.ErrnoToError(syscall.SetsockoptTimeval(fd, level, opt, &tv));
 }
 
 func (c *connBase) SetReadBuffer(bytes int) os.Error {
-	return setsockopt_int(c.sysFD(), syscall.SOL_SOCKET, syscall.SO_RCVBUF, bytes);
+	return setsockoptInt(c.sysFD(), syscall.SOL_SOCKET, syscall.SO_RCVBUF, bytes);
 }
 
 func (c *connBase) SetWriteBuffer(bytes int) os.Error {
-	return setsockopt_int(c.sysFD(), syscall.SOL_SOCKET, syscall.SO_SNDBUF, bytes);
+	return setsockoptInt(c.sysFD(), syscall.SOL_SOCKET, syscall.SO_SNDBUF, bytes);
 }
 
 func (c *connBase) SetReadTimeout(nsec int64) os.Error {
@@ -369,7 +404,7 @@
 }
 
 func (c *connBase) SetReuseAddr(reuse bool) os.Error {
-	return setsockopt_int(c.sysFD(), syscall.SOL_SOCKET, syscall.SO_REUSEADDR, boolint(reuse));
+	return setsockoptInt(c.sysFD(), syscall.SOL_SOCKET, syscall.SO_REUSEADDR, boolint(reuse));
 }
 
 func (c *connBase) BindToDevice(dev string) os.Error {
@@ -378,22 +413,30 @@
 }
 
 func (c *connBase) SetDontRoute(dontroute bool) os.Error {
-	return setsockopt_int(c.sysFD(), syscall.SOL_SOCKET, syscall.SO_DONTROUTE, boolint(dontroute));
+	return setsockoptInt(c.sysFD(), syscall.SOL_SOCKET, syscall.SO_DONTROUTE, boolint(dontroute));
 }
 
 func (c *connBase) SetKeepAlive(keepalive bool) os.Error {
-	return setsockopt_int(c.sysFD(), syscall.SOL_SOCKET, syscall.SO_KEEPALIVE, boolint(keepalive));
+	return setsockoptInt(c.sysFD(), syscall.SOL_SOCKET, syscall.SO_KEEPALIVE, boolint(keepalive));
 }
 
 func (c *connBase) SetLinger(sec int) os.Error {
-	e := syscall.Setsockopt_linger(c.sysFD(), syscall.SOL_SOCKET, syscall.SO_LINGER, sec);
+	var l syscall.Linger;
+	if sec >= 0 {
+		l.Onoff = 1;
+		l.Linger = int32(sec);
+	} else {
+		l.Onoff = 0;
+		l.Linger = 0;
+	}
+	e := syscall.SetsockoptLinger(c.sysFD(), syscall.SOL_SOCKET, syscall.SO_LINGER, &l);
 	return os.ErrnoToError(e);
 }
 
 
 // Internet sockets (TCP, UDP)
 
-func internetSocket(net, laddr, raddr string, proto int64, mode string) (fd *netFD, err os.Error) {
+func internetSocket(net, laddr, raddr string, proto int, mode string) (fd *netFD, err os.Error) {
 	// Parse addresses (unless they are empty).
 	var lip, rip IP;
 	var lport, rport int;
@@ -430,25 +473,22 @@
 		}
 	}
 
-	var cvt func(addr IP, port int) (sa *syscall.Sockaddr, err os.Error);
-	var family int64;
+	var family int;
 	if vers == 4 {
-		cvt = v4ToSockaddr;
 		family = syscall.AF_INET
 	} else {
-		cvt = v6ToSockaddr;
 		family = syscall.AF_INET6
 	}
 
-	var la, ra *syscall.Sockaddr;
+	var la, ra syscall.Sockaddr;
 	if lip != nil {
-		la, lerr = cvt(lip, lport);
+		la, lerr = ipToSockaddr(family, lip, lport);
 		if lerr != nil {
 			return nil, lerr
 		}
 	}
 	if rip != nil {
-		ra, rerr = cvt(rip, rport);
+		ra, rerr = ipToSockaddr(family, rip, rport);
 		if rerr != nil {
 			return nil, rerr
 		}
@@ -471,7 +511,7 @@
 	if c == nil {
 		return os.EINVAL
 	}
-	return setsockopt_int(c.sysFD(), syscall.IPPROTO_TCP, syscall.TCP_NODELAY, boolint(nodelay))
+	return setsockoptInt(c.sysFD(), syscall.IPPROTO_TCP, syscall.TCP_NODELAY, boolint(nodelay))
 }
 
 func newConnTCP(fd *netFD, raddr string) *ConnTCP {
@@ -535,7 +575,7 @@
 // Unix domain sockets
 
 func unixSocket(net, laddr, raddr string, mode string) (fd *netFD, err os.Error) {
-	var proto int64;
+	var proto int;
 	switch net {
 	default:
 		return nil, UnknownNetwork;
@@ -545,7 +585,7 @@
 		proto = syscall.SOCK_DGRAM;
 	}
 
-	var la, ra *syscall.Sockaddr;
+	var la, ra syscall.Sockaddr;
 	switch mode {
 	case "dial":
 		if laddr != "" {
@@ -554,19 +594,13 @@
 		if raddr == "" {
 			return nil, MissingAddress;
 		}
-		ra, err = unixToSockaddr(raddr);
-		if err != nil {
-			return nil, err;
-		}
+		ra = &syscall.SockaddrUnix{Name: raddr};
 
 	case "listen":
 		if laddr == "" {
 			return nil, MissingAddress;
 		}
-		la, err = unixToSockaddr(laddr);
-		if err != nil {
-			return nil, err;
-		}
+		la = &syscall.SockaddrUnix{Name: laddr};
 		if raddr != "" {
 			return nil, BadAddress;
 		}
@@ -636,7 +670,7 @@
 		}
 		fd = fd1;
 	}
-	r, e1 := syscall.Listen(fd.fd, 8); // listenBacklog());
+	e1 := syscall.Listen(fd.fd, 8); // listenBacklog());
 	if e1 != 0 {
 		syscall.Close(fd.fd);
 		return nil, os.ErrnoToError(e1);
@@ -650,17 +684,11 @@
 	if l == nil || l.fd == nil || l.fd.fd < 0 {
 		return nil, "", os.EINVAL
 	}
-	var sa syscall.Sockaddr;
-	fd, e := l.fd.Accept(&sa);
+	fd, e := l.fd.accept();
 	if e != nil {
 		return nil, "", e
 	}
-	raddr, err = sockaddrToUnix(&sa);
-	if err != nil {
-		fd.Close();
-		return nil, "", err
-	}
-	return newConnUnix(fd, raddr), raddr, nil
+	return newConnUnix(fd, fd.raddr), raddr, nil
 }
 
 // Accept implements the Accept method in the Listener interface;
@@ -765,7 +793,7 @@
 	if e != nil {
 		return nil, e
 	}
-	r, e1 := syscall.Listen(fd.fd, listenBacklog());
+	e1 := syscall.Listen(fd.fd, listenBacklog());
 	if e1 != 0 {
 		syscall.Close(fd.fd);
 		return nil, os.ErrnoToError(e1)
@@ -781,17 +809,11 @@
 	if l == nil || l.fd == nil || l.fd.fd < 0 {
 		return nil, "", os.EINVAL
 	}
-	var sa syscall.Sockaddr;
-	fd, e := l.fd.Accept(&sa);
+	fd, e := l.fd.accept();
 	if e != nil {
 		return nil, "", e
 	}
-	raddr, err = sockaddrToHostPort(&sa);
-	if err != nil {
-		fd.Close();
-		return nil, "", err
-	}
-	return newConnTCP(fd, raddr), raddr, nil
+	return newConnTCP(fd, fd.raddr), fd.raddr, nil
 }
 
 // Accept implements the Accept method in the Listener interface;
diff --git a/src/lib/net/net_darwin.go b/src/lib/net/net_darwin.go
deleted file mode 100644
index 50e19d6..0000000
--- a/src/lib/net/net_darwin.go
+++ /dev/null
@@ -1,100 +0,0 @@
-// Copyright 2009 The Go Authors.  All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package net
-
-import (
-	"net";
-	"os";
-	"syscall";
-	"unsafe";
-)
-
-func v4ToSockaddr(p IP, port int) (sa1 *syscall.Sockaddr, err os.Error) {
-	p = p.To4();
-	if p == nil || port < 0 || port > 0xFFFF {
-		return nil, os.EINVAL
-	}
-	sa := new(syscall.SockaddrInet4);
-	sa.Len = syscall.SizeofSockaddrInet4;
-	sa.Family = syscall.AF_INET;
-	sa.Port[0] = byte(port>>8);
-	sa.Port[1] = byte(port);
-	for i := 0; i < IPv4len; i++ {
-		sa.Addr[i] = p[i]
-	}
-	return (*syscall.Sockaddr)(unsafe.Pointer(sa)), nil
-}
-
-func v6ToSockaddr(p IP, port int) (sa1 *syscall.Sockaddr, err os.Error) {
-	p = p.To16();
-	if p == nil || port < 0 || port > 0xFFFF {
-		return nil, os.EINVAL
-	}
-	sa := new(syscall.SockaddrInet6);
-	sa.Len = syscall.SizeofSockaddrInet6;
-	sa.Family = syscall.AF_INET6;
-	sa.Port[0] = byte(port>>8);
-	sa.Port[1] = byte(port);
-	for i := 0; i < IPv6len; i++ {
-		sa.Addr[i] = p[i]
-	}
-	return (*syscall.Sockaddr)(unsafe.Pointer(sa)), nil
-}
-
-func sockaddrToIP(sa1 *syscall.Sockaddr) (p IP, port int, err os.Error) {
-	switch sa1.Family {
-	case syscall.AF_INET:
-		sa := (*syscall.SockaddrInet4)(unsafe.Pointer(sa1));
-		a := IP(&sa.Addr).To16();
-		if a == nil {
-			return nil, 0, os.EINVAL
-		}
-		return a, int(sa.Port[0])<<8 + int(sa.Port[1]), nil;
-	case syscall.AF_INET6:
-		sa := (*syscall.SockaddrInet6)(unsafe.Pointer(sa1));
-		a := IP(&sa.Addr).To16();
-		if a == nil {
-			return nil, 0, os.EINVAL
-		}
-		return nil, int(sa.Port[0])<<8 + int(sa.Port[1]), nil;
-	default:
-		return nil, 0, os.EINVAL
-	}
-	return nil, 0, nil	// not reached
-}
-
-func listenBacklog() int64 {
-	return syscall.SOMAXCONN
-}
-
-func unixToSockaddr(name string) (sa1 *syscall.Sockaddr, err os.Error) {
-	sa := new(syscall.SockaddrUnix);
-	n := len(name);
-	if n >= len(sa.Path) || n == 0 {
-		return nil, os.EINVAL;
-	}
-	sa.Len = byte(3 + n);	// 2 for Family, Len; 1 for NUL
-	sa.Family = syscall.AF_UNIX;
-	for i := 0; i < len(name); i++ {
-		sa.Path[i] = name[i];
-	}
-	return (*syscall.Sockaddr)(unsafe.Pointer(sa)), nil;
-}
-
-func sockaddrToUnix(sa1 *syscall.Sockaddr) (string, os.Error) {
-	if sa1.Family != syscall.AF_UNIX || sa1.Len < 3 || sa1.Len > syscall.SizeofSockaddrUnix {
-		return "", os.EINVAL;
-	}
-	sa := (*syscall.SockaddrUnix)(unsafe.Pointer(sa1));
-	n := int(sa.Len) - 3;	// subtract leading Family, Len, terminating NUL
-	for i := 0; i < n; i++ {
-		if sa.Path[i] == 0 {
-			// found early NUL; assume Len is overestimating
-			n = i;
-			break;
-		}
-	}
-	return string(sa.Path[0:n]), nil;
-}
diff --git a/src/lib/net/net_linux.go b/src/lib/net/net_linux.go
deleted file mode 100644
index 4127867..0000000
--- a/src/lib/net/net_linux.go
+++ /dev/null
@@ -1,124 +0,0 @@
-// Copyright 2009 The Go Authors.  All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package net
-
-import (
-	"net";
-	"os";
-	"syscall";
-	"unsafe";
-)
-
-func v4ToSockaddr(p IP, port int) (sa1 *syscall.Sockaddr, err os.Error) {
-	p = p.To4();
-	if p == nil || port < 0 || port > 0xFFFF {
-		return nil, os.EINVAL
-	}
-	sa := new(syscall.SockaddrInet4);
-	sa.Family = syscall.AF_INET;
-	sa.Port[0] = byte(port>>8);
-	sa.Port[1] = byte(port);
-	for i := 0; i < IPv4len; i++ {
-		sa.Addr[i] = p[i]
-	}
-	return (*syscall.Sockaddr)(unsafe.Pointer(sa)), nil
-}
-
-func v6ToSockaddr(p IP, port int) (sa1 *syscall.Sockaddr, err os.Error) {
-	p = p.To16();
-	if p == nil || port < 0 || port > 0xFFFF {
-		return nil, os.EINVAL
-	}
-
-	// IPv4 callers use 0.0.0.0 to mean "announce on any available address".
-	// In IPv6 mode, Linux treats that as meaning "announce on 0.0.0.0",
-	// which it refuses to do.  Rewrite to the IPv6 all zeros.
-	if p4 := p.To4(); p4 != nil && p4[0] == 0 && p4[1] == 0 && p4[2] == 0 && p4[3] == 0 {
-		p = IPzero;
-	}
-
-	sa := new(syscall.SockaddrInet6);
-	sa.Family = syscall.AF_INET6;
-	sa.Port[0] = byte(port>>8);
-	sa.Port[1] = byte(port);
-	for i := 0; i < IPv6len; i++ {
-		sa.Addr[i] = p[i]
-	}
-	return (*syscall.Sockaddr)(unsafe.Pointer(sa)), nil
-}
-
-func sockaddrToIP(sa1 *syscall.Sockaddr) (p IP, port int, err os.Error) {
-	switch sa1.Family {
-	case syscall.AF_INET:
-		sa := (*syscall.SockaddrInet4)(unsafe.Pointer(sa1));
-		a := IP(&sa.Addr).To16();
-		if a == nil {
-			return nil, 0, os.EINVAL
-		}
-		return a, int(sa.Port[0])<<8 + int(sa.Port[1]), nil;
-	case syscall.AF_INET6:
-		sa := (*syscall.SockaddrInet6)(unsafe.Pointer(sa1));
-		a := IP(&sa.Addr).To16();
-		if a == nil {
-			return nil, 0, os.EINVAL
-		}
-		return a, int(sa.Port[0])<<8 + int(sa.Port[1]), nil;
-	default:
-		return nil, 0, os.EINVAL
-	}
-	return nil, 0, nil	// not reached
-}
-
-func listenBacklog() int64 {
-	// TODO: Read the limit from /proc/sys/net/core/somaxconn,
-	// to take advantage of kernels that have raised the limit.
-	return syscall.SOMAXCONN
-}
-
-func unixToSockaddr(name string) (sa1 *syscall.Sockaddr, err os.Error) {
-	sa := new(syscall.SockaddrUnix);
-	n := len(name);
-	if n >= len(sa.Path) || n == 0 {
-		return nil, os.EINVAL;
-	}
-	sa.Family = syscall.AF_UNIX;
-	for i := 0; i < len(name); i++ {
-		sa.Path[i] = name[i];
-	}
-
-	// Special case: @ in first position indicates
-	// an abstract socket, which has no file system
-	// representation and starts with a NUL byte
-	// when talking to the kernel about it.
-	if sa.Path[0] == '@' {
-		sa.Path[0] = 0;
-	}
-	sa.Length = 1 + int64(n) + 1;	// family, name, \0
-
-	return (*syscall.Sockaddr)(unsafe.Pointer(sa)), nil;
-}
-
-func sockaddrToUnix(sa1 *syscall.Sockaddr) (string, os.Error) {
-	if sa1.Family != syscall.AF_UNIX {
-		return "", os.EINVAL;
-	}
-
-	sa := (*syscall.SockaddrUnix)(unsafe.Pointer(sa1));
-
-	// @ special case (see comment in unixToSockaddr).
-	if sa.Path[0] == 0 {
-		// Not friendly to overwrite in place but
-		// okay in an internal function.
-		// The caller doesn't care if we do.
-		sa.Path[0] = '@';
-	}
-
-	// count length of path
-	n := 0;
-	for n < len(sa.Path) && sa.Path[n] != 0 {
-		n++;
-	}
-	return string(sa.Path[0:n]), nil;
-}
diff --git a/src/lib/net/timeout_test.go b/src/lib/net/timeout_test.go
index 8ad4f54..e08ce88 100644
--- a/src/lib/net/timeout_test.go
+++ b/src/lib/net/timeout_test.go
@@ -30,7 +30,7 @@
 	}
 }
 
-func TestTmeoutUDP(t *testing.T) {
+func TestTimeoutUDP(t *testing.T) {
 	testTimeout(t, "udp", "127.0.0.1:53");
 }