sys_windows.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // Copyright 2014 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package ipv4
  5. import (
  6. "golang.org/x/net/internal/iana"
  7. "golang.org/x/net/internal/socket"
  8. )
  9. const (
  10. // See ws2tcpip.h.
  11. sysIP_OPTIONS = 0x1
  12. sysIP_HDRINCL = 0x2
  13. sysIP_TOS = 0x3
  14. sysIP_TTL = 0x4
  15. sysIP_MULTICAST_IF = 0x9
  16. sysIP_MULTICAST_TTL = 0xa
  17. sysIP_MULTICAST_LOOP = 0xb
  18. sysIP_ADD_MEMBERSHIP = 0xc
  19. sysIP_DROP_MEMBERSHIP = 0xd
  20. sysIP_DONTFRAGMENT = 0xe
  21. sysIP_ADD_SOURCE_MEMBERSHIP = 0xf
  22. sysIP_DROP_SOURCE_MEMBERSHIP = 0x10
  23. sysIP_PKTINFO = 0x13
  24. sizeofInetPktinfo = 0x8
  25. sizeofIPMreq = 0x8
  26. sizeofIPMreqSource = 0xc
  27. )
  28. type inetPktinfo struct {
  29. Addr [4]byte
  30. Ifindex int32
  31. }
  32. type ipMreq struct {
  33. Multiaddr [4]byte
  34. Interface [4]byte
  35. }
  36. type ipMreqSource struct {
  37. Multiaddr [4]byte
  38. Sourceaddr [4]byte
  39. Interface [4]byte
  40. }
  41. // See http://msdn.microsoft.com/en-us/library/windows/desktop/ms738586(v=vs.85).aspx
  42. var (
  43. ctlOpts = [ctlMax]ctlOpt{}
  44. sockOpts = map[int]*sockOpt{
  45. ssoTOS: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_TOS, Len: 4}},
  46. ssoTTL: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_TTL, Len: 4}},
  47. ssoMulticastTTL: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_MULTICAST_TTL, Len: 4}},
  48. ssoMulticastInterface: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_MULTICAST_IF, Len: 4}},
  49. ssoMulticastLoopback: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_MULTICAST_LOOP, Len: 4}},
  50. ssoHeaderPrepend: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_HDRINCL, Len: 4}},
  51. ssoJoinGroup: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_ADD_MEMBERSHIP, Len: sizeofIPMreq}, typ: ssoTypeIPMreq},
  52. ssoLeaveGroup: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_DROP_MEMBERSHIP, Len: sizeofIPMreq}, typ: ssoTypeIPMreq},
  53. }
  54. )
  55. func (pi *inetPktinfo) setIfindex(i int) {
  56. pi.Ifindex = int32(i)
  57. }