Install Socat Cygwin
Posted : admin On 5/27/2019I installed Cygwin64 on a win7-64 with gcc dev tools and I just noticed that it produces 64bit binaries. (Well, not that surprising :o) Is there a mean to make it producing some 32bit binaries?
The Cygwin 1.7.x devel area offers an older version of GCC (3.4.4-999). Run make install (this will install all the relevant files to the relevant directories). Unofficial build of socat built with cygwin. Output of socat -V socat by Gerhard Rieger - see.
Dest-unreach / socat. Socat - Multipurpose relay Abstract what: 'netcat++' (extended design, new implementation) OS: AIX, BSD, HP-UX, Linux, Solaris e.a. (UNIX) lic: GPL2 inst: tar x.;./configure; make; make install doc: README; socat.html, socat.1; xio.help ui: command line exa: socat TCP6-LISTEN:8080,reuseaddr,fork PROXY:proxy:www.domain.
I am compiling the socat tool for windows, compiled in 64bit it is working, but I am trying to make another version suitable for an XP-32.
The configure
script does not seem to support a -b 32
switch (that I must have seen for ming64 from this thread, and if I try to specify the -m32
switch in CFLAGS
for configure
it fails:
Would the option be to also install Cygwin32, or can I compile 32bit code with another setting or additional cygwin package?
Yum Install Socat
Edit:I have found that my cygwin64/gcc cannot compile a simple hello.c
program in 32bits:
with a gcc -o hello.exe hello.c
it works flawlessly, but gcc -o hello.exe hello.c -m32
spits
3 Answers
Socat Download
Cygwin provides packages containing cygwin-to-cygwin cross toolchains. There are cygwin32-*
packages for building 32-bit from 64-bit Cygwin and cygwin64-*
packages for building 64-bit from 32-bit Cygwin.
I've never used them, but I assume they work pretty much as any cross toolchain, so you should pass correct --host
and --build
arguments to your ./configure
step.
Adding -m32 to the compiler does not make it select the correct libraries. You should check you have the i686-pc-cygwin-gcc compiler installed. To use that compiler you have to do something like this:
./configure --target=i686-pc-cygwin
Hope it helps :-)
configure is part of autotools, and not relevant to the original question. There are two 32 bit runtime environments you can build a C program for. CYGWIN-32 and MINGW32. I will not go into details on the differences, but a cygwin32 program is posix/Linux compatible (mostly), so I prefer that environment. Here are the details on how to make a cygwin32 application on a cygwin64 install:
1)install cygwin32-gcc package and the cygwin32-w32api-runtime package in cygwin64 setup, if you have not already done this. this will install a c compiler i686-pc-cygwin-gcc and the runtime cygwin1.dll that you will need to test your program (or you can test it in a cygwin32 install).
2) assuming your hello.c program above is to be compiled, select the C compiler and runtime, from the cygwin64 shell by using export CC, or just execute the C compiler as the default make output shows below 'make hello':
3) you will note that nothing really happens because Cygwin runtime for 32 bit is not in the path. So add it to the path, and it will execute correctly
4) Sit back, have a sip of coffee, and rejoice
Not the answer you're looking for? Browse other questions tagged gcccygwin32bit-64bitwindows-7-x64 or ask your own question.
I have a scenario where multiple processes on the same box want to communicate with a serial device. Process A needs two-way communications with the serial port, and Process B only needs to be able to write to the serial port. The serial device is continually spewing data, while the two processes periodically write to the port. The environment is Cygwin on Windows (the processes are windows processes), but the serial port could be moved to a *nix virtual machine if anyone has a Linux-only solution.
My 'network diagram' is as follows:
My first attempt was to set up a socat instance with udp-recvfrom and the fork option. This works for the first packet - a process forks off from socat, sends the data to the serial device, and starts reading data back from the serial device. However, this forked process now has the serial port open for read-write, so no more forks successfully start.
Can anyone think of any way to get this to work? I can think of the following avenues but I haven't found settings to make any of them work:
- Use socat's udp-recv option to receive from anyone, but find a way to make it send replies to a specific address.
- Use two unidirectional socats, one to write to the port and one to read from the port. I would then need a way to combine these two unidirectional streams into one bidirectional stream, but I don't know how.
1 Answer
I found a solution. It involves 4 instances of socat, arranged in the network diagram below:
- Socat 'B' talks to the serial port, takes input on stdin and outputs to stdout.
- Socat 'A' listens for UDP packets from anywhere and outputs them over stdout, where they are piped into socat 'B'.
- Socat 'C' listens for a TCP connection from Process A. Data coming from socat 'A' comes in stdin and is routed to Process A. Data from Process A is sent out stdout to socat 'D'.
- Socat 'D' takes data from stdin and sends it out over UDP to socat 'A'.
Process B sends UDP packets to socat 'B' when it wants to inject traffic.
The bash command to create this monstrosity is as follows:
This also sets a timeout of 5 seconds and logs a lot of detail to 'log.txt'. Port numbers replaced for security.