mirror of
https://github.com/rwinkhart/sys.git
synced 2026-09-02 15:17:31 -04:00
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 <Jason@zx2c4.com> Trust: Alex Brainman <alex.brainman@gmail.com> Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
This commit is contained in:
@@ -773,6 +773,7 @@ const socket_error = uintptr(^uint32(0))
|
|||||||
//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 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 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 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 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 GetServByName(name string, proto string) (s *Servent, err error) [failretval==nil] = ws2_32.getservbyname
|
||||||
//sys Ntohs(netshort uint16) (u uint16) = ws2_32.ntohs
|
//sys Ntohs(netshort uint16) (u uint16) = ws2_32.ntohs
|
||||||
|
|||||||
@@ -1039,6 +1039,18 @@ type WSAMsg struct {
|
|||||||
Flags uint32
|
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.
|
// Invented values to support what package os expects.
|
||||||
const (
|
const (
|
||||||
S_IFMT = 0x1f000
|
S_IFMT = 0x1f000
|
||||||
|
|||||||
@@ -370,6 +370,7 @@ var (
|
|||||||
procWSARecvFrom = modws2_32.NewProc("WSARecvFrom")
|
procWSARecvFrom = modws2_32.NewProc("WSARecvFrom")
|
||||||
procWSASend = modws2_32.NewProc("WSASend")
|
procWSASend = modws2_32.NewProc("WSASend")
|
||||||
procWSASendTo = modws2_32.NewProc("WSASendTo")
|
procWSASendTo = modws2_32.NewProc("WSASendTo")
|
||||||
|
procWSASocketW = modws2_32.NewProc("WSASocketW")
|
||||||
procWSAStartup = modws2_32.NewProc("WSAStartup")
|
procWSAStartup = modws2_32.NewProc("WSAStartup")
|
||||||
procbind = modws2_32.NewProc("bind")
|
procbind = modws2_32.NewProc("bind")
|
||||||
procclosesocket = modws2_32.NewProc("closesocket")
|
procclosesocket = modws2_32.NewProc("closesocket")
|
||||||
@@ -3155,6 +3156,15 @@ func WSASendTo(s Handle, bufs *WSABuf, bufcnt uint32, sent *uint32, flags uint32
|
|||||||
return
|
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) {
|
func WSAStartup(verreq uint32, data *WSAData) (sockerr error) {
|
||||||
r0, _, _ := syscall.Syscall(procWSAStartup.Addr(), 2, uintptr(verreq), uintptr(unsafe.Pointer(data)), 0)
|
r0, _, _ := syscall.Syscall(procWSAStartup.Addr(), 2, uintptr(verreq), uintptr(unsafe.Pointer(data)), 0)
|
||||||
if r0 != 0 {
|
if r0 != 0 {
|
||||||
|
|||||||
Reference in New Issue
Block a user