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 {
|
if n > 0 {
|
||||||
sl += Socklen_t(n) + 1
|
sl += Socklen_t(n) + 1
|
||||||
}
|
}
|
||||||
if sa.raw.Path[0] == '@' {
|
sl = sa.raw.adjustAbstract(sl)
|
||||||
sa.raw.Path[0] = 0
|
|
||||||
// Don't count trailing NUL for abstract address.
|
|
||||||
sl--
|
|
||||||
}
|
|
||||||
|
|
||||||
// length is family (uint16), name, NUL.
|
// length is family (uint16), name, NUL.
|
||||||
return (*RawSockaddrAny)(unsafe.Pointer(&sa.raw)), sl, nil
|
return (*RawSockaddrAny)(unsafe.Pointer(&sa.raw)), sl, nil
|
||||||
|
@ -11,11 +11,11 @@ const SizeofSockaddrInet6 = 28
|
|||||||
const SizeofSockaddrUnix = 110
|
const SizeofSockaddrUnix = 110
|
||||||
|
|
||||||
type RawSockaddrInet4 struct {
|
type RawSockaddrInet4 struct {
|
||||||
Len uint8;
|
Len uint8
|
||||||
Family uint8;
|
Family uint8
|
||||||
Port uint16;
|
Port uint16
|
||||||
Addr [4]byte /* in_addr */;
|
Addr [4]byte /* in_addr */
|
||||||
Zero [8]uint8;
|
Zero [8]uint8
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sa *RawSockaddrInet4) setLen() Socklen_t {
|
func (sa *RawSockaddrInet4) setLen() Socklen_t {
|
||||||
@ -24,12 +24,12 @@ func (sa *RawSockaddrInet4) setLen() Socklen_t {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type RawSockaddrInet6 struct {
|
type RawSockaddrInet6 struct {
|
||||||
Len uint8;
|
Len uint8
|
||||||
Family uint8;
|
Family uint8
|
||||||
Port uint16;
|
Port uint16
|
||||||
Flowinfo uint32;
|
Flowinfo uint32
|
||||||
Addr [16]byte /* in6_addr */;
|
Addr [16]byte /* in6_addr */
|
||||||
Scope_id uint32;
|
Scope_id uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sa *RawSockaddrInet6) setLen() Socklen_t {
|
func (sa *RawSockaddrInet6) setLen() Socklen_t {
|
||||||
@ -38,9 +38,9 @@ func (sa *RawSockaddrInet6) setLen() Socklen_t {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type RawSockaddrUnix struct {
|
type RawSockaddrUnix struct {
|
||||||
Len uint8;
|
Len uint8
|
||||||
Family uint8;
|
Family uint8
|
||||||
Path [108]int8;
|
Path [108]int8
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sa *RawSockaddrUnix) setLen(n int) {
|
func (sa *RawSockaddrUnix) setLen(n int) {
|
||||||
@ -62,10 +62,14 @@ func (sa *RawSockaddrUnix) getLen() (int, error) {
|
|||||||
return n, nil
|
return n, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (sa *RawSockaddrUnix) adjustAbstract(sl Socklen_t) Socklen_t {
|
||||||
|
return sl
|
||||||
|
}
|
||||||
|
|
||||||
type RawSockaddr struct {
|
type RawSockaddr struct {
|
||||||
Len uint8;
|
Len uint8
|
||||||
Family uint8;
|
Family uint8
|
||||||
Data [14]int8;
|
Data [14]int8
|
||||||
}
|
}
|
||||||
|
|
||||||
// BindToDevice binds the socket associated with fd to device.
|
// BindToDevice binds the socket associated with fd to device.
|
||||||
|
@ -64,6 +64,10 @@ func (sa *RawSockaddrUnix) getLen() (int, error) {
|
|||||||
return n, nil
|
return n, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (sa *RawSockaddrUnix) adjustAbstract(sl Socklen_t) Socklen_t {
|
||||||
|
return sl
|
||||||
|
}
|
||||||
|
|
||||||
type RawSockaddr struct {
|
type RawSockaddr struct {
|
||||||
Family uint16
|
Family uint16
|
||||||
Data [14]int8
|
Data [14]int8
|
||||||
|
@ -110,6 +110,15 @@ func (sa *RawSockaddrUnix) getLen() (int, error) {
|
|||||||
return n, nil
|
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 {
|
type RawSockaddrLinklayer struct {
|
||||||
Family uint16
|
Family uint16
|
||||||
Protocol uint16
|
Protocol uint16
|
||||||
|
@ -12,9 +12,9 @@ const SizeofSockaddrUnix = 110
|
|||||||
|
|
||||||
type RawSockaddrInet4 struct {
|
type RawSockaddrInet4 struct {
|
||||||
Family uint16
|
Family uint16
|
||||||
Port uint16
|
Port uint16
|
||||||
Addr [4]byte /* in_addr */
|
Addr [4]byte /* in_addr */
|
||||||
Zero [8]uint8
|
Zero [8]uint8
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sa *RawSockaddrInet4) setLen() Socklen_t {
|
func (sa *RawSockaddrInet4) setLen() Socklen_t {
|
||||||
@ -22,12 +22,12 @@ func (sa *RawSockaddrInet4) setLen() Socklen_t {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type RawSockaddrInet6 struct {
|
type RawSockaddrInet6 struct {
|
||||||
Family uint16
|
Family uint16
|
||||||
Port uint16
|
Port uint16
|
||||||
Flowinfo uint32
|
Flowinfo uint32
|
||||||
Addr [16]byte /* in6_addr */
|
Addr [16]byte /* in6_addr */
|
||||||
Scope_id uint32
|
Scope_id uint32
|
||||||
Src_id uint32
|
Src_id uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sa *RawSockaddrInet6) setLen() Socklen_t {
|
func (sa *RawSockaddrInet6) setLen() Socklen_t {
|
||||||
@ -36,38 +36,27 @@ func (sa *RawSockaddrInet6) setLen() Socklen_t {
|
|||||||
|
|
||||||
type RawSockaddrUnix struct {
|
type RawSockaddrUnix struct {
|
||||||
Family uint16
|
Family uint16
|
||||||
Path [108]int8
|
Path [108]int8
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sa *RawSockaddrUnix) setLen(int) {
|
func (sa *RawSockaddrUnix) setLen(int) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sa *RawSockaddrUnix) getLen() (int, error) {
|
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
|
n := 0
|
||||||
for n < len(sa.Path) - 3 && sa.Path[n] != 0 {
|
for n < len(sa.Path) && sa.Path[n] != 0 {
|
||||||
n++
|
n++
|
||||||
}
|
}
|
||||||
|
|
||||||
return n, nil
|
return n, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (sa *RawSockaddrUnix) adjustAbstract(sl Socklen_t) Socklen_t {
|
||||||
|
return sl
|
||||||
|
}
|
||||||
|
|
||||||
type RawSockaddr struct {
|
type RawSockaddr struct {
|
||||||
Family uint16
|
Family uint16
|
||||||
Data [14]int8
|
Data [14]int8
|
||||||
}
|
}
|
||||||
|
|
||||||
// BindToDevice binds the socket associated with fd to device.
|
// BindToDevice binds the socket associated with fd to device.
|
||||||
|
Loading…
Reference in New Issue
Block a user