Can someone tell me what I'm doing wrong?

Ray Van Dolson rayvd at bludgeon.org
Wed May 23 05:17:24 GMT 2001


Well, I think you guys were right...  here is the source file I am
currently using and seems to have fixed my probs.

#include <stdio.h>
#include <errno.h>
#include <sys/time.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <libsmbclient.h>

#define MAX_BUFF_SIZE 255
#define WORKGROUP "STUDENTS"
#define USERNAME "Guest"
#define PASSWORD ""

void auth_fn(const char *server, const char *share, char *workgroup, int wgmaxlen, char *username, int unmaxlen, char *password, int pwmaxlen) {
	strncpy(workgroup,WORKGROUP,strlen(WORKGROUP)+1);
	strncpy(username,USERNAME,strlen(USERNAME)+1);
	strncpy(password,PASSWORD,strlen(PASSWORD));
}

// This is the function being wrapped
int directory_list(char *url, char *dirs[512]) {
	int error, dirHandle, i;
	char dirbuff[MAX_BUFF_SIZE];
	struct smbc_dirent *dirStruct;
//	char *tmp[512];

//	for (i = 0; i < 512; i++)
//		dirs[i] = (char *)malloc(255);

	dirStruct = (struct smbc_dirent *) dirbuff;
	error = smbc_init(auth_fn, 10);

	printf("The URL passed is: %s\n",url);

	i = 0;
	dirHandle = smbc_opendir(url);
//	printf("The directory handle is: %d\n",dirHandle);
//	printf("Looping...\n");
	while (dirStruct = smbc_readdir(dirHandle)) {
//		printf("Starting loop %d ... \n",i+1);
//		printf("%s which is %d chars long\n",dirStruct->name,dirStruct->namelen);
		strncpy(dirs[i++], dirStruct->name, 255);
//		printf("Finished!\n");
	}
	dirs[i][0] = '\0';
//	printf("The value we shall return is %d\n",i);
	return i;
}

int main(int argc, char** argv) {
	char *directories[512];
	int i,count;

	for (i = 0; i < 512; i++)
		directories[i]=(char*)malloc(255);

	i = 0;
	i = directory_list(argv[1],directories);
	for (count = 0; count < i; count++) {
		printf("%s\n",directories[count]);
	}
	printf("Total: %d files\n",i);

	for (i = 0; i < 512; i++)
		free(directories[i]);
}






More information about the samba-technical mailing list