func socketConnect(pid int, proto ProtoType, rAddr string) (net.Conn, error) { fd, err := ns.OpenProcess(pid, ns.CLONE_NEWNET) defer ns.Close(fd) if err != nil { return nil, err } return nsProxySocketConnect(fd, proto, rAddr) }
func proxySocketListener(pid int, proto ProtoType, lAddr string) (net.Listener, error) { fd, err := ns.OpenProcess(pid, ns.CLONE_NEWNET) defer ns.Close(fd) if err != nil { return nil, err } return nsSocketListener(fd, proto, lAddr) }
func nsProxySocketConnect(fd uintptr, proto ProtoType, rAddr string) (net.Conn, error) { origNs, _ := ns.OpenProcess(os.Getpid(), ns.CLONE_NEWNET) defer ns.Close(origNs) defer ns.Set(origNs, ns.CLONE_NEWNET) err := ns.Set(uintptr(fd), ns.CLONE_NEWNET) if err != nil { return nil, err } return net.Dial(string(proto), rAddr) }
func nsSocketListener(fd uintptr, proto ProtoType, lAddr string) (net.Listener, error) { origNs, _ := ns.OpenProcess(os.Getpid(), ns.CLONE_NEWNET) defer ns.Close(origNs) defer ns.Set(origNs, ns.CLONE_NEWNET) err := ns.Set(uintptr(fd), ns.CLONE_NEWNET) if err != nil { return nil, err } return net.Listen(string(proto), lAddr) }