Installing socat on Mac OS X

In another article I showed how to create a twisted pair of virtual serial port on Linux using socat, the same thing can be done on Mac OS X, but socat must be installed using the source code, so you need to have the developer tools installed

Download the source code from here (http://www.dest-unreach.org/socat/), I downloaded version socat-2.0.0-b5

9-pinout

open a terminal ad cd into the directory where you have downloaded the source code

extract the archive issuing the following command:
# tar zxvf socat-2.0.0-b5.tgz

cd into the socat source directory
# cd socat-2.0.0-b5

run the configure script:
# ./configure

run the make command to build the application
# make
............
............
gcc -O -D_GNU_SOURCE  -Wall -Wno-parentheses -DHAVE_CONFIG_H -I.  -I.   -c -o xio-ip4.o xio-ip4.c
gcc -O -D_GNU_SOURCE  -Wall -Wno-parentheses -DHAVE_CONFIG_H -I.  -I.   -c -o xio-ip6.o xio-ip6.c
xio-ip6.c:28:155: error: use of undeclared identifier 'IPV6_PKTINFO'; did you mean 'OPT_IPV6_PKTINFO'?
  ..."pktinfo", OPT_IPV6_PKTINFO, GROUP_SOCK_IP6, PH_PASTSOCKET, TYPE_BOOL, OFUNC_SOCKOPT, SOL_IPV6, IPV6_PKTINFO };
                                                                                                     ^~~~~~~~~~~~
                                                                                                     OPT_IPV6_PKTINFO
./xioopts.h:361:4: note: 'OPT_IPV6_PKTINFO' declared here
   OPT_IPV6_PKTINFO,
   ^
xio-ip6.c:32:155: error: use of undeclared identifier 'IPV6_RTHDR'
  ...{ "ipv6-rthdr",   "rthdr",   OPT_IPV6_RTHDR,   GROUP_SOCK_IP6, PH_PASTSOCKET, TYPE_BOOL, OFUNC_SOCKOPT, SOL_IPV6, IPV6_RTHD...
                                                                                                                       ^
xio-ip6.c:39:155: error: use of undeclared identifier 'IPV6_DSTOPTS'; did you mean 'OPT_IPV6_DSTOPTS'?
  ..."dstopts", OPT_IPV6_DSTOPTS, GROUP_SOCK_IP6, PH_PASTSOCKET, TYPE_BOOL, OFUNC_SOCKOPT, SOL_IPV6, IPV6_DSTOPTS };
                                                                                                     ^~~~~~~~~~~~
                                                                                                     OPT_IPV6_DSTOPTS
./xioopts.h:356:4: note: 'OPT_IPV6_DSTOPTS' declared here
   OPT_IPV6_DSTOPTS,
   ^
xio-ip6.c:43:155: error: use of undeclared identifier 'IPV6_HOPOPTS'; did you mean 'OPT_IPV6_HOPOPTS'?
  ..."hopopts", OPT_IPV6_HOPOPTS, GROUP_SOCK_IP6, PH_PASTSOCKET, TYPE_BOOL, OFUNC_SOCKOPT, SOL_IPV6, IPV6_HOPOPTS };
                                                                                                     ^~~~~~~~~~~~
                                                                                                     OPT_IPV6_HOPOPTS
./xioopts.h:359:4: note: 'OPT_IPV6_HOPOPTS' declared here
   OPT_IPV6_HOPOPTS,
   ^
xio-ip6.c:50:155: error: use of undeclared identifier 'IPV6_HOPLIMIT'; did you mean 'OPT_IPV6_HOPLIMIT'?
  ...PH_PASTSOCKET, TYPE_BOOL, OFUNC_SOCKOPT, SOL_IPV6, IPV6_HOPLIMIT };
                                                        ^~~~~~~~~~~~~
                                                        OPT_IPV6_HOPLIMIT
./xioopts.h:358:4: note: 'OPT_IPV6_HOPLIMIT' declared here
   OPT_IPV6_HOPLIMIT,
   ^
xio-ip6.c:206:9: error: use of undeclared identifier 'IPV6_PKTINFO'; did you mean 'OPT_IPV6_PKTINFO'?
   case IPV6_PKTINFO: {
        ^~~~~~~~~~~~
        OPT_IPV6_PKTINFO
./xioopts.h:361:4: note: 'OPT_IPV6_PKTINFO' declared here
   OPT_IPV6_PKTINFO,
   ^
xio-ip6.c:217:9: error: use of undeclared identifier 'IPV6_HOPLIMIT'; did you mean 'OPT_IPV6_HOPLIMIT'?
   case IPV6_HOPLIMIT:
        ^~~~~~~~~~~~~
        OPT_IPV6_HOPLIMIT
./xioopts.h:358:4: note: 'OPT_IPV6_HOPLIMIT' declared here
   OPT_IPV6_HOPLIMIT,
   ^
xio-ip6.c:222:9: error: use of undeclared identifier 'IPV6_RTHDR'
   case IPV6_RTHDR:
        ^
xio-ip6.c:234:9: error: use of undeclared identifier 'IPV6_DSTOPTS'; did you mean 'OPT_IPV6_DSTOPTS'?
   case IPV6_DSTOPTS:
        ^~~~~~~~~~~~
        OPT_IPV6_DSTOPTS
./xioopts.h:356:4: note: 'OPT_IPV6_DSTOPTS' declared here
   OPT_IPV6_DSTOPTS,
   ^
xio-ip6.c:239:9: error: use of undeclared identifier 'IPV6_HOPOPTS'; did you mean 'OPT_IPV6_HOPOPTS'?
   case IPV6_HOPOPTS:
        ^~~~~~~~~~~~
        OPT_IPV6_HOPOPTS
./xioopts.h:359:4: note: 'OPT_IPV6_HOPOPTS' declared here
   OPT_IPV6_HOPOPTS,
   ^
10 errors generated.
make: *** [xio-ip6.o] Error 1


as you can see there are undeclared IPv6 identifiers. To solve this problem you have to add the following line at the beginning of xio-ip6.c:
 #define __APPLE_USE_RFC_2292

You can issue the following command or you can edit xio-ip6.c with your favorite editor:

# echo '#define __APPLE_USE_RFC_2292' > temp_file.c
# cat xio-ip6.c >> temp_file.c
# mv temp_file.csv xio-ip6.c

Issue, again, the make command:

 

# make

This time the make should go well…

 

now on a terminal window run socat

# socat -d -d PTY: PTY:

The output should look like the following one:

2013/09/20 14:07:10 socat[6871] N PTY is /dev/pts/5
2013/09/20 14:07:10 socat[6871] N PTY is /dev/pts/6
2013/09/20 14:07:10 socat[6871] N starting data transfer loop with FDs [3,3] and [5,5]

 

Now you have two "serial" ports connected back to back, open a new terminal and issue the following command

# sudo cat /dev/pts/5

open a new terminal and issue the following command

# sudo echo "Hello World" > /dev/pts/6

On the first terminal you should see the string "Hello World".

 

That's all, nothing more.

Gg1