net: Only use GNU/Linux unix socket abstract paths on GNU/Linux.
From-SVN: r201217
This commit is contained in:
parent
821f6f1b31
commit
f735ce315f
@ -92,11 +92,7 @@ func (sa *SockaddrUnix) sockaddr() (*RawSockaddrAny, Socklen_t, error) {
|
||||
if n > 0 {
|
||||
sl += Socklen_t(n) + 1
|
||||
}
|
||||
if sa.raw.Path[0] == '@' {
|
||||
sa.raw.Path[0] = 0
|
||||
// Don't count trailing NUL for abstract address.
|
||||
sl--
|
||||
}
|
||||
sl = sa.raw.adjustAbstract(sl)
|
||||
|
||||
// length is family (uint16), name, NUL.
|
||||
return (*RawSockaddrAny)(unsafe.Pointer(&sa.raw)), sl, nil
|
||||
|
@ -11,11 +11,11 @@ const SizeofSockaddrInet6 = 28
|
||||
const SizeofSockaddrUnix = 110
|
||||
|
||||
type RawSockaddrInet4 struct {
|
||||
Len uint8;
|
||||
Family uint8;
|
||||
Port uint16;
|
||||
Addr [4]byte /* in_addr */;
|
||||
Zero [8]uint8;
|
||||
Len uint8
|
||||
Family uint8
|
||||
Port uint16
|
||||
Addr [4]byte /* in_addr */
|
||||
Zero [8]uint8
|
||||
}
|
||||
|
||||
func (sa *RawSockaddrInet4) setLen() Socklen_t {
|
||||
@ -24,12 +24,12 @@ func (sa *RawSockaddrInet4) setLen() Socklen_t {
|
||||
}
|
||||
|
||||
type RawSockaddrInet6 struct {
|
||||
Len uint8;
|
||||
Family uint8;
|
||||
Port uint16;
|
||||
Flowinfo uint32;
|
||||
Addr [16]byte /* in6_addr */;
|
||||
Scope_id uint32;
|
||||
Len uint8
|
||||
Family uint8
|
||||
Port uint16
|
||||
Flowinfo uint32
|
||||
Addr [16]byte /* in6_addr */
|
||||
Scope_id uint32
|
||||
}
|
||||
|
||||
func (sa *RawSockaddrInet6) setLen() Socklen_t {
|
||||
@ -38,9 +38,9 @@ func (sa *RawSockaddrInet6) setLen() Socklen_t {
|
||||
}
|
||||
|
||||
type RawSockaddrUnix struct {
|
||||
Len uint8;
|
||||
Family uint8;
|
||||
Path [108]int8;
|
||||
Len uint8
|
||||
Family uint8
|
||||
Path [108]int8
|
||||
}
|
||||
|
||||
func (sa *RawSockaddrUnix) setLen(n int) {
|
||||
@ -62,10 +62,14 @@ func (sa *RawSockaddrUnix) getLen() (int, error) {
|
||||
return n, nil
|
||||
}
|
||||
|
||||
func (sa *RawSockaddrUnix) adjustAbstract(sl Socklen_t) Socklen_t {
|
||||
return sl
|
||||
}
|
||||
|
||||
type RawSockaddr struct {
|
||||
Len uint8;
|
||||
Family uint8;
|
||||
Data [14]int8;
|
||||
Len uint8
|
||||
Family uint8
|
||||
Data [14]int8
|
||||
}
|
||||
|
||||
// BindToDevice binds the socket associated with fd to device.
|
||||
|
@ -64,6 +64,10 @@ func (sa *RawSockaddrUnix) getLen() (int, error) {
|
||||
return n, nil
|
||||
}
|
||||
|
||||
func (sa *RawSockaddrUnix) adjustAbstract(sl Socklen_t) Socklen_t {
|
||||
return sl
|
||||
}
|
||||
|
||||
type RawSockaddr struct {
|
||||
Family uint16
|
||||
Data [14]int8
|
||||
|
@ -110,6 +110,15 @@ func (sa *RawSockaddrUnix) getLen() (int, error) {
|
||||
return n, nil
|
||||
}
|
||||
|
||||
func (sa *RawSockaddrUnix) adjustAbstract(sl Socklen_t) Socklen_t {
|
||||
if sa.Path[0] == '@' {
|
||||
sa.Path[0] = 0
|
||||
// Don't count trailing NUL for abstract address.
|
||||
sl--
|
||||
}
|
||||
return sl
|
||||
}
|
||||
|
||||
type RawSockaddrLinklayer struct {
|
||||
Family uint16
|
||||
Protocol uint16
|
||||
|
@ -43,28 +43,17 @@ func (sa *RawSockaddrUnix) setLen(int) {
|
||||
}
|
||||
|
||||
func (sa *RawSockaddrUnix) getLen() (int, error) {
|
||||
if sa.Path[0] == 0 {
|
||||
// "Abstract" Unix domain socket.
|
||||
// Rewrite leading NUL as @ for textual display.
|
||||
// (This is the standard convention.)
|
||||
// Not friendly to overwrite in place,
|
||||
// but the callers below don't care.
|
||||
sa.Path[0] = '@'
|
||||
}
|
||||
|
||||
// Assume path ends at NUL.
|
||||
// This is not technically the GNU/Linux semantics for
|
||||
// abstract Unix domain sockets--they are supposed
|
||||
// to be uninterpreted fixed-size binary blobs--but
|
||||
// everyone uses this convention.
|
||||
n := 0
|
||||
for n < len(sa.Path) - 3 && sa.Path[n] != 0 {
|
||||
for n < len(sa.Path) && sa.Path[n] != 0 {
|
||||
n++
|
||||
}
|
||||
|
||||
return n, nil
|
||||
}
|
||||
|
||||
func (sa *RawSockaddrUnix) adjustAbstract(sl Socklen_t) Socklen_t {
|
||||
return sl
|
||||
}
|
||||
|
||||
type RawSockaddr struct {
|
||||
Family uint16
|
||||
Data [14]int8
|
||||
|
Loading…
Reference in New Issue
Block a user