NetServerEnum2 from libsmbclient on port 445.
Stephan Kulow
coolo at kde.org
Tue Apr 8 13:53:02 GMT 2003
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.
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);
}
More information about the samba-technical
mailing list