Less than 42 API calls.
Documented
Less than 150KB stripped
Low memory footprint
Only 2 dependencies
Only POSIX calls
Dual LGPL
and commercial licensing
/* SMB Connect, login and read file example */
#include <arpa/inet.h>
#include <stdio.h>
#include <bsdm/bdsm.h>
int main()
{
struct in_addr addr;
smb_session *session;
smb_tid tid;
smb_fd fd;
session = smb_session_new();
if (session == NULL)
exit(1);
inet_aton("127.0.0.1", &addr.sin_addr);
if (smb_session_connect(session, "MYNAME",
addr.sin_addr.s_addr, SMB_TRANSPORT_TCP))
{
printf("Unable to connect to host\n");
exit(2);
}
smb_session_set_creds(session, "MYNAME", "login",
"password");
if (smb_session_login(session))
{
if (session->guest)
printf("Logged in as GUEST \n");
else
printf("Successfully logged in\n");
}
else
{
printf("Auth failed\n");
exit(3);
}
tid = smb_tree_connect(session, "MyShare");
if (!tid)
{
printf("Unable to connect to share\n");
exit(4);
}
fd = smb_fopen(session, tid, "\\My\\File");
if (!fd)
{
printf("Unable to open file\n");
exit(5);
}
char buffer[512];
smb_fread(session, fd, buffer, 512);
/* Use data */
smb_fclose(session, fd);
smb_tree_disconnect(session, tid);
smb_session_destroy(session);
return(0);
}
/* Netbios Discover */
#include <stdio.h>
#include <bsdm/bdsm.h>
static void print_entry(const char *what, void *p_opaque,
netbios_ns_entry *entry)
{
struct in_addr addr;
addr.s_addr = netbios_ns_entry_ip(entry);
printf("%s(%p): Ip: %s, name: %s/%s<%x>\n",
what,
p_opaque,
inet_ntoa(addr),
netbios_ns_entry_group(entry),
netbios_ns_entry_name(entry),
netbios_ns_entry_type(entry));
}
static void on_entry_added(void *p_opaque,
netbios_ns_entry *entry)
{
print_entry("added", p_opaque, entry);
}
static void on_entry_removed(void *p_opaque,
netbios_ns_entry *entry)
{
print_entry("removed", p_opaque, entry);
}
int main()
{
netbios_ns *ns;
netbios_ns_discover_callbacks callbacks;
ns = netbios_ns_new();
callbacks.p_opaque = (void*)0x42;
callbacks.pf_on_entry_added = on_entry_added;
callbacks.pf_on_entry_removed = on_entry_removed;
printf("Discovering...\nPress Enter to quit\n");
if (!netbios_ns_discover_start(ns,
4, // broadcast every 4 sec
&callbacks))
{
fprintf(stderr, "Error while discovering local network\n");
exit(42);
}
getchar();
netbios_ns_discover_stop(ns);
return (0);
}
While the most up-to-date documentation can be found in the README of the project on the github page, here's a brief summary
$> ./bootstrap $> ./configure --prefix=/usr/local/libdsm $> make && make install