See also, http://libraryofalexandria.io/cgo/
cgo
has a lot of trap.
but Not "C" pkg also directory in $GOROOT/src
. IDE's(vim) Goto command not works.
So, Here collect materials.
See also, http://libraryofalexandria.io/cgo/
cgo
has a lot of trap.
but Not "C" pkg also directory in $GOROOT/src
. IDE's(vim) Goto command not works.
So, Here collect materials.
package main | |
import ( | |
"context" | |
"flag" | |
"fmt" | |
"io" | |
"net" | |
"net/http" | |
"os" |
Here is the gist for showing how to send string from c to go without a copy, for sending an float32 array from c to go without copy, please see here
Below is the documentation for converting between a c string and a go string:
// From https://golang.org/cmd/cgo/
// A few special functions convert between Go and C types by making copies of the data.
// Go string to C string
// The C string is allocated in the C heap using malloc.
// It is the caller's responsibility to arrange for it to be
// freed, such as by calling C.free (be sure to include stdlib.h
#define KBUILD_MODNAME "foo" | |
#include <uapi/linux/bpf.h> | |
#include <linux/bpf.h> | |
#include <linux/icmp.h> | |
#include <linux/if_ether.h> | |
#include <linux/if_vlan.h> | |
#include <linux/in.h> | |
#include <linux/ip.h> | |
#include <linux/tcp.h> | |
#include <linux/udp.h> |
GODEBUG=netdns=cgo+2 go run listen.go | |
GOOS: linux | |
go package net: using cgo DNS resolver | |
go package net: hostLookupOrder(localhost) = cgo | |
net.LookupHost addrs: [::1 127.0.0.1] err: <nil> | |
go package net: hostLookupOrder(localhost) = cgo | |
Listener address: 127.0.0.1:8080 | |
go package net: hostLookupOrder(localhost) = cgo | |
Dial remote address: 127.0.0.1:8080 |
#!/usr/bin/env python3 | |
import base64 | |
import subprocess | |
from json import dumps | |
from hashlib import md5 | |
from Crypto.Cipher import AES | |
from Crypto.Util.Padding import pad | |
def get_id_and_sn(): |