Search code examples
cmacostermiossocat

How do I fix socat to work properly on MacOs?


I've tried the Homebrew version of socat on MacOs Mojave and it fails to work when run with:

socat STDIO,raw TCP:localhost:40707

This gives the error:

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

Without the raw it works fine, however I want raw because I want to be able to manipulate text dialogs within the shell that socat is connected to.

So I downloaded the source of version 1.7.3.3 of socat, and after a small hack got it to compile. Same problem with my locally compiled version. Looking at the source for socat, it has in 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;
}

I presume that tcsetattr works a bit differently on a Mac because the same code works fine on Linux. Can anyone help me fix this?

UPDATE: I decided to try to create a docker container running socat as a workaround.

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

Then I ran the container with:

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

Unfortunately that didn't work either, and just gave me:

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

Although again, it did seem to work without the raw.


Solution

  • Went back to a previous Socat version 1.7.3.2 and got it working, so there appears to be something wrong with latest socat on Mac (1.7.3.3).