mirror of
https://github.com/golang/go.git
synced 2025-05-16 21:04:38 +00:00
make IP address available
R=rsc DELTA=30 (30 added, 0 deleted, 0 changed) OCL=30536 CL=30536
This commit is contained in:
parent
7f3eb2738f
commit
efc4088ccd
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user