1
0
mirror of https://github.com/golang/go synced 2024-11-21 20:14:52 -07:00

net, syscall: update IP multicast socket options for darwin, freebsd, linux

Add IPv6Mreq and Inet6Pktinfo for specifying the network interface.
Rename IpMreq to IPMreq, SetsockoptIpMreq to SetsockoptIPMreq.

R=rsc, dave, robert.hencke
CC=golang-dev
https://golang.org/cl/4532098
This commit is contained in:
Mikio Hara 2011-06-02 10:10:17 -04:00 committed by Russ Cox
parent 9995d216eb
commit d1bdff5448
14 changed files with 148 additions and 51 deletions

View File

@ -293,10 +293,10 @@ func (c *UDPConn) JoinGroup(addr IP) os.Error {
if ip == nil {
return &OpError{"joingroup", "udp", &IPAddr{ip}, errInvalidMulticast}
}
mreq := &syscall.IpMreq{
mreq := &syscall.IPMreq{
Multiaddr: [4]byte{ip[0], ip[1], ip[2], ip[3]},
}
err := os.NewSyscallError("setsockopt", syscall.SetsockoptIpMreq(c.fd.sysfd, syscall.IPPROTO_IP, syscall.IP_ADD_MEMBERSHIP, mreq))
err := os.NewSyscallError("setsockopt", syscall.SetsockoptIPMreq(c.fd.sysfd, syscall.IPPROTO_IP, syscall.IP_ADD_MEMBERSHIP, mreq))
if err != nil {
return &OpError{"joingroup", "udp", &IPAddr{ip}, err}
}
@ -312,10 +312,10 @@ func (c *UDPConn) LeaveGroup(addr IP) os.Error {
if ip == nil {
return &OpError{"leavegroup", "udp", &IPAddr{ip}, errInvalidMulticast}
}
mreq := &syscall.IpMreq{
mreq := &syscall.IPMreq{
Multiaddr: [4]byte{ip[0], ip[1], ip[2], ip[3]},
}
err := os.NewSyscallError("setsockopt", syscall.SetsockoptIpMreq(c.fd.sysfd, syscall.IPPROTO_IP, syscall.IP_DROP_MEMBERSHIP, mreq))
err := os.NewSyscallError("setsockopt", syscall.SetsockoptIPMreq(c.fd.sysfd, syscall.IPPROTO_IP, syscall.IP_DROP_MEMBERSHIP, mreq))
if err != nil {
return &OpError{"leavegroup", "udp", &IPAddr{ip}, err}
}

View File

@ -22,7 +22,6 @@ const ImplementsGetwd = false
func Getwd() (string, int) { return "", ENOTSUP }
/*
* Wrapped
*/
@ -392,7 +391,11 @@ func SetsockoptLinger(fd, level, opt int, l *Linger) (errno int) {
return setsockopt(fd, level, opt, uintptr(unsafe.Pointer(l)), unsafe.Sizeof(*l))
}
func SetsockoptIpMreq(fd, level, opt int, mreq *IpMreq) (errno int) {
func SetsockoptIPMreq(fd, level, opt int, mreq *IPMreq) (errno int) {
return setsockopt(fd, level, opt, uintptr(unsafe.Pointer(mreq)), unsafe.Sizeof(*mreq))
}
func SetsockoptIPv6Mreq(fd, level, opt int, mreq *IPv6Mreq) (errno int) {
return setsockopt(fd, level, opt, uintptr(unsafe.Pointer(mreq)), unsafe.Sizeof(*mreq))
}

View File

@ -463,7 +463,11 @@ func SetsockoptLinger(fd, level, opt int, l *Linger) (errno int) {
return setsockopt(fd, level, opt, uintptr(unsafe.Pointer(l)), unsafe.Sizeof(*l))
}
func SetsockoptIpMreq(fd, level, opt int, mreq *IpMreq) (errno int) {
func SetsockoptIPMreq(fd, level, opt int, mreq *IPMreq) (errno int) {
return setsockopt(fd, level, opt, uintptr(unsafe.Pointer(mreq)), unsafe.Sizeof(*mreq))
}
func SetsockoptIPv6Mreq(fd, level, opt int, mreq *IPv6Mreq) (errno int) {
return setsockopt(fd, level, opt, uintptr(unsafe.Pointer(mreq)), unsafe.Sizeof(*mreq))
}

View File

@ -680,13 +680,19 @@ const (
IP_DROP_MEMBERSHIP
)
type IpMreq struct {
type IPMreq struct {
Multiaddr [4]byte /* in_addr */
Interface [4]byte /* in_addr */
}
type IPv6Mreq struct {
Multiaddr [16]byte /* in6_addr */
Interface uint32
}
func SetsockoptLinger(fd, level, opt int, l *Linger) (errno int) { return EWINDOWS }
func SetsockoptIpMreq(fd, level, opt int, mreq *IpMreq) (errno int) { return EWINDOWS }
func SetsockoptIPMreq(fd, level, opt int, mreq *IPMreq) (errno int) { return EWINDOWS }
func SetsockoptIPv6Mreq(fd, level, opt int, mreq *IPv6Mreq) (errno int) { return EWINDOWS }
func BindToDevice(fd int, device string) (errno int) { return EWINDOWS }
// TODO(brainman): fix all needed for os

View File

@ -39,8 +39,7 @@ Input to godefs. See also mkerrors.sh and mkall.sh
// Machine characteristics; for internal use.
enum
{
enum {
$sizeofPtr = sizeof(void*),
$sizeofShort = sizeof(short),
$sizeofInt = sizeof(int),
@ -48,7 +47,6 @@ enum
$sizeofLongLong = sizeof(long long),
};
// Basic types
typedef short $_C_short;
@ -71,8 +69,7 @@ typedef gid_t $_Gid_t;
// Files
enum
{
enum {
$O_CLOEXEC = 0, // not supported
};
@ -86,8 +83,6 @@ typedef struct log2phys $Log2phys_t;
typedef struct dirent $Dirent;
// Wait status.
// Sockets
union sockaddr_all {
@ -112,9 +107,11 @@ typedef struct sockaddr_any $RawSockaddrAny;
typedef socklen_t $_Socklen;
typedef struct linger $Linger;
typedef struct iovec $Iovec;
typedef struct ip_mreq $IpMreq;
typedef struct ip_mreq $IPMreq;
typedef struct ipv6_mreq $IPv6Mreq;
typedef struct msghdr $Msghdr;
typedef struct cmsghdr $Cmsghdr;
typedef struct in6_pktinfo $Inet6Pktinfo;
enum {
$SizeofSockaddrInet4 = sizeof(struct sockaddr_in),
@ -123,19 +120,21 @@ enum {
$SizeofSockaddrUnix = sizeof(struct sockaddr_un),
$SizeofSockaddrDatalink = sizeof(struct sockaddr_dl),
$SizeofLinger = sizeof(struct linger),
$SizeofIpMreq = sizeof(struct ip_mreq),
$SizeofIPMreq = sizeof(struct ip_mreq),
$SizeofIPv6Mreq = sizeof(struct ipv6_mreq),
$SizeofMsghdr = sizeof(struct msghdr),
$SizeofCmsghdr = sizeof(struct cmsghdr),
$SizeofInet6Pktinfo = sizeof(struct in6_pktinfo),
};
// Ptrace requests
enum {
$PTRACE_TRACEME = PT_TRACE_ME,
$PTRACE_CONT = PT_CONTINUE,
$PTRACE_KILL = PT_KILL,
};
// Events (kqueue, kevent)
typedef struct kevent $Kevent_t;

View File

@ -35,8 +35,7 @@ Input to godefs. See also mkerrors.sh and mkall.sh
// Machine characteristics; for internal use.
enum
{
enum {
$sizeofPtr = sizeof(void*),
$sizeofShort = sizeof(short),
$sizeofInt = sizeof(int),
@ -44,7 +43,6 @@ enum
$sizeofLongLong = sizeof(long long),
};
// Basic types
typedef short $_C_short;
@ -66,13 +64,11 @@ typedef gid_t $_Gid_t;
// Files
enum
{
enum {
$O_CLOEXEC = 0, // not supported
};
enum
{ // Directory mode bits
enum { // Directory mode bits
$S_IFMT = S_IFMT,
$S_IFIFO = S_IFIFO,
$S_IFCHR = S_IFCHR,
@ -95,8 +91,6 @@ typedef struct flock $Flock_t;
typedef struct dirent $Dirent;
// Wait status.
// Sockets
union sockaddr_all {
@ -121,9 +115,11 @@ typedef struct sockaddr_any $RawSockaddrAny;
typedef socklen_t $_Socklen;
typedef struct linger $Linger;
typedef struct iovec $Iovec;
typedef struct ip_mreq $IpMreq;
typedef struct ip_mreq $IPMreq;
typedef struct ipv6_mreq $IPv6Mreq;
typedef struct msghdr $Msghdr;
typedef struct cmsghdr $Cmsghdr;
typedef struct in6_pktinfo $Inet6Pktinfo;
enum {
$SizeofSockaddrInet4 = sizeof(struct sockaddr_in),
@ -132,19 +128,21 @@ enum {
$SizeofSockaddrUnix = sizeof(struct sockaddr_un),
$SizeofSockaddrDatalink = sizeof(struct sockaddr_dl),
$SizeofLinger = sizeof(struct linger),
$SizeofIpMreq = sizeof(struct ip_mreq),
$SizeofIPMreq = sizeof(struct ip_mreq),
$SizeofIPv6Mreq = sizeof(struct ipv6_mreq),
$SizeofMsghdr = sizeof(struct msghdr),
$SizeofCmsghdr = sizeof(struct cmsghdr),
$SizeofInet6Pktinfo = sizeof(struct in6_pktinfo),
};
// Ptrace requests
enum {
$PTRACE_TRACEME = PT_TRACE_ME,
$PTRACE_CONT = PT_CONTINUE,
$PTRACE_KILL = PT_KILL,
};
// Events (kqueue, kevent)
typedef struct kevent $Kevent_t;

View File

@ -47,8 +47,7 @@ Input to godefs. See also mkerrors.sh and mkall.sh
// Machine characteristics; for internal use.
enum
{
enum {
$sizeofPtr = sizeof(void*),
$sizeofShort = sizeof(short),
$sizeofInt = sizeof(int),
@ -113,9 +112,11 @@ typedef struct sockaddr_any $RawSockaddrAny;
typedef socklen_t $_Socklen;
typedef struct linger $Linger;
typedef struct iovec $Iovec;
typedef struct ip_mreq $IpMreq;
typedef struct ip_mreq $IPMreq;
typedef struct ipv6_mreq $IPv6Mreq;
typedef struct msghdr $Msghdr;
typedef struct cmsghdr $Cmsghdr;
typedef struct in6_pktinfo $Inet6Pktinfo;
typedef struct ucred $Ucred;
enum {
@ -126,9 +127,11 @@ enum {
$SizeofSockaddrLinklayer = sizeof(struct sockaddr_ll),
$SizeofSockaddrNetlink = sizeof(struct sockaddr_nl),
$SizeofLinger = sizeof(struct linger),
$SizeofIpMreq = sizeof(struct ip_mreq),
$SizeofIPMreq = sizeof(struct ip_mreq),
$SizeofIPv6Mreq = sizeof(struct ipv6_mreq),
$SizeofMsghdr = sizeof(struct msghdr),
$SizeofCmsghdr = sizeof(struct cmsghdr),
$SizeofInet6Pktinfo = sizeof(struct in6_pktinfo),
$SizeofUcred = sizeof(struct ucred),
};

View File

@ -22,9 +22,11 @@ const (
SizeofSockaddrUnix = 0x6a
SizeofSockaddrDatalink = 0x14
SizeofLinger = 0x8
SizeofIpMreq = 0x8
SizeofIPMreq = 0x8
SizeofIPv6Mreq = 0x14
SizeofMsghdr = 0x1c
SizeofCmsghdr = 0xc
SizeofInet6Pktinfo = 0x14
PTRACE_TRACEME = 0
PTRACE_CONT = 0x7
PTRACE_KILL = 0x8
@ -226,11 +228,16 @@ type Iovec struct {
Len uint32
}
type IpMreq struct {
type IPMreq struct {
Multiaddr [4]byte /* in_addr */
Interface [4]byte /* in_addr */
}
type IPv6Mreq struct {
Multiaddr [16]byte /* in6_addr */
Interface uint32
}
type Msghdr struct {
Name *byte
Namelen uint32
@ -247,6 +254,11 @@ type Cmsghdr struct {
Type int32
}
type Inet6Pktinfo struct {
Addr [16]byte /* in6_addr */
Ifindex uint32
}
type Kevent_t struct {
Ident uint32
Filter int16

View File

@ -22,9 +22,11 @@ const (
SizeofSockaddrUnix = 0x6a
SizeofSockaddrDatalink = 0x14
SizeofLinger = 0x8
SizeofIpMreq = 0x8
SizeofIPMreq = 0x8
SizeofIPv6Mreq = 0x14
SizeofMsghdr = 0x30
SizeofCmsghdr = 0xc
SizeofInet6Pktinfo = 0x14
PTRACE_TRACEME = 0
PTRACE_CONT = 0x7
PTRACE_KILL = 0x8
@ -234,11 +236,16 @@ type Iovec struct {
Len uint64
}
type IpMreq struct {
type IPMreq struct {
Multiaddr [4]byte /* in_addr */
Interface [4]byte /* in_addr */
}
type IPv6Mreq struct {
Multiaddr [16]byte /* in6_addr */
Interface uint32
}
type Msghdr struct {
Name *byte
Namelen uint32
@ -257,6 +264,11 @@ type Cmsghdr struct {
Type int32
}
type Inet6Pktinfo struct {
Addr [16]byte /* in6_addr */
Ifindex uint32
}
type Kevent_t struct {
Ident uint64
Filter int16

View File

@ -32,9 +32,11 @@ const (
SizeofSockaddrUnix = 0x6a
SizeofSockaddrDatalink = 0x36
SizeofLinger = 0x8
SizeofIpMreq = 0x8
SizeofIPMreq = 0x8
SizeofIPv6Mreq = 0x14
SizeofMsghdr = 0x1c
SizeofCmsghdr = 0xc
SizeofInet6Pktinfo = 0x14
PTRACE_TRACEME = 0
PTRACE_CONT = 0x7
PTRACE_KILL = 0x8
@ -219,11 +221,16 @@ type Iovec struct {
Len uint32
}
type IpMreq struct {
type IPMreq struct {
Multiaddr [4]byte /* in_addr */
Interface [4]byte /* in_addr */
}
type IPv6Mreq struct {
Multiaddr [16]byte /* in6_addr */
Interface uint32
}
type Msghdr struct {
Name *byte
Namelen uint32
@ -240,6 +247,11 @@ type Cmsghdr struct {
Type int32
}
type Inet6Pktinfo struct {
Addr [16]byte /* in6_addr */
Ifindex uint32
}
type Kevent_t struct {
Ident uint32
Filter int16

View File

@ -32,9 +32,11 @@ const (
SizeofSockaddrUnix = 0x6a
SizeofSockaddrDatalink = 0x36
SizeofLinger = 0x8
SizeofIpMreq = 0x8
SizeofIPMreq = 0x8
SizeofIPv6Mreq = 0x14
SizeofMsghdr = 0x30
SizeofCmsghdr = 0xc
SizeofInet6Pktinfo = 0x14
PTRACE_TRACEME = 0
PTRACE_CONT = 0x7
PTRACE_KILL = 0x8
@ -220,11 +222,16 @@ type Iovec struct {
Len uint64
}
type IpMreq struct {
type IPMreq struct {
Multiaddr [4]byte /* in_addr */
Interface [4]byte /* in_addr */
}
type IPv6Mreq struct {
Multiaddr [16]byte /* in6_addr */
Interface uint32
}
type Msghdr struct {
Name *byte
Namelen uint32
@ -243,6 +250,11 @@ type Cmsghdr struct {
Type int32
}
type Inet6Pktinfo struct {
Addr [16]byte /* in6_addr */
Ifindex uint32
}
type Kevent_t struct {
Ident uint64
Filter int16

View File

@ -19,9 +19,11 @@ const (
SizeofSockaddrLinklayer = 0x14
SizeofSockaddrNetlink = 0xc
SizeofLinger = 0x8
SizeofIpMreq = 0x8
SizeofIPMreq = 0x8
SizeofIPv6Mreq = 0x14
SizeofMsghdr = 0x1c
SizeofCmsghdr = 0xc
SizeofInet6Pktinfo = 0x14
SizeofUcred = 0xc
IFA_UNSPEC = 0
IFA_ADDRESS = 0x1
@ -298,11 +300,16 @@ type Iovec struct {
Len uint32
}
type IpMreq struct {
type IPMreq struct {
Multiaddr [4]byte /* in_addr */
Interface [4]byte /* in_addr */
}
type IPv6Mreq struct {
Multiaddr [16]byte /* in6_addr */
Interface uint32
}
type Msghdr struct {
Name *byte
Namelen uint32
@ -319,6 +326,11 @@ type Cmsghdr struct {
Type int32
}
type Inet6Pktinfo struct {
Addr [16]byte /* in6_addr */
Ifindex uint32
}
type Ucred struct {
Pid int32
Uid uint32

View File

@ -19,9 +19,11 @@ const (
SizeofSockaddrLinklayer = 0x14
SizeofSockaddrNetlink = 0xc
SizeofLinger = 0x8
SizeofIpMreq = 0x8
SizeofIPMreq = 0x8
SizeofIPv6Mreq = 0x14
SizeofMsghdr = 0x38
SizeofCmsghdr = 0x10
SizeofInet6Pktinfo = 0x14
SizeofUcred = 0xc
IFA_UNSPEC = 0
IFA_ADDRESS = 0x1
@ -298,11 +300,16 @@ type Iovec struct {
Len uint64
}
type IpMreq struct {
type IPMreq struct {
Multiaddr [4]byte /* in_addr */
Interface [4]byte /* in_addr */
}
type IPv6Mreq struct {
Multiaddr [16]byte /* in6_addr */
Interface uint32
}
type Msghdr struct {
Name *byte
Namelen uint32
@ -321,6 +328,11 @@ type Cmsghdr struct {
Type int32
}
type Inet6Pktinfo struct {
Addr [16]byte /* in6_addr */
Ifindex uint32
}
type Ucred struct {
Pid int32
Uid uint32

View File

@ -24,9 +24,11 @@ const (
SizeofSockaddrLinklayer = 0x14
SizeofSockaddrNetlink = 0xc
SizeofLinger = 0x8
SizeofIpMreq = 0x8
SizeofIPMreq = 0x8
SizeofIPv6Mreq = 0x14
SizeofMsghdr = 0x1c
SizeofCmsghdr = 0xc
SizeofInet6Pktinfo = 0x14
SizeofUcred = 0xc
IFA_UNSPEC = 0
IFA_ADDRESS = 0x1
@ -305,11 +307,16 @@ type Iovec struct {
Len uint32
}
type IpMreq struct {
type IPMreq struct {
Multiaddr [4]byte /* in_addr */
Interface [4]byte /* in_addr */
}
type IPv6Mreq struct {
Multiaddr [16]byte /* in6_addr */
Interface uint32
}
type Msghdr struct {
Name *byte
Namelen uint32
@ -326,6 +333,11 @@ type Cmsghdr struct {
Type int32
}
type Inet6Pktinfo struct {
Addr [16]byte /* in6_addr */
Ifindex uint32
}
type Ucred struct {
Pid int32
Uid uint32