NetServerEnum2 from libsmbclient on port 445.
Christopher R. Hertel
crh at ubiqx.mn.org
Tue Apr 8 14:05:51 GMT 2003
Stephan Kulow wrote:
>
> On Tuesday 08 April 2003 14:31, Derrell.Lipman at UnwiredUniverse.com wrote:
> > "Christopher R. Hertel" <crh at ubiqx.mn.org> writes:
> >
> > > This is an interesting area of study. The NetServerEnum2() function
> > > call is supposed to return a list of NetBIOS names. SMB on port 445
> > > is NetBIOS-less SMB. In theory, it makes some sort of sense that a
> > > NetServerEnum2() call via port 445 would not return any NetBIOS server
> > > names.
> >
> > I had this issue in smbwrapper as well. After some discussion with people on
> > this list, I came to the following solution which has worked well for me so
> > far.
> >
> > /* Force use of port 139 for first try, so browse lists can work*/
> > c.port = 139;
> >
> > /* Attempt to connect */
> > if (!cli_connect(&c, server_n, &ip)) {
> > /*
> > * Port 139 connection failed. Try port 445 to handle
> > * connections to newer (e.g. XP) hosts with NetBIOS disabled.
> > */
> > c.port = 445;
> > if (!cli_connect(&c, server_n, &ip)) {
> > errno = ENOENT;
> > free(username);
> > free(workgroup);
> > free(password);
> > return NULL;
> > }
> > }
> >
> Which arises the question why 445 is tried first. Reading http://www.ubiqx.org/cifs/SMB.html
:)
> the only hint I could find was "Running naked is probably the easiest
> transport test to try first", but I can't really find a reason not to try
> 139 first instead.
Since the NetServerEnum2 call returns a list of NetBIOS names it makes sense
that you'd only try it on the NBT port (unless the user specifically asks
for a different port, eg: smb://workgroup:445/)
Otherwise, I have found that there is a lot of argument regarding the
'right' way to go through the list of options. Some are quick, but fail
badly, others are difficult to set up. It's all a matter of taste, really,
so I tried to provide a guide in that section, not a rule. There's no
really good rule in that case.
Thanks for reading!
Chris -)-----
PS... Can someone else on Team take a look at the patch? I've pulled two
all-nighters already this week trying to finish my book.
> Otherwise the attached patch might be the cleaner version.
>
> Greetings, Stephan
>
> --- libsmb/cliconnect.c 4 Apr 2003 23:39:16 -0000 1.135
> +++ libsmb/cliconnect.c 8 Apr 2003 13:52:25 -0000
> @@ -1109,12 +1109,12 @@ BOOL cli_connect(struct cli_state *cli,
> if (getenv("LIBSMB_PROG")) {
> cli->fd = sock_exec(getenv("LIBSMB_PROG"));
> } else {
> - /* try 445 first, then 139 */
> - int port = cli->port?cli->port:445;
> + /* try 139 first, then 445 */
> + int port = cli->port?cli->port:139;
> cli->fd = open_socket_out(SOCK_STREAM, &cli->dest_ip,
> port, cli->timeout);
> if (cli->fd == -1 && cli->port == 0) {
> - port = 139;
> + port = 445;
> cli->fd = open_socket_out(SOCK_STREAM, &cli->dest_ip,
> port, cli->timeout);
> }
--
Samba Team -- http://www.samba.org/ -)----- Christopher R. Hertel
jCIFS Team -- http://jcifs.samba.org/ -)----- ubiqx development, uninq.
ubiqx Team -- http://www.ubiqx.org/ -)----- crh at ubiqx.mn.org
OnLineBook -- http://ubiqx.org/cifs/ -)----- crh at ubiqx.org
More information about the samba-technical
mailing list