diff options
| author | Rob Pike <r@golang.org> | 2009-06-19 16:03:59 -0700 |
|---|---|---|
| committer | Rob Pike <r@golang.org> | 2009-06-19 16:03:59 -0700 |
| commit | efc4088ccd5434f1536f46e7fdab48e2fc3565ed (patch) | |
| tree | a837b88e0c0ee62103e26060e6c4bec98e0d7dec /src | |
| parent | 7f3eb2738f4e2e372fc43e72b28be0685381e7f4 (diff) | |
| download | go-efc4088ccd5434f1536f46e7fdab48e2fc3565ed.tar.xz | |
make IP address available
R=rsc
DELTA=30 (30 added, 0 deleted, 0 changed)
OCL=30536
CL=30536
Diffstat (limited to 'src')
| -rw-r--r-- | src/pkg/net/fd.go | 10 | ||||
| -rw-r--r-- | src/pkg/net/net.go | 20 |
2 files changed, 30 insertions, 0 deletions
diff --git a/src/pkg/net/fd.go b/src/pkg/net/fd.go index befcd554fe..17598af466 100644 --- a/src/pkg/net/fd.go +++ b/src/pkg/net/fd.go @@ -436,3 +436,13 @@ func (fd *netFD) addr() string { addr, err1 := sockaddrToString(sa); return addr; } + +func (fd *netFD) remoteAddr() string { + sa, err := syscall.Getpeername(fd.fd); + if err != 0 { + return ""; + } + // TODO(rsc): woud like to say err not err1 but 6g complains + addr, err1 := sockaddrToString(sa); + return addr; +} diff --git a/src/pkg/net/net.go b/src/pkg/net/net.go index 8d7e7ba328..91d498a3da 100644 --- a/src/pkg/net/net.go +++ b/src/pkg/net/net.go @@ -33,6 +33,12 @@ type Conn interface { // Close closes the connection. Close() os.Error; + // LocalAddr returns the local network address. + LocalAddr() string; + + // RemoteAddr returns the remote network address. + RemoteAddr() string; + // For packet-based protocols such as UDP, // ReadFrom reads the next packet from the network, // returning the number of bytes read and the remote @@ -318,6 +324,20 @@ type connBase struct { raddr string; } +func (c *connBase) LocalAddr() string { + if c == nil { + return "" + } + return c.fd.addr(); +} + +func (c *connBase) RemoteAddr() string { + if c == nil { + return "" + } + return c.fd.remoteAddr(); +} + func (c *connBase) File() *os.File { if c == nil { return nil |
