Re: [ROOT] TServerSocket bug?

From: Fons Rademakers (Fons.Rademakers@cern.ch)
Date: Sun Nov 18 2001 - 22:44:22 MET


Hi Xavier,

   interesting. Firstly, the TServerSocket connects correctly to the
specified port. What goes wrong is the TServerSocket::GetLocalPort()
call. This call uses getsockname() to get the port to which the
server socket is bound. The returned port number is in network byte
order and is converted to host byte order before passing it to 
the TInetAddress class which returns the number you print. Now for
all ports except the ones that fail the port number is, as expected,
in network byte order. However, for the ones that fail the getsockname()
returns the port in host byte order (!), which then get swapped again
resulting in the error. Check for example 10005, if you swap its
two bytes you get 5415, idem for the others. I don't know directly
a solution for this problem? Anybody knows what is going on? What
is special about some of these ports? I tried this on RH7.1 with kernel
2.4.10.

Cheers, Fons.


On Saturday 17 November 2001 17:47, Xavier Bertou wrote:
> Hi all,
> this small program:
>
> #include "TROOT.h"
> #include "TServerSocket.h"
> #include <stdlib.h>
> #include <stdio.h>
>
> TROOT TRoot ("Test","My test");
>
> int main()
> {
> 	for (int i=10000;i<20000;i++) {
> 		TServerSocket *ss=new TServerSocket(i,kTRUE);
> 		if (ss->IsValid() && ss->GetLocalPort()!=i)
> 			printf("ROOT took %d instead of %d!!!\n",ss->GetLocalPort(),i);
> 		delete ss;
> 	}
> 	return 0;
> }
>
> Gives the following output on a few different computers:
> lpnp256 ~  gcc `root-config --cflags` a.cc `root-config --libs`
> lpnp256 ~  ./a.out
> ROOT took 5415 instead of 10005!!!
> SysError in <TUnixSystem::UnixTcpService>: bind (Permission denied)
> ROOT took 1064 instead of 10244!!!
> ROOT took 1320 instead of 10245!!!
> ROOT took 1576 instead of 10246!!!
> ROOT took 1832 instead of 10247!!!
> [...]
>
> In particular, once a port has been found, it is very simple to reproduce
> the bug:
> lpnp256 ~  /Raid/opt/root/bin/root
> [...]
> root [0] TServerSocket *ss=new TServerSocket(10005)
> root [1] ss->GetLocalPort()
> (Int_t)5415
>
> Of course, I can bind this port with a simple 'nc -l -p 10005' and it
> works perfectly.
>
> This happens with all the root versions installed on our computers (from
> 2.25 to 3.02.03). The output is not dependant on the root version, but
> depends on the machine, and the ports on which the error is seen are
> different on our Mandrake 7.0, 7.2 and 8.1 boxes, on Pentium II or III
> Pcs. They all are stock mandrake distributions, and root has been
> compiled on them with the basic compiler of the distribution and with the
> configuration:
> ./configure linuxegcs --prefix=$DIR --libdir=$DIR/lib --incdir=$DIR/include
> --mandir=$DIR/man/man1 --etcdir=$DIR/etc --docdir=$DIR/doc
> --datadir=$DIR/share --enable-rpath
>
> Any idea? Anyone able to reproduce that on other architectures?

-- 
Org:    CERN, European Laboratory for Particle Physics.
Mail:   1211 Geneve 23, Switzerland
E-Mail: Fons.Rademakers@cern.ch              Phone: +41 22 7679248
WWW:    http://root.cern.ch/~rdm/            Fax:   +41 22 7679480



This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:51:08 MET