Search code examples
socat

socat, need example using af_inet sock_stream to get data from machine


Need example to connect using PF_INET and SOCK_STREAM via socat program. When I try:

sudo socat socket-connect:af_inet:0:192.168.0.10 STDIO 

I get:

[11458] E exiting on signal 11

Solution

  • What you try is establishing a TCP connecting using low level functions. Therefore you will need a port number. For this example solution I take 80.

    Assuming you have good reason not to use the ready to use TCP address the solution might be something like:

    socat SOCKET-CONNECT:2:6:"x0050 xC0A8000A x00000000 x00000000" STDIO
    

    Meaning of parameters: 2...AF_INET 6...TCP The third parameter is data to construct the socket address, for AF_INET we need a struct sockaddr_in; the first two bytes of the record specify its length and are implicitly generated by Socat from the given data. x0050...port in hex, network byte order xC0A8000A...hex for 192.168.0.10 x00000000...padding to length 16

    Hope this helps!