Jason A. Donenfeld has uploaded this change for review.
windows: add WSASocket
Simple function to complement the other ws2 functions we have:
https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsasocketw
Change-Id: Idf6b17360d84a8529e48ab94561c4ac7bee1d847
---
M windows/syscall_windows.go
M windows/types_windows.go
M windows/zsyscall_windows.go
3 files changed, 23 insertions(+), 0 deletions(-)
diff --git a/windows/syscall_windows.go b/windows/syscall_windows.go
index a278c5f..b8916ae 100644
--- a/windows/syscall_windows.go
+++ b/windows/syscall_windows.go
@@ -773,6 +773,7 @@
//sys WSASend(s Handle, bufs *WSABuf, bufcnt uint32, sent *uint32, flags uint32, overlapped *Overlapped, croutine *byte) (err error) [failretval==socket_error] = ws2_32.WSASend
//sys WSARecvFrom(s Handle, bufs *WSABuf, bufcnt uint32, recvd *uint32, flags *uint32, from *RawSockaddrAny, fromlen *int32, overlapped *Overlapped, croutine *byte) (err error) [failretval==socket_error] = ws2_32.WSARecvFrom
//sys WSASendTo(s Handle, bufs *WSABuf, bufcnt uint32, sent *uint32, flags uint32, to *RawSockaddrAny, tolen int32, overlapped *Overlapped, croutine *byte) (err error) [failretval==socket_error] = ws2_32.WSASendTo
+//sys WSASocket(af int32, typ int32, protocol int32, protoInfo *WSAProtocolInfo, group uint32, flags uint32) (handle Handle, err error) [failretval==InvalidHandle] = ws2_32.WSASocketW
//sys GetHostByName(name string) (h *Hostent, err error) [failretval==nil] = ws2_32.gethostbyname
//sys GetServByName(name string, proto string) (s *Servent, err error) [failretval==nil] = ws2_32.getservbyname
//sys Ntohs(netshort uint16) (u uint16) = ws2_32.ntohs
diff --git a/windows/types_windows.go b/windows/types_windows.go
index 28cf15b..fe13527 100644
--- a/windows/types_windows.go
+++ b/windows/types_windows.go
@@ -1039,6 +1039,18 @@
Flags uint32
}
+// Flags for WSASocket
+const (
+ WSA_FLAG_OVERLAPPED = 0x01
+ WSA_FLAG_MULTIPOINT_C_ROOT = 0x02
+ WSA_FLAG_MULTIPOINT_C_LEAF = 0x04
+ WSA_FLAG_MULTIPOINT_D_ROOT = 0x08
+ WSA_FLAG_MULTIPOINT_D_LEAF = 0x10
+ WSA_FLAG_ACCESS_SYSTEM_SECURITY = 0x40
+ WSA_FLAG_NO_HANDLE_INHERIT = 0x80
+ WSA_FLAG_REGISTERED_IO = 0x100
+)
+
// Invented values to support what package os expects.
const (
S_IFMT = 0x1f000
diff --git a/windows/zsyscall_windows.go b/windows/zsyscall_windows.go
index 316157e..ca558ea 100644
--- a/windows/zsyscall_windows.go
+++ b/windows/zsyscall_windows.go
@@ -370,6 +370,7 @@
procWSARecvFrom = modws2_32.NewProc("WSARecvFrom")
procWSASend = modws2_32.NewProc("WSASend")
procWSASendTo = modws2_32.NewProc("WSASendTo")
+ procWSASocketW = modws2_32.NewProc("WSASocketW")
procWSAStartup = modws2_32.NewProc("WSAStartup")
procbind = modws2_32.NewProc("bind")
procclosesocket = modws2_32.NewProc("closesocket")
@@ -3155,6 +3156,15 @@
return
}
+func WSASocket(af int32, typ int32, protocol int32, protoInfo *WSAProtocolInfo, group uint32, flags uint32) (handle Handle, err error) {
+ r0, _, e1 := syscall.Syscall6(procWSASocketW.Addr(), 6, uintptr(af), uintptr(typ), uintptr(protocol), uintptr(unsafe.Pointer(protoInfo)), uintptr(group), uintptr(flags))
+ handle = Handle(r0)
+ if handle == InvalidHandle {
+ err = errnoErr(e1)
+ }
+ return
+}
+
func WSAStartup(verreq uint32, data *WSAData) (sockerr error) {
r0, _, _ := syscall.Syscall(procWSAStartup.Addr(), 2, uintptr(verreq), uintptr(unsafe.Pointer(data)), 0)
if r0 != 0 {
To view, visit change 295175. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Alex Brainman, Brad Fitzpatrick, Ian Lance Taylor.
Patch set 1:Run-TryBot +1Trust +1
Attention is currently required from: Jason A. Donenfeld, Brad Fitzpatrick, Ian Lance Taylor.
Patch set 1:Code-Review +2Trust +1
1 comment:
Patchset:
LGTM.
Thank you.
Alex
To view, visit change 295175. To unsubscribe, or for help writing mail filters, visit settings.
Jason A. Donenfeld submitted this change.
windows: add WSASocket
Simple function to complement the other ws2 functions we have:
https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsasocketw
Change-Id: Idf6b17360d84a8529e48ab94561c4ac7bee1d847
Reviewed-on: https://go-review.googlesource.com/c/sys/+/295175
Trust: Jason A. Donenfeld <Ja...@zx2c4.com>
Trust: Alex Brainman <alex.b...@gmail.com>
Run-TryBot: Jason A. Donenfeld <Ja...@zx2c4.com>
TryBot-Result: Go Bot <go...@golang.org>
Reviewed-by: Alex Brainman <alex.b...@gmail.com>
To view, visit change 295175. To unsubscribe, or for help writing mail filters, visit settings.