Some CGo fixes.

This commit is contained in:
Adam Ierymenko 2020-05-30 12:07:52 -07:00
parent 1970dab13d
commit 33269cd29d
No known key found for this signature in database
GPG key ID: C8877CF2D7A5D7F3
2 changed files with 9 additions and 9 deletions

View file

@ -42,8 +42,8 @@ func NewEndpointFromString(s string) (*Endpoint, error) {
if strings.IndexRune(s, '-') > 0 || (strings.IndexRune(s, ':') < 0 && strings.IndexRune(s, '.') < 0) {
var ep Endpoint
cs := C.CString(s)
defer C.free(cs)
if C.ZT_Endpoint_fromString(cs) == nil {
defer C.free(unsafe.Pointer(cs))
if C.ZT_Endpoint_fromString(&ep.cep, cs) != 0 {
return nil, ErrInvalidParameter
}
return &ep, nil
@ -115,7 +115,7 @@ func (ep *Endpoint) MAC() MAC {
func (ep *Endpoint) String() string {
var buf [4096]byte
cs := C.ZT_Endpoint_toString(&ep.cep,unsafe.Pointer(&buf[0]),4096)
cs := C.ZT_Endpoint_toString(&ep.cep, (*C.char)(unsafe.Pointer(&buf[0])), 4096)
if cs == nil {
return "0"
}

View file

@ -70,8 +70,8 @@ func NewLocatorFromString(s string) (*Locator, error) {
}
sb := []byte(s)
sb = append(sb, 0)
loc := C.ZT_Locator_fromString(unsafe.Pointer(&sb[0]))
if uintptr(loc) == 0 {
loc := C.ZT_Locator_fromString((*C.char)(unsafe.Pointer(&sb[0])))
if loc == nil {
return nil, ErrInvalidParameter
}
goloc := new(Locator)
@ -104,7 +104,7 @@ func (loc *Locator) GetInfo(id *Identity) (ts int64, fp *Fingerprint, eps []Endp
func (loc *Locator) String() string {
var buf [4096]byte
C.ZT_Locator_toString(loc.cl,unsafe.Pointer(&buf[0]),4096)
C.ZT_Locator_toString(loc.cl, (*C.char)(unsafe.Pointer(&buf[0])), 4096)
for i := range buf {
if buf[i] == 0 {
return string(buf[0:i])