Beispiel #1
0
//export goUdpGwClient_NewConnection
// goUdpGwClient_NewConnection creates a connection and returns a connection ID
// given local and remote addresses.
func goUdpGwClient_NewConnection(cLocalAddr C.BAddr, cRemoteAddr C.BAddr) C.uint16_t {

	// Open a connection for localAddr and remoteAddr
	laddr := C.baddr_to_str(&cLocalAddr)
	raddr := C.baddr_to_str(&cRemoteAddr)

	defer func() {
		C.free(unsafe.Pointer(laddr))
		C.free(unsafe.Pointer(raddr))
	}()

	localAddr := C.GoString(laddr)
	remoteAddr := C.GoString(raddr)

	connID, err := udpgwLookupOrCreateConnId(localAddr, remoteAddr)
	if err != nil {
		return 0
	}

	client, _ := getUdpGwClientById(connID)

	client.cLocalAddr = cLocalAddr
	client.cRemoteAddr = cRemoteAddr

	return C.uint16_t(connID)
}
Beispiel #2
0
//export goUdpGwClient_FindConnectionIdByAddr
// goUdpGwClient_FindConnectionIdByAddr returns a connection ID given local and
// remote addresses.
func goUdpGwClient_FindConnectionIdByAddr(cLocalAddr C.BAddr, cRemoteAddr C.BAddr) C.uint16_t {
	// Open a connection for localAddr and remoteAddr
	laddr := C.baddr_to_str(&cLocalAddr)
	raddr := C.baddr_to_str(&cRemoteAddr)

	defer func() {
		C.free(unsafe.Pointer(laddr))
		C.free(unsafe.Pointer(raddr))
	}()

	connID, err := udpgwLookupConnId(C.GoString(laddr), C.GoString(raddr))
	if err != nil {
		return 0
	}

	return C.uint16_t(connID)
}