mirror of
https://github.com/golang/go
synced 2024-11-25 08:07:57 -07:00
syscall: add sockaddr_ll support for linux/386, linux/amd64
R=rsc, albert.strasheim CC=golang-dev https://golang.org/cl/2356042
This commit is contained in:
parent
d3a2118b8a
commit
b390c4b9d6
@ -26,6 +26,7 @@ includes_Linux='
|
|||||||
#include <sys/inotify.h>
|
#include <sys/inotify.h>
|
||||||
#include <linux/ptrace.h>
|
#include <linux/ptrace.h>
|
||||||
#include <linux/wait.h>
|
#include <linux/wait.h>
|
||||||
|
#include <netpacket/packet.h>
|
||||||
'
|
'
|
||||||
|
|
||||||
includes_Darwin='
|
includes_Darwin='
|
||||||
@ -86,7 +87,7 @@ done
|
|||||||
$2 ~ /^E[A-Z0-9_]+$/ ||
|
$2 ~ /^E[A-Z0-9_]+$/ ||
|
||||||
$2 ~ /^SIG[^_]/ ||
|
$2 ~ /^SIG[^_]/ ||
|
||||||
$2 ~ /^IN_/ ||
|
$2 ~ /^IN_/ ||
|
||||||
$2 ~ /^(AF|SOCK|SO|SOL|IPPROTO|IP|IPV6|TCP|EVFILT|EV|SHUT|PROT|MAP)_/ ||
|
$2 ~ /^(AF|SOCK|SO|SOL|IPPROTO|IP|IPV6|TCP|EVFILT|EV|SHUT|PROT|MAP|PACKET)_/ ||
|
||||||
$2 == "SOMAXCONN" ||
|
$2 == "SOMAXCONN" ||
|
||||||
$2 == "NAME_MAX" ||
|
$2 == "NAME_MAX" ||
|
||||||
$2 ~ /^(O|F|FD|NAME|S|PTRACE)_/ ||
|
$2 ~ /^(O|F|FD|NAME|S|PTRACE)_/ ||
|
||||||
|
@ -261,8 +261,47 @@ func (sa *SockaddrUnix) sockaddr() (uintptr, _Socklen, int) {
|
|||||||
return uintptr(unsafe.Pointer(&sa.raw)), 1 + _Socklen(n) + 1, 0
|
return uintptr(unsafe.Pointer(&sa.raw)), 1 + _Socklen(n) + 1, 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type SockaddrLinklayer struct {
|
||||||
|
Protocol uint16
|
||||||
|
Ifindex int
|
||||||
|
Hatype uint16
|
||||||
|
Pkttype uint8
|
||||||
|
Halen uint8
|
||||||
|
Addr [8]byte
|
||||||
|
raw RawSockaddrLinklayer
|
||||||
|
}
|
||||||
|
|
||||||
|
func (sa *SockaddrLinklayer) sockaddr() (uintptr, _Socklen, int) {
|
||||||
|
if sa.Ifindex < 0 || sa.Ifindex > 0x7fffffff {
|
||||||
|
return 0, 0, EINVAL
|
||||||
|
}
|
||||||
|
sa.raw.Family = AF_PACKET
|
||||||
|
sa.raw.Protocol = sa.Protocol
|
||||||
|
sa.raw.Ifindex = int32(sa.Ifindex)
|
||||||
|
sa.raw.Hatype = sa.Hatype
|
||||||
|
sa.raw.Pkttype = sa.Pkttype
|
||||||
|
sa.raw.Halen = sa.Halen
|
||||||
|
for i := 0; i < len(sa.Addr); i++ {
|
||||||
|
sa.raw.Addr[i] = sa.Addr[i]
|
||||||
|
}
|
||||||
|
return uintptr(unsafe.Pointer(&sa.raw)), SizeofSockaddrLinklayer, 0
|
||||||
|
}
|
||||||
|
|
||||||
func anyToSockaddr(rsa *RawSockaddrAny) (Sockaddr, int) {
|
func anyToSockaddr(rsa *RawSockaddrAny) (Sockaddr, int) {
|
||||||
switch rsa.Addr.Family {
|
switch rsa.Addr.Family {
|
||||||
|
case AF_PACKET:
|
||||||
|
pp := (*RawSockaddrLinklayer)(unsafe.Pointer(rsa))
|
||||||
|
sa := new(SockaddrLinklayer)
|
||||||
|
sa.Protocol = pp.Protocol
|
||||||
|
sa.Ifindex = int(pp.Ifindex)
|
||||||
|
sa.Hatype = pp.Hatype
|
||||||
|
sa.Pkttype = pp.Pkttype
|
||||||
|
sa.Halen = pp.Halen
|
||||||
|
for i := 0; i < len(sa.Addr); i++ {
|
||||||
|
sa.Addr[i] = pp.Addr[i]
|
||||||
|
}
|
||||||
|
return sa, 0
|
||||||
|
|
||||||
case AF_UNIX:
|
case AF_UNIX:
|
||||||
pp := (*RawSockaddrUnix)(unsafe.Pointer(rsa))
|
pp := (*RawSockaddrUnix)(unsafe.Pointer(rsa))
|
||||||
sa := new(SockaddrUnix)
|
sa := new(SockaddrUnix)
|
||||||
|
6
src/pkg/syscall/types_linux.c
Executable file → Normal file
6
src/pkg/syscall/types_linux.c
Executable file → Normal file
@ -15,6 +15,7 @@ Input to godefs. See also mkerrors.sh and mkall.sh
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <netinet/tcp.h>
|
#include <netinet/tcp.h>
|
||||||
|
#include <netpacket/packet.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/epoll.h>
|
#include <sys/epoll.h>
|
||||||
@ -91,6 +92,7 @@ union sockaddr_all {
|
|||||||
struct sockaddr_in s2; // these pad it out
|
struct sockaddr_in s2; // these pad it out
|
||||||
struct sockaddr_in6 s3;
|
struct sockaddr_in6 s3;
|
||||||
struct sockaddr_un s4;
|
struct sockaddr_un s4;
|
||||||
|
struct sockaddr_ll s5;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct sockaddr_any {
|
struct sockaddr_any {
|
||||||
@ -101,6 +103,7 @@ struct sockaddr_any {
|
|||||||
typedef struct sockaddr_in $RawSockaddrInet4;
|
typedef struct sockaddr_in $RawSockaddrInet4;
|
||||||
typedef struct sockaddr_in6 $RawSockaddrInet6;
|
typedef struct sockaddr_in6 $RawSockaddrInet6;
|
||||||
typedef struct sockaddr_un $RawSockaddrUnix;
|
typedef struct sockaddr_un $RawSockaddrUnix;
|
||||||
|
typedef struct sockaddr_ll $RawSockaddrLinklayer;
|
||||||
typedef struct sockaddr $RawSockaddr;
|
typedef struct sockaddr $RawSockaddr;
|
||||||
typedef struct sockaddr_any $RawSockaddrAny;
|
typedef struct sockaddr_any $RawSockaddrAny;
|
||||||
typedef socklen_t $_Socklen;
|
typedef socklen_t $_Socklen;
|
||||||
@ -115,6 +118,7 @@ enum {
|
|||||||
$SizeofSockaddrInet6 = sizeof(struct sockaddr_in6),
|
$SizeofSockaddrInet6 = sizeof(struct sockaddr_in6),
|
||||||
$SizeofSockaddrAny = sizeof(struct sockaddr_any),
|
$SizeofSockaddrAny = sizeof(struct sockaddr_any),
|
||||||
$SizeofSockaddrUnix = sizeof(struct sockaddr_un),
|
$SizeofSockaddrUnix = sizeof(struct sockaddr_un),
|
||||||
|
$SizeofSockaddrLinklayer = sizeof(struct sockaddr_ll),
|
||||||
$SizeofLinger = sizeof(struct linger),
|
$SizeofLinger = sizeof(struct linger),
|
||||||
$SizeofMsghdr = sizeof(struct msghdr),
|
$SizeofMsghdr = sizeof(struct msghdr),
|
||||||
$SizeofCmsghdr = sizeof(struct cmsghdr),
|
$SizeofCmsghdr = sizeof(struct cmsghdr),
|
||||||
@ -126,7 +130,7 @@ enum {
|
|||||||
typedef struct inotify_event $InotifyEvent;
|
typedef struct inotify_event $InotifyEvent;
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
$SizeofInotifyEvent = sizeof(struct inotify_event)
|
$SizeofInotifyEvent = sizeof(struct inotify_event)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -408,6 +408,21 @@ const (
|
|||||||
O_SYNC = 0x1000
|
O_SYNC = 0x1000
|
||||||
O_TRUNC = 0x200
|
O_TRUNC = 0x200
|
||||||
O_WRONLY = 0x1
|
O_WRONLY = 0x1
|
||||||
|
PACKET_ADD_MEMBERSHIP = 0x1
|
||||||
|
PACKET_BROADCAST = 0x1
|
||||||
|
PACKET_DROP_MEMBERSHIP = 0x2
|
||||||
|
PACKET_FASTROUTE = 0x6
|
||||||
|
PACKET_HOST = 0
|
||||||
|
PACKET_LOOPBACK = 0x5
|
||||||
|
PACKET_MR_ALLMULTI = 0x2
|
||||||
|
PACKET_MR_MULTICAST = 0
|
||||||
|
PACKET_MR_PROMISC = 0x1
|
||||||
|
PACKET_MULTICAST = 0x2
|
||||||
|
PACKET_OTHERHOST = 0x3
|
||||||
|
PACKET_OUTGOING = 0x4
|
||||||
|
PACKET_RECV_OUTPUT = 0x3
|
||||||
|
PACKET_RX_RING = 0x5
|
||||||
|
PACKET_STATISTICS = 0x6
|
||||||
PTRACE_ATTACH = 0x10
|
PTRACE_ATTACH = 0x10
|
||||||
PTRACE_BTS_CLEAR = 0x2c
|
PTRACE_BTS_CLEAR = 0x2c
|
||||||
PTRACE_BTS_CONFIG = 0x28
|
PTRACE_BTS_CONFIG = 0x28
|
||||||
|
@ -408,6 +408,21 @@ const (
|
|||||||
O_SYNC = 0x1000
|
O_SYNC = 0x1000
|
||||||
O_TRUNC = 0x200
|
O_TRUNC = 0x200
|
||||||
O_WRONLY = 0x1
|
O_WRONLY = 0x1
|
||||||
|
PACKET_ADD_MEMBERSHIP = 0x1
|
||||||
|
PACKET_BROADCAST = 0x1
|
||||||
|
PACKET_DROP_MEMBERSHIP = 0x2
|
||||||
|
PACKET_FASTROUTE = 0x6
|
||||||
|
PACKET_HOST = 0
|
||||||
|
PACKET_LOOPBACK = 0x5
|
||||||
|
PACKET_MR_ALLMULTI = 0x2
|
||||||
|
PACKET_MR_MULTICAST = 0
|
||||||
|
PACKET_MR_PROMISC = 0x1
|
||||||
|
PACKET_MULTICAST = 0x2
|
||||||
|
PACKET_OTHERHOST = 0x3
|
||||||
|
PACKET_OUTGOING = 0x4
|
||||||
|
PACKET_RECV_OUTPUT = 0x3
|
||||||
|
PACKET_RX_RING = 0x5
|
||||||
|
PACKET_STATISTICS = 0x6
|
||||||
PTRACE_ARCH_PRCTL = 0x1e
|
PTRACE_ARCH_PRCTL = 0x1e
|
||||||
PTRACE_ATTACH = 0x10
|
PTRACE_ATTACH = 0x10
|
||||||
PTRACE_BTS_CLEAR = 0x2c
|
PTRACE_BTS_CLEAR = 0x2c
|
||||||
|
@ -6,21 +6,22 @@ package syscall
|
|||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
const (
|
const (
|
||||||
sizeofPtr = 0x4
|
sizeofPtr = 0x4
|
||||||
sizeofShort = 0x2
|
sizeofShort = 0x2
|
||||||
sizeofInt = 0x4
|
sizeofInt = 0x4
|
||||||
sizeofLong = 0x4
|
sizeofLong = 0x4
|
||||||
sizeofLongLong = 0x8
|
sizeofLongLong = 0x8
|
||||||
PathMax = 0x1000
|
PathMax = 0x1000
|
||||||
SizeofSockaddrInet4 = 0x10
|
SizeofSockaddrInet4 = 0x10
|
||||||
SizeofSockaddrInet6 = 0x1c
|
SizeofSockaddrInet6 = 0x1c
|
||||||
SizeofSockaddrAny = 0x70
|
SizeofSockaddrAny = 0x70
|
||||||
SizeofSockaddrUnix = 0x6e
|
SizeofSockaddrUnix = 0x6e
|
||||||
SizeofLinger = 0x8
|
SizeofSockaddrLinklayer = 0x14
|
||||||
SizeofMsghdr = 0x1c
|
SizeofLinger = 0x8
|
||||||
SizeofCmsghdr = 0xc
|
SizeofMsghdr = 0x1c
|
||||||
SizeofUcred = 0xc
|
SizeofCmsghdr = 0xc
|
||||||
SizeofInotifyEvent = 0x10
|
SizeofUcred = 0xc
|
||||||
|
SizeofInotifyEvent = 0x10
|
||||||
)
|
)
|
||||||
|
|
||||||
// Types
|
// Types
|
||||||
@ -181,6 +182,16 @@ type RawSockaddrUnix struct {
|
|||||||
Path [108]int8
|
Path [108]int8
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type RawSockaddrLinklayer struct {
|
||||||
|
Family uint16
|
||||||
|
Protocol uint16
|
||||||
|
Ifindex int32
|
||||||
|
Hatype uint16
|
||||||
|
Pkttype uint8
|
||||||
|
Halen uint8
|
||||||
|
Addr [8]uint8
|
||||||
|
}
|
||||||
|
|
||||||
type RawSockaddr struct {
|
type RawSockaddr struct {
|
||||||
Family uint16
|
Family uint16
|
||||||
Data [14]int8
|
Data [14]int8
|
||||||
|
@ -6,21 +6,22 @@ package syscall
|
|||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
const (
|
const (
|
||||||
sizeofPtr = 0x8
|
sizeofPtr = 0x8
|
||||||
sizeofShort = 0x2
|
sizeofShort = 0x2
|
||||||
sizeofInt = 0x4
|
sizeofInt = 0x4
|
||||||
sizeofLong = 0x8
|
sizeofLong = 0x8
|
||||||
sizeofLongLong = 0x8
|
sizeofLongLong = 0x8
|
||||||
PathMax = 0x1000
|
PathMax = 0x1000
|
||||||
SizeofSockaddrInet4 = 0x10
|
SizeofSockaddrInet4 = 0x10
|
||||||
SizeofSockaddrInet6 = 0x1c
|
SizeofSockaddrInet6 = 0x1c
|
||||||
SizeofSockaddrAny = 0x70
|
SizeofSockaddrAny = 0x70
|
||||||
SizeofSockaddrUnix = 0x6e
|
SizeofSockaddrUnix = 0x6e
|
||||||
SizeofLinger = 0x8
|
SizeofSockaddrLinklayer = 0x14
|
||||||
SizeofMsghdr = 0x38
|
SizeofLinger = 0x8
|
||||||
SizeofCmsghdr = 0x10
|
SizeofMsghdr = 0x38
|
||||||
SizeofUcred = 0xc
|
SizeofCmsghdr = 0x10
|
||||||
SizeofInotifyEvent = 0x10
|
SizeofUcred = 0xc
|
||||||
|
SizeofInotifyEvent = 0x10
|
||||||
)
|
)
|
||||||
|
|
||||||
// Types
|
// Types
|
||||||
@ -181,6 +182,16 @@ type RawSockaddrUnix struct {
|
|||||||
Path [108]int8
|
Path [108]int8
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type RawSockaddrLinklayer struct {
|
||||||
|
Family uint16
|
||||||
|
Protocol uint16
|
||||||
|
Ifindex int32
|
||||||
|
Hatype uint16
|
||||||
|
Pkttype uint8
|
||||||
|
Halen uint8
|
||||||
|
Addr [8]uint8
|
||||||
|
}
|
||||||
|
|
||||||
type RawSockaddr struct {
|
type RawSockaddr struct {
|
||||||
Family uint16
|
Family uint16
|
||||||
Data [14]int8
|
Data [14]int8
|
||||||
|
Loading…
Reference in New Issue
Block a user