]> Cypherpunks repositories - gostls13.git/commitdiff
syscall: add sockaddr_ll support for linux/386, linux/amd64
authorMikio Hara <mikioh.mikioh@gmail.com>
Tue, 12 Oct 2010 13:48:56 +0000 (09:48 -0400)
committerRuss Cox <rsc@golang.org>
Tue, 12 Oct 2010 13:48:56 +0000 (09:48 -0400)
R=rsc, albert.strasheim
CC=golang-dev
https://golang.org/cl/2356042

src/pkg/syscall/mkerrors.sh
src/pkg/syscall/syscall_linux.go
src/pkg/syscall/types_linux.c [changed mode: 0755->0644]
src/pkg/syscall/zerrors_linux_386.go
src/pkg/syscall/zerrors_linux_amd64.go
src/pkg/syscall/ztypes_linux_386.go
src/pkg/syscall/ztypes_linux_amd64.go

index 48274b9808215a8e4cb811b8087448736f4f34ea..a402da6a025bdf8c0c73c8ae28b941c7a27bb69a 100755 (executable)
@@ -26,6 +26,7 @@ includes_Linux='
 #include <sys/inotify.h>
 #include <linux/ptrace.h>
 #include <linux/wait.h>
+#include <netpacket/packet.h>
 '
 
 includes_Darwin='
@@ -86,7 +87,7 @@ done
                $2 ~ /^E[A-Z0-9_]+$/ ||
                $2 ~ /^SIG[^_]/ ||
                $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 == "NAME_MAX" ||
                $2 ~ /^(O|F|FD|NAME|S|PTRACE)_/ ||
index 19c9cc3d90fd34f461556426099a26b4c5157940..e97574d50a407169aee839c807e4b1b23bf4689c 100644 (file)
@@ -261,8 +261,47 @@ func (sa *SockaddrUnix) sockaddr() (uintptr, _Socklen, int) {
        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) {
        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:
                pp := (*RawSockaddrUnix)(unsafe.Pointer(rsa))
                sa := new(SockaddrUnix)
old mode 100755 (executable)
new mode 100644 (file)
index 7489bc9..4752e31
@@ -15,6 +15,7 @@ Input to godefs.  See also mkerrors.sh and mkall.sh
 #include <fcntl.h>
 #include <netinet/in.h>
 #include <netinet/tcp.h>
+#include <netpacket/packet.h>
 #include <signal.h>
 #include <stdio.h>
 #include <sys/epoll.h>
@@ -91,6 +92,7 @@ union sockaddr_all {
        struct sockaddr_in s2;  // these pad it out
        struct sockaddr_in6 s3;
        struct sockaddr_un s4;
+       struct sockaddr_ll s5;
 };
 
 struct sockaddr_any {
@@ -101,6 +103,7 @@ struct sockaddr_any {
 typedef struct sockaddr_in $RawSockaddrInet4;
 typedef struct sockaddr_in6 $RawSockaddrInet6;
 typedef struct sockaddr_un $RawSockaddrUnix;
+typedef struct sockaddr_ll $RawSockaddrLinklayer;
 typedef struct sockaddr $RawSockaddr;
 typedef struct sockaddr_any $RawSockaddrAny;
 typedef socklen_t $_Socklen;
@@ -115,6 +118,7 @@ enum {
        $SizeofSockaddrInet6 = sizeof(struct sockaddr_in6),
        $SizeofSockaddrAny = sizeof(struct sockaddr_any),
        $SizeofSockaddrUnix = sizeof(struct sockaddr_un),
+       $SizeofSockaddrLinklayer = sizeof(struct sockaddr_ll),
        $SizeofLinger = sizeof(struct linger),
        $SizeofMsghdr = sizeof(struct msghdr),
        $SizeofCmsghdr = sizeof(struct cmsghdr),
@@ -126,7 +130,7 @@ enum {
 typedef struct inotify_event $InotifyEvent;
 
 enum {
-        $SizeofInotifyEvent = sizeof(struct inotify_event)
+       $SizeofInotifyEvent = sizeof(struct inotify_event)
 };
 
 
index b4bb19ba700713047c356967a291c3e4b58e60d3..13b5d6b365068230550e54a5e88dcd596bc441c1 100644 (file)
@@ -408,6 +408,21 @@ const (
        O_SYNC                           = 0x1000
        O_TRUNC                          = 0x200
        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_BTS_CLEAR                 = 0x2c
        PTRACE_BTS_CONFIG                = 0x28
index 1893c51bffebd61e3da2b18774f268b64f70925f..af7f924ff5e9cd9e1fc2a623a8b4a92dae32bdb2 100644 (file)
@@ -408,6 +408,21 @@ const (
        O_SYNC                           = 0x1000
        O_TRUNC                          = 0x200
        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_ATTACH                    = 0x10
        PTRACE_BTS_CLEAR                 = 0x2c
index 99ce60819c8b58be44e9ff03350d5a358b42fc19..0603168aa50d8c2347b386a96356fe9482ba0b89 100644 (file)
@@ -6,21 +6,22 @@ package syscall
 
 // Constants
 const (
-       sizeofPtr           = 0x4
-       sizeofShort         = 0x2
-       sizeofInt           = 0x4
-       sizeofLong          = 0x4
-       sizeofLongLong      = 0x8
-       PathMax             = 0x1000
-       SizeofSockaddrInet4 = 0x10
-       SizeofSockaddrInet6 = 0x1c
-       SizeofSockaddrAny   = 0x70
-       SizeofSockaddrUnix  = 0x6e
-       SizeofLinger        = 0x8
-       SizeofMsghdr        = 0x1c
-       SizeofCmsghdr       = 0xc
-       SizeofUcred         = 0xc
-       SizeofInotifyEvent  = 0x10
+       sizeofPtr               = 0x4
+       sizeofShort             = 0x2
+       sizeofInt               = 0x4
+       sizeofLong              = 0x4
+       sizeofLongLong          = 0x8
+       PathMax                 = 0x1000
+       SizeofSockaddrInet4     = 0x10
+       SizeofSockaddrInet6     = 0x1c
+       SizeofSockaddrAny       = 0x70
+       SizeofSockaddrUnix      = 0x6e
+       SizeofSockaddrLinklayer = 0x14
+       SizeofLinger            = 0x8
+       SizeofMsghdr            = 0x1c
+       SizeofCmsghdr           = 0xc
+       SizeofUcred             = 0xc
+       SizeofInotifyEvent      = 0x10
 )
 
 // Types
@@ -181,6 +182,16 @@ type RawSockaddrUnix struct {
        Path   [108]int8
 }
 
+type RawSockaddrLinklayer struct {
+       Family   uint16
+       Protocol uint16
+       Ifindex  int32
+       Hatype   uint16
+       Pkttype  uint8
+       Halen    uint8
+       Addr     [8]uint8
+}
+
 type RawSockaddr struct {
        Family uint16
        Data   [14]int8
index 3883a58aa0686f49cacd1263372cae2bae88729a..b975a8732052030d675b902c030a5f1d1bb246d6 100644 (file)
@@ -6,21 +6,22 @@ package syscall
 
 // Constants
 const (
-       sizeofPtr           = 0x8
-       sizeofShort         = 0x2
-       sizeofInt           = 0x4
-       sizeofLong          = 0x8
-       sizeofLongLong      = 0x8
-       PathMax             = 0x1000
-       SizeofSockaddrInet4 = 0x10
-       SizeofSockaddrInet6 = 0x1c
-       SizeofSockaddrAny   = 0x70
-       SizeofSockaddrUnix  = 0x6e
-       SizeofLinger        = 0x8
-       SizeofMsghdr        = 0x38
-       SizeofCmsghdr       = 0x10
-       SizeofUcred         = 0xc
-       SizeofInotifyEvent  = 0x10
+       sizeofPtr               = 0x8
+       sizeofShort             = 0x2
+       sizeofInt               = 0x4
+       sizeofLong              = 0x8
+       sizeofLongLong          = 0x8
+       PathMax                 = 0x1000
+       SizeofSockaddrInet4     = 0x10
+       SizeofSockaddrInet6     = 0x1c
+       SizeofSockaddrAny       = 0x70
+       SizeofSockaddrUnix      = 0x6e
+       SizeofSockaddrLinklayer = 0x14
+       SizeofLinger            = 0x8
+       SizeofMsghdr            = 0x38
+       SizeofCmsghdr           = 0x10
+       SizeofUcred             = 0xc
+       SizeofInotifyEvent      = 0x10
 )
 
 // Types
@@ -181,6 +182,16 @@ type RawSockaddrUnix struct {
        Path   [108]int8
 }
 
+type RawSockaddrLinklayer struct {
+       Family   uint16
+       Protocol uint16
+       Ifindex  int32
+       Hatype   uint16
+       Pkttype  uint8
+       Halen    uint8
+       Addr     [8]uint8
+}
+
 type RawSockaddr struct {
        Family uint16
        Data   [14]int8