Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/sys/windows: missing SOCKADDR_BTH #52958

Closed
MatejMagat305 opened this issue May 18, 2022 · 6 comments
Closed

x/sys/windows: missing SOCKADDR_BTH #52958

MatejMagat305 opened this issue May 18, 2022 · 6 comments
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FeatureRequest NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@MatejMagat305
Copy link

MatejMagat305 commented May 18, 2022

I m not expert and I don t know, whether this belong to Proposals or Bugs, so sorry...

What version of Go are you using (go version)?

go version go1.18 windows/amd64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

go env Output
set GO111MODULE=on
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\matej\AppData\Local\go-build
set GOENV=C:\Users\matej\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\matej\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\matej\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.18
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=C:\Users\matej\GolandProjects\bluetooth\go.mod
set GOWORK=
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\matej\AppData\Local\Temp\go-build2316299000=/tmp/go-build -gno-record-gcc-switches 

What did you do?

I wanted create bluetooth socket on windows and I found that, there is no SockaddrBth similar (eqivalent) to SOCKADDR_BTH:

package main

import "golang.org/x/sys/windows"

func main() {
	sock, err := windows.Socket(windows.AF_BTH, windows.SOCK_STREAM, windows.BTHPROTO_RFCOMM)
	if err != nil {
		panic(err)
	}
        println(sock) // here is all right  
	//err = windows.Bind(sock,?)
	//if err != nil {
	//	panic(err)
	//}
	//return
}

So I was trying to add own struct to vendor according above mention SOCKADDR_BTH

type SockaddrBth struct {
	family         uint16
	BtAddr         [6]byte
	ServiceClassId GUID
	Port           uint16
}

func (sa *SockaddrBth) sockaddr() (unsafe.Pointer, int32, error) {
	if sa.Port < 0 || sa.Port > 31 {
		return nil, 0, syscall.EINVAL
	}
	sa.family = AF_BTH
	p := (*[2]byte)(unsafe.Pointer(&sa.Port))
	p[0] = byte(sa.Port >> 8)
	p[1] = byte(sa.Port)
	return unsafe.Pointer(sa), int32(unsafe.Sizeof(*sa)), nil
}

and run

package main

import (
	"golang.org/x/sys/windows"
)

func main() {
        ...
	sock, err := windows.Socket(windows.AF_BTH, windows.SOCK_STREAM, windows.BTHPROTO_RFCOMM)
	if err != nil {
		panic(err)
	}
	g, _ := windows.GenerateGUID()
	s := &windows.SockaddrBth{
		BtAddr:         [6]byte{},
		ServiceClassId: g,
		Port:           1,
	}
	err = windows.Bind(sock, s)
	if err != nil {
		panic(err) //golang.org/x/sys/windows.WSAEFAULT (10014)
	}
       ...
}

What did you expect to see?

no error

What did you see instead?

golang.org/x/sys/windows.WSAEFAULT (10014)

@seankhliao seankhliao changed the title golang.org/x/sys/windows missing API ? golang.org/x/sys/windows missing SOCKADDR_BTH May 18, 2022
@seankhliao seankhliao changed the title golang.org/x/sys/windows missing SOCKADDR_BTH x/sys/windows: missing SOCKADDR_BTH May 18, 2022
@gopherbot gopherbot added this to the Unreleased milestone May 18, 2022
@mknyszek mknyszek added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label May 18, 2022
@mknyszek
Copy link
Contributor

CC @golang/runtime @alexbrainman

@alexbrainman
Copy link
Member

golang.org/x/sys/windows.WSAEFAULT (10014)

@MatejMagat305

From

https://docs.microsoft.com/en-us/windows/win32/winsock/windows-sockets-error-codes-2

WSAEFAULT
10014
Bad address.
The system detected an invalid pointer address in attempting to use a pointer argument of a call. This error occurs if an application passes an invalid pointer value, or if the length of the buffer is too small. For instance, if the length of an argument, which is a sockaddr structure, is smaller than the sizeof(sockaddr).

I suspect there is a bug in your program. But I never used Bluetooth API on Windows. So I don't know what your problem is.

Alex

@MatejMagat305
Copy link
Author

I was found it, but I do not know how i can fix it, because it should be available in pure GO ...

@alexbrainman
Copy link
Member

I was found it, but I do not know how i can fix it, ...

I don't know how to fix it too.

Alex

@MatejMagat305
Copy link
Author

Primary I do not want create own sockaddrBt ..., but I do not to see how and what I should use ... .

@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Jul 7, 2022
@MatejMagat305
Copy link
Author

MatejMagat305 commented Feb 24, 2024

I think that is solved by #53929

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FeatureRequest NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants