]> Cypherpunks repositories - gostls13.git/commitdiff
make IP address available
authorRob Pike <r@golang.org>
Fri, 19 Jun 2009 23:03:59 +0000 (16:03 -0700)
committerRob Pike <r@golang.org>
Fri, 19 Jun 2009 23:03:59 +0000 (16:03 -0700)
R=rsc
DELTA=30  (30 added, 0 deleted, 0 changed)
OCL=30536
CL=30536

src/pkg/net/fd.go
src/pkg/net/net.go

index befcd554fe7f3f681a97617c30cb761d0526d320..17598af4663312d9da9499a686201ea4b3d434c5 100644 (file)
@@ -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;
+}
index 8d7e7ba3285fa879a822d38fbcea7af29bdfa573..91d498a3da68fcf53499ae09f4a7883d3b4154e1 100644 (file)
@@ -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