Esempio n. 1
0
func (table *BpfTable) leafToBytes(leafStr string) ([]byte, error) {
	mod := table.module.p
	leaf_size := C.bpf_table_leaf_size_id(mod, table.id)
	leaf := make([]byte, leaf_size)
	leafP := unsafe.Pointer(&leaf[0])
	leafCS := C.CString(leafStr)
	defer C.free(unsafe.Pointer(leafCS))
	r := C.bpf_table_leaf_sscanf(mod, table.id, leafCS, leafP)
	if r != 0 {
		//Warn.Printf("leaf type is \"%s\"\n", C.GoString(C.bpf_table_leaf_desc_id(mod, table.id)))
		return nil, fmt.Errorf("error scanning leaf (%v) from string", leafStr)
	}
	return leaf, nil
}
Esempio n. 2
0
func (table *BpfTable) leafToBytes(leafX interface{}) ([]byte, error) {
	mod := table.module.p
	leaf_size := C.bpf_table_leaf_size_id(mod, table.id)
	leafStr, ok := leafX.(string)
	if !ok {
		return nil, fmt.Errorf("table leaf must be a string")
	}
	leaf := make([]byte, leaf_size)
	leafP := unsafe.Pointer(&leaf[0])
	leafCS := C.CString(leafStr)
	defer C.free(unsafe.Pointer(leafCS))
	r := C.bpf_table_leaf_sscanf(mod, table.id, leafCS, leafP)
	if r != 0 {
		return nil, fmt.Errorf("error scanning leaf from string")
	}
	return leaf, nil
}