[jcifs] Cannot assign requested address

Michael B Allen mba2000 at ioplex.com
Fri Aug 19 20:21:39 GMT 2005


On Thu, 11 Aug 2005 02:20:11 -0400
Michael B Allen <mba2000 at ioplex.com> wrote:

> On Wed, 10 Aug 2005 17:39:06 +0200
> Mathias Dietz <MDIETZ at de.ibm.com> wrote:
> 
> > with jcifs 1.2.1 I get the following error message when I try to connect to
> > a samba share. (using fedora core 4 and java 1.5)
> > jcifs.util.transport.TransportException
> > java.net.SocketException: Invalid argument or cannot assign requested
> > address
> >       at java.net.PlainSocketImpl.socketConnect(Native Method)
> >       ......
> >       at jcifs.smb.SmbTransport.negotiate(SmbTransport.java:228)
> >       at jcifs.smb.SmbTransport.doConnect(SmbTransport.java:266)
> >       at jcifs.util.transport.Transport.run(Transport.java:204)
> >       at java.lang.Thread.run(Thread.java:568)
> > 
> > After some testing and debugging I found that the problem does not occur
> > with jcifs 1.1.11.
> > With jcifs 1.2.1 the config class has been changed to the following:
> > 
> >     public static InetAddress getLocalHost() {
> >         String addr = prp.getProperty( "jcifs.smb.client.laddr" );
> >         try {
> >             if( addr == null ) {
> >   --->>>            return InetAddress.getLocalHost();     <<<----
> >             }
> >             return InetAddress.getByName( addr );
> >         } catch( UnknownHostException uhe ) {
> >             if( log.level > 0 ) {
> >                 log.println( addr );
> >                 uhe.printStackTrace( log );
> >         }   }
> >         return null;
> >     }
> > 
> > If no jcifs.smb.client.laddr is specified, then localhost/127.0.0.1 is
> > returned and
> > SMBTransport uses the returned value to create a socket.
> >  ->>  socket = new Socket( address.getHostAddress(), port, localAddr,
> > localPort );
> > 
> > This is not possible because the samba server is not reachable via
> > 127.0.0.1 (NoRouteToHost!).
> > 
> > Could someone fix this bug ? Possible solutions:
> >       A) change the Config.getLocalHost() method to return null if no
> > jcifs.smb.client.laddr is specified
> >       B) change SMBTransport and replace LADDR with Config.getInetAddress(
> > "jcifs.smb.client.laddr", null )  (jcifs 1.1.11 like)
> 
> Nice analysis. This bug is on The List but I had not really looked at
> it closely yet. I think your diagnosis will be helpful. If 1.1.11 really
> used option B then I think that is the way to go.

This is fixed. An SmbTransport.localAddr of null indicates the default
interface rather than trying to use InetAddress.getLocalHost(). Although
in 1.1 we used the four parameter Socket constructor with a the null
for localAddr. That worked but just to be safe I have added a clause
the uses the two parameter constructor if localAddr is null.

Mike


More information about the jcifs mailing list