// gcc -Wall -o smbtest smbtest.c -lsmbclient #define _GNU_SOURCE #include #include #include #include static void auth_fn(const char *server, const char *share, char *workgroup, int wgmaxlen, char *username, int unmaxlen, char *password, int pwmaxlen) { printf ("auth_fn called:\n" "server: %s\n" "share: %s\n" "wgroup: %s\n\n", server, share, workgroup); } int main (int argc, char **argv) { struct smbc_dirent *entry; int err, fd; err = smbc_init (auth_fn, 10); if (err < 0) { char *str; str = strerror (err); printf ("smbc_init: %s\n", str); free (str); return 1; } fd = smbc_opendir ("smb://"); if (fd < 0) { perror ("smbc_opendir"); return 1; } entry = smbc_readdir (fd); while (entry != NULL) { char *name; name = strndup (entry->name, entry->namelen); printf ("read %s\n", name); free (name); entry = smbc_readdir (fd); } smbc_closedir (fd); return 0; }