Skip to content
This repository has been archived by the owner on Jan 16, 2022. It is now read-only.

Commit

Permalink
Merge pull request #16 from libp2p/fix/no-cgo
Browse files Browse the repository at this point in the history
fix: build without CGO
  • Loading branch information
Stebalien authored Mar 31, 2020
2 parents 52957a0 + d15798c commit 681f967
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module github.com/libp2p/go-sockaddr

require golang.org/x/sys v0.0.0-20190228124157-a34e9553db1e

go 1.13
14 changes: 0 additions & 14 deletions sockaddr.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
package sockaddr

import (
"unsafe"

sockaddrnet "github.com/libp2p/go-sockaddr/net"
)

import "C"

// Socklen is a type for the length of a sockaddr.
type Socklen uint

Expand All @@ -22,13 +18,3 @@ func SockaddrToAny(sa sockaddrnet.Sockaddr) (*sockaddrnet.RawSockaddrAny, Sockle
func AnyToSockaddr(rsa *sockaddrnet.RawSockaddrAny) (sockaddrnet.Sockaddr, error) {
return anyToSockaddr(rsa)
}

// AnyToCAny casts a *RawSockaddrAny to a *C.struct_sockaddr_any
func AnyToCAny(a *sockaddrnet.RawSockaddrAny) *C.struct_sockaddr_any {
return (*C.struct_sockaddr_any)(unsafe.Pointer(a))
}

// CAnyToAny casts a *C.struct_sockaddr_any to a *RawSockaddrAny
func CAnyToAny(a *C.struct_sockaddr_any) *sockaddrnet.RawSockaddrAny {
return (*sockaddrnet.RawSockaddrAny)(unsafe.Pointer(a))
}
18 changes: 18 additions & 0 deletions sockaddr_cgo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package sockaddr

import (
"C"
"unsafe"

sockaddrnet "github.com/libp2p/go-sockaddr/net"
)

// AnyToCAny casts a *RawSockaddrAny to a *C.struct_sockaddr_any
func AnyToCAny(a *sockaddrnet.RawSockaddrAny) *C.struct_sockaddr_any {
return (*C.struct_sockaddr_any)(unsafe.Pointer(a))
}

// CAnyToAny casts a *C.struct_sockaddr_any to a *RawSockaddrAny
func CAnyToAny(a *C.struct_sockaddr_any) *sockaddrnet.RawSockaddrAny {
return (*sockaddrnet.RawSockaddrAny)(unsafe.Pointer(a))
}

0 comments on commit 681f967

Please sign in to comment.