Total Pageviews

Thursday, 26 May 2022

sock


Richard Stevens' sock program ##Introduction In TCP/IP Illustrated Vol. 1, Richard Stevens used a program called "sock" to demonstrate the many properties of TCP/IP. Unfortunately, the book only speaks about how to use the program but does not point to a site for downloading its sources. While sock is contained in the code package accompanying UNIX Network Programming, this code is also getting dated.

Recently I came across a standalone version of sock on a T/TCP project page. It was likewise indicating signs of bitrot, so I dusted it off and updated it to build on at least Linux, FreeBSD, OpenBSD, and MacOS, and made it available for download here.

I'm more than happy to include build fixes for other platforms, but I can not provide general build support, etc.

##News 0.3.2 is out, with minor compatibility updates. 01.06.10

##Features You want to have a look at the book for this, but here's the help output:

   usage: sock [ options ] <host> <port>       (for client; default)
   sock [ options ] -s [ <IPaddr> ] <port>     (for server)
   sock [ options ] -i <host> <port>           (for "source" client)
   sock [ options ] -i -s [ <IPaddr> ] <port>  (for "sink" server)
   options: -b n  bind n as client's local port number
     -c    convert newline to CR/LF & vice versa
     -f a.b.c.d.p  foreign IP address = a.b.c.d, foreign port# = p
     -g a.b.c.d  loose source route
     -h    issue TCP half close on standard input EOF
     -i    "source" data to socket, "sink" data from socket (w/-s)
     -j a.b.c.d  join multicast group
     -k    write or writev in chunks
     -l a.b.c.d.p  client's local IP address = a.b.c.d, local port# = p
     -n n  #buffers to write for "source" client (default 1024)
     -o    do NOT connect UDP client
     -p n  #ms to pause before each read or write (source/sink)
     -q n  size of listen queue for TCP server (default 5)
     -r n  #bytes per read() for "sink" server (default 1024)
     -s    operate as server instead of client
     -t n  set multicast ttl
     -u    use UDP instead of TCP
     -v    verbose
     -w n  #bytes per write() for "source" client (default 1024)
     -x n  #ms for SO_RCVTIMEO (receive timeout)
     -y n  #ms for SO_SNDTIMEO (send timeout)
     -A    SO_REUSEADDR option
     -B    SO_BROADCAST option
     -C    set terminal to cbreak mode
     -D    SO_DEBUG option
     -E    IP_RECVDSTADDR option
     -F    fork after connection accepted (TCP concurrent server)
     -G a.b.c.d  strict source route
     -H n  IP_TOS option (16=min del, 8=max thru, 4=max rel, 2=min$)
     -I    SIGIO signal
     -J n  IP_TTL option
     -K    SO_KEEPALIVE option
     -L n  SO_LINGER option, n = linger time
     -N    TCP_NODELAY option
     -O n  #ms to pause after listen, but before first accept
     -P n  #ms to pause before first read or write (source/sink)
     -Q n  #ms to pause after receiving FIN, but before close
     -R n  SO_RCVBUF option
     -S n  SO_SNDBUF option
     -T    SO_REUSEPORT option
     -U n  enter urgent mode before write number n (source only)
     -V    use writev() instead of write(); enables -k too
     -W    ignore write errors for sink client
     -X n  TCP_MAXSEG option (set MSS)
     -Y    SO_DONTROUTE option
     -Z    MSG_PEEK 
 
from https://github.com/daheli/sock 
----
Richard Stevens' sock program, based on http://www.icir.org/christian/sock.html 

This is a standalone version of Richard Stevens' "sock" program, based on the code available for the UNIX Network Programming book, at:

http://www.kohala.com/start/unpv12e.html

I found this version at

http://ttcplinux.sourceforge.net/tools/tools.html

and cleaned up the tarball a bit. To make sock a little easier to find, I'm now hosting it on a dedicated webpage:

http://www.icir.org/christian/sock.html

I will implement minor updates to the code when I feel they make sense for reasons of clarity or educational value, but I won't make any other changes (such as additional features or similars).

I'm happy to incorporate build fixes where feasible and necessary, but I do not give build support etc.

from https://github.com/anguslee/sock

https://github.com/keyou/sock

----

W. Richard Stevens' sock program (cleaned and ported to Linux)

W. Richard Steven's sock program

This is a port of W. Richard Steven's "sock" program. This program is extensively used for exercises in his excellent TCP/IP Illustrated book (I don't make any money if you purchased this book, I'm just a fan).

The original port of sock was done by Mike Borella but didn't compile on my system (gcc 4.8.4+). I fixed all the errors and warnings and used [GNU indent] (https://www.gnu.org/software/indent/manual/indent.html) to reformat the source code consistently.

Please note that I do not hold the Copyright over this program. The program is copyrighted by Mr. Stevens, but allowed free use as long as properly attributed (see the LICENSE) file for details.

Compiling

To compile the program, just type:

$ ./configure
$ make
$ sudo make install

Pull requests

Times change, and so do compilers and systems. If you manage to patch a problem in this program, send me a pull request and I will incorporate it back into the repository. I recommend using GNU indent to reformat your sources before opening the pull request. The recommended indent invocation is:

indent -l128 --no-tabs --tab-size4 --indent-level4 --braces-on-if-line \
       --cuddle-else --braces-on-func-def-line --braces-on-struct-decl-line \
       --cuddle-do-while --no-space-after-function-call-names \ 
       --no-space-after-parentheses --dont-break-procedure-type *.c
from https://github.com/marcopaganini/sock
 
 

No comments:

Post a Comment