Looking for a tiny smb library ?

--You're at the right place

Discover libdsm



Simple

Less than 42 API calls.

Documented

Lightweight

Less than 150KB stripped

Low memory footprint

Portable

theorically

Only 2 dependencies

Only POSIX calls

Open-Source

Dual LGPL

and commercial licensing

Top

Features

  • Speaking SMB v1
  • Read-only client
  • Discover hosts
  • List shares
  • List folders
  • Read files
  • Transport
    • Netbios over TCP
    • Direct-TCP
  • Server compatibility
    • Samba 3 & 4
    • Apple SMBX
    • Windows 7 & 8
    • older Windows untested
  • Netbios
    • Name lookup
    • Reverse lookup
  • Supported system
    • Linux
    • OSX
  • pkg-config enabled
  • Unicode path support
Top

Examples

/* 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);
}
Click here for complete code of examples.
Top

Documentation

Building

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

Requirements

  • A Unix system with a shell
  • A C99 compiler (gcc and clang tested)
  • autotools
  • libiconv
  • libtasn1
  • doxygen to generate documentation
  • getopt_long for example programs

Building

Here you just have to roll the traditional
$> ./bootstrap
$> ./configure --prefix=/usr/local/libdsm
$> make && make install

API Documentation

You can find a few examples in the bin/ folder of the source code but you'll likely enjoy the extensive API documentation you can fond by clicking the link below:

Download

You can download one of our stable release as a tarbal by clicking on the following link
Last stable release : 0.0.4

View the releases
If you're more of a warrior or want to contribute, you can find this project's code on GitHub. As always Pull Requests are always welcome :)

Fork me on GitHub
Top

Contact us

Having some troubles with libdsm ?

Please browse the existing issues on GitHub and, if you doesn't find a solution to your problem, you can open a new one.
For other concerns, you can mail 'contact' _AT_ lta _DOT_ io
Top