akr/socket-test
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
= socket test commands == Home Page https://github.com/akr/socket-test == Build % git clone git://github.com/akr/socket-test.git % cd socket-test % ./configure CFLAGS='-g -O0 -Wall' # [optional] -Wall assumes gcc. % make == Usage % ./unix-stream -h usage: unix-stream [options] server-path [connect-path [client-path]] option: -h : show this help message -U : don't unlink sockets. -c : test in the current directory. -s : server only test mode. -p : prepend sizeof(sun_path)-10 characters for socket-path. -g N : buffer size for getsockname/getpeername/accept (no sign means exact. +N for increase and -N for decrease from sockaddr_un) -4 : show 4.4BSD sun_len field == Results Some of the results are shown in below. * Table: http://htmlpreview.github.com/?https://github.com/akr/socket-test/blob/master/results/index.html * Raw results: https://github.com/akr/socket-test/tree/master/results == Example ./unix-stream command takes "escaped" pathnames for Unix domain sockets. The escape notation is similar to ANSI C with run length compression. The parenthesized part, (integer * "string"), means _integer_ times repeatation of "string". Debian GNU/Linux 7.0 (wheezy) : linux% uname -mrsv Linux 3.2.0-4-amd64 #1 SMP Debian 3.2.35-2 x86_64 linux% ./size sizeof(sockaddr)=16 offsetof(sa_family)=0 sizeof(sa_family)=2 offsetof(sa_data)=2 sizeof(sa_data)=14 sizeof(sockaddr_un)=110 offsetof(sun_family)=0 sizeof(sun_family)=2 offsetof(sun_path)=2 sizeof(sun_path)=108 sizeof(sockaddr_in)=16 offsetof(sin_family)=0 sizeof(sin_family)=2 offsetof(sin_port)=2 sizeof(sin_port)=2 offsetof(sin_addr)=4 sizeof(sin_addr)=4 sizeof(sockaddr_in6)=28 offsetof(sin6_family)=0 sizeof(sin6_family)=2 offsetof(sin6_port)=2 sizeof(sin6_port)=2 offsetof(sin6_flowinfo)=4 sizeof(sin6_flowinfo)=4 offsetof(sin6_addr)=8 sizeof(sin6_addr)=16 offsetof(sin6_scope_id)=24 sizeof(sin6_scope_id)=4 sizeof(sockaddr_storage)=128 offsetof(ss_family)=0 sizeof(ss_family)=2 linux% ./unix-stream 'foo' './foo' bind(server) <- "foo" (3 bytes) getsockname(server) -> "foo\0" (4 bytes) # Linux complements a NUL. getsockname(client) -> "" (0 bytes) # sun_family only sockaddr_un for anonymous Unix domain socket. connect <- "./foo" (5 bytes) getpeername(client) -> "foo\0" (4 bytes) # getpeername returns the name given for bind(). accept -> "" (0 bytes) getsockname(accepted) -> "foo\0" (4 bytes) getpeername(accepted) -> "" (0 bytes) linux% ./unix-stream -s '(10*"0123456789")0123456' bind(server) <- "(10*"0123456789")0123456" (107 bytes) getsockname(server) -> "(10*"0123456789")0123456\0" (108 bytes) linux% ./unix-stream -s '(10*"0123456789")01234567' bind(server) <- "(10*"0123456789")01234567" (108 bytes) getsockname(server) -> "(10*"0123456789")01234567"... (109 bytes) linux% ./unix-stream -s '(10*"0123456789")012345678' bind(server) <- "(10*"0123456789")012345678" (109 bytes) bind(server): Invalid argument (EINVAL) linux% ./unix-stream -s /etc/hosts bind(server) <- "/etc/hosts" (10 bytes) bind(server): Address already in use (EADDRINUSE) linux% ./unix-stream -s /etc bind(server) <- "/etc" (4 bytes) bind(server): Address already in use (EADDRINUSE) linux% ./unix-stream -s / bind(server) <- "/" (1 bytes) bind(server): Address already in use (EADDRINUSE) # EADDRINUSE for the root directory. linux% ./unix-stream -s /foo bind(server) <- "/foo" (4 bytes) bind(server): Permission denied (EACCES) linux% ./unix-stream -s '' bind(server) <- "" (0 bytes) getsockname(server) -> "\000005" (6 bytes) # Linux "autobind" feature binds a socket to a fresh name in abstract name space. linux% ./unix-stream -s '' bind(server) <- "" (0 bytes) getsockname(server) -> "\000006" (6 bytes) # Linux "autobind" feature linux% ./unix-stream '\0abc' # Linux "abstract name space" begins with "\0" bind(server) <- "\0abc" (4 bytes) getsockname(server) -> "\0abc" (4 bytes) getsockname(client) -> "" (0 bytes) connect <- "\0abc" (4 bytes) getpeername(client) -> "\0abc" (4 bytes) accept -> "" (0 bytes) getsockname(accepted) -> "\0abc" (4 bytes) getpeername(accepted) -> "" (0 bytes) linux% ./unix-stream '\0abc' '\0abc\0' bind(server) <- "\0abc" (4 bytes) getsockname(server) -> "\0abc" (4 bytes) getsockname(client) -> "" (0 bytes) connect <- "\0abc\0" (5 bytes) connect: Connection refused (ECONNREFUSED) # Linux "abstract name space" treats NUL as usual character. FreeBSD 9.1 : freebsd% uname -mrsv FreeBSD 9.1-RELEASE FreeBSD 9.1-RELEASE #0 r243825: Tue Dec 4 09:23:10 UTC 2012 root@farrell.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC amd64 freebsd% ./size sizeof(sockaddr)=16 offsetof(sa_len)=0 sizeof(sa_len)=1 # 4.4BSD has s*_len field. offsetof(sa_family)=1 sizeof(sa_family)=1 offsetof(sa_data)=2 sizeof(sa_data)=14 sizeof(sockaddr_un)=106 offsetof(sun_len)=0 sizeof(sun_len)=1 offsetof(sun_family)=1 sizeof(sun_family)=1 offsetof(sun_path)=2 sizeof(sun_path)=104 sizeof(sockaddr_in)=16 offsetof(sin_len)=0 sizeof(sin_len)=1 offsetof(sin_family)=1 sizeof(sin_family)=1 offsetof(sin_port)=2 sizeof(sin_port)=2 offsetof(sin_addr)=4 sizeof(sin_addr)=4 sizeof(sockaddr_in6)=28 offsetof(sin6_len)=0 sizeof(sin6_len)=1 offsetof(sin6_family)=1 sizeof(sin6_family)=1 offsetof(sin6_port)=2 sizeof(sin6_port)=2 offsetof(sin6_flowinfo)=4 sizeof(sin6_flowinfo)=4 offsetof(sin6_addr)=8 sizeof(sin6_addr)=16 offsetof(sin6_scope_id)=24 sizeof(sin6_scope_id)=4 sizeof(sockaddr_storage)=128 offsetof(ss_len)=0 sizeof(ss_len)=1 offsetof(ss_family)=1 sizeof(ss_family)=1 freebsd% ./unix-stream foo ./foo bind(server) <- "foo" (3 bytes) getsockname(server) -> "foo" (3 bytes) # FreeBSD doesn't complement a NUL. getsockname(client) -> "(14*"\0")" (14 bytes) # 14 NULs returned for anonymous Unix domain socket. connect <- "./foo" (5 bytes) getpeername(client) -> "foo" (3 bytes) # getpeername returns the name given for bind(). accept -> "(14*"\0")" (14 bytes) getsockname(accepted) -> "foo" (3 bytes) getpeername(accepted) -> "(14*"\0")" (14 bytes) freebsd% ./unix-stream -s '(10*"0123456789")012' bind(server) <- "(10*"0123456789")012" (103 bytes) getsockname(server) -> "(10*"0123456789")012" (103 bytes) freebsd% ./unix-stream -s '(10*"0123456789")0123' bind(server) <- "(10*"0123456789")0123" (104 bytes) getsockname(server) -> "(10*"0123456789")0123" (104 bytes) freebsd% ./unix-stream -s '(10*"0123456789")01234' bind(server) <- "(10*"0123456789")01234" (105 bytes) bind(server): Invalid argument (EINVAL) freebsd% ./unix-stream -s /etc/hosts bind(server) <- "/etc/hosts" (10 bytes) bind(server): Address already in use (EADDRINUSE) freebsd% ./unix-stream -s /etc bind(server) <- "/etc" (4 bytes) bind(server): Address already in use (EADDRINUSE) freebsd% ./unix-stream -s / bind(server) <- "/" (1 bytes) bind(server): Is a directory (EISDIR) # EISDIR for the root directory. freebsd% ./unix-stream -s /foo bind(server) <- "/foo" (4 bytes) bind(server): Permission denied (EACCES) freebsd% ./unix-stream -s '' # EINVAL for empty path. bind(server) <- "" (0 bytes) bind(server): Invalid argument (EINVAL) == License Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: (1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. (2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. (3) The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. (The modified BSD licence)
About
socket test commands
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published