【问题标题】:How do I fix socat to work properly on MacOs?如何修复 socat 在 MacO 上正常工作?
【发布时间】:2019-10-04 11:46:58
【问题描述】:

我在 MacOs Mojave 上尝试过自制版本的 socat,但在运行时它无法工作:

socat STDIO,raw TCP:localhost:40707

这给出了错误:

tcsetattr(7, TCSADRAIN, 0x10457ad30): Device not configured

没有raw 它可以正常工作,但是我想要原始的,因为我希望能够在 socat 连接到的 shell 中操作文本对话框。

于是我下载了socat 1.7.3.3 版本的源代码,经过一个小小的hack 后,它得以编译。我的本地编译版本也有同样的问题。查看socat的源码,在xio-termios.c中有:

int xiotermios_flush(int fd) {
    if (_xiotermios_doit) {
        if (Tcsetattr(fd, TCSADRAIN, &_xiotermios_data.termarg) < 0) {
            Error3("tcsetattr(%d, TCSADRAIN, %p): %s",
                fd, &_xiotermios_data.termarg, strerror(errno));
            return -1;
        }
        _xiotermios_doit = false;
    }
    return 0;
}

我认为 tcsetattr 在 Mac 上的工作方式略有不同,因为相同的代码在 Linux 上工作正常。谁能帮我解决这个问题?

更新:我决定尝试创建一个运行 socat 的 docker 容器作为解决方法。

FROM alpine:3.10.2
RUN apk add --no-cache socat
ENTRYPOINT ["socat"]

然后我运行容器:

docker run --rm -ti socat STDIO,raw TCP:host.docker.internal:40707

不幸的是,这也不起作用,只是给了我:

tcsetattr(5, TCSADRAIN, 0x55aadeb42b40): Not a tty

虽然没有raw,但它似乎确实可以工作。

【问题讨论】:

    标签: c macos termios socat


    【解决方案1】:

    回到以前的 Socat 版本 1.7.3.2 并让它工作,所以 Mac (1.7.3.3) 上的最新 socat 似乎有问题。

    【讨论】:

      猜你喜欢
      • 2021-11-12
      • 1970-01-01
      • 2010-09-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多