libsmbclient: Connection reset by peer when reconnecting to a
host.
derrell at samba.org
derrell at samba.org
Wed Nov 16 22:34:19 GMT 2005
Tim Hutt <tdh29 at cam.ac.uk> writes:
> On Thursday 10 November 2005 23:19, derrell at samba.org wrote:
>> Tim Hutt <tdh29 at cam.ac.uk> writes:
>> > Hi,
>> >
>> > I've written a simple smb search engine that crawls some subnets (172.31.
>> > [57-60,65].*) on my network.
>> >
>> > Unfortunately after it has gone through one scan any subsequent
>> > connection attempts say connection reset by peer.
>>
>> ...
>>
>> context = smbc_set_context(NULL); /* retrieve current context */
>> smbc_free_context(context, TRUE); /* close all cached connections */
>> if (smbc_init(your_auth_data_fn, debug_level) != 0) {
>> printf("We've got problems\n");
>> /* Handle the error */
>> }
>>
>> ...
>>
>> Please indicate in the bugzilla report if the above helped solve the
>> problem, to narrow down what I need to look at.
>
> Ok, I added it as bug 3257: https://bugzilla.samba.org/show_bug.cgi?id=3257
Thanks.
> The thing you suggested didn't help though... Any other suggestions?
Not off hand. Do you get the same problem if you connect repeatedly to a
smaller number of servers? If so, does the problem happen after the same
(approximate) number of connections as in your original test?
> Also, I have some more general questions about libsmbclient:
>
> a) Is it at all thread safe? What if I use more than one context?
The internals of Samba, as used by the client library, are not thread safe.
I'd stick with separate processes rather than threads if you need multiple
concurrent access.
Although using multiple contexts makes the top layer of the client library
somewhat thread safe, it's calling lots of deeper code which was never built
to be thread safe.
> b) What is a context?
It's initialization state and cached connection state. There are default
callback functions and default values for context variables. You can change
some of those, as your application requires. See libsmbclient.h for an
explanation of the context structure (struct _SMBCCTX).
> c) Do you have to actually fill in all the callbacks in the context thing or
> can you leave them as NULL so that it uses some default implementation?
The callbacks need to be set, but they are initialized to defaults for you by
smbc_new_context() which is called by smbc_init().
> d) Is there a way to get the NetBIOS name from an IP using libsmbclient?
Probably, but that one I'd have to research. I don't recall ever trying to do
that. You can get the NetBIOS name using "nmblookup -S" so if you look at the
source code to nmblookup, you may be able to figure out what libsmbclient
functions you'd have to call to do something similar.
Cheers,
Derrell
ps. Please continue to cc: samba-technical on further questsions/discussion,
so it's all saved in the archive.
More information about the samba-technical
mailing list