Nmap Development mailing list archives

Re: Ncat: socket bind error on Mac OS X


From: Kris Katterjohn <katterjohn () gmail com>
Date: Sun, 27 Jul 2008 17:48:22 -0500

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

David Fifield wrote:
On Sun, Jul 27, 2008 at 01:14:40PM +0200, Dirk Loss wrote:
on Mac OS X 10.5.4 (Intel) Ncat dies with the following error when I try 
to put it into listening mode:

$ ncat -l 22222
bind: Invalid argument

Running Ncat as root, switching to UDP or disabling IPv6 in my system 
preferences did not help. I verified that there is no other process 
listing on my local TCP port 22222.

Apparently the bind() call in sys_wrap.c returns -1 and errno = 22 
(EINVAL). According to the man page [1], this means that either the 
"socket is already bound to an address and the protocol does not support 
binding to a new address" or the "socket may have been shut down."

I think I have tracked this down. bind is being picky about the address
length. Currently do_listen is calling Bind with sizeof(srcaddr), which
is 128. If I change it to sizeof(struct sockaddr_in), which is 16, then
it works. Of course, that only works for IPv4 addresses, so it needs to
be based on the address family.


Good catch!  This was definitely a mistake on my part when adding IPv6
listening functionality.

BSDs have an extra sockaddr.sa_len (and sockaddr_storage.ss_len, and
sockaddr_in.sin_len) member. Currently it's always set to 0 by memset. I
tried setting it to a proper value and it didn't seem to make a
difference. However, changing the address length passed to bind did
work.


Sounds like a plan.  I'll commit a fix in a minute.

David Fifield


Thanks,
Kris Katterjohn

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iQIVAwUBSIz7NP9K37xXYl36AQLW+Q/8DxIzOBY5YijosTl3kw3b5j/xJcbDlRT7
1GCHzlp/m8NMVmhvXpU9XWbVoO1hTNH+Ar47Bm6aQTR3hsaEYM1uE++o1Z8iXDMQ
qCoLVIhGoGzVnFndqMSAt/+lk4DwlaXl35KTXFwXT32kDAqq0ADgtPf+NonLzit6
4bF9XTC3r2G0/1Z9hi2JDYOV06vfUnnnx6b/+/hGezP6iqnzvMmJcTzOD76HvUNp
oekSaFzEAg6UiUCBoFS3dW1MOpkurFiG9oyIJfOuEwCfYRGG5vBKi6yzxPJeLug9
DvlE7y4KL3rQ8DjcwtSxFz4eXo0UApmTfo9j6deUJRcVIvi7yZczt13qp53cPvQX
zMDu5dowIP31/q7BUe4wC69wq8qx46ypj7N9EpmYysqFL/G4ao6uW6T9lRzCg7vB
cDwQ+0W2n4vQHjq5CnpUGjjKw6bFIXU8PgIjP/iWjLa5+MOuCMKCMH02w1SgQqu4
fE5MW9hVdDgBNPVOJIULtAlh0O1IA119wJngJKY0p1qjF8FgZdufrPCPettJ7Szb
sXCfeHvTSz1IoQFgTjnRd7xTmys1LJROIsAZ594ueYBHDjELVQogxweFCpH+tNnd
66KUS48pD7S/CQDHYycPv9dsII0iP/79wi1RTsTd3Nw09YA1G78rD4c6vLgz7Ibw
nLqhWnkI9ns=
=pfKm
-----END PGP SIGNATURE-----

_______________________________________________
Sent through the nmap-dev mailing list
http://cgi.insecure.org/mailman/listinfo/nmap-dev
Archived at http://SecLists.Org


Current thread: