how is buf declared in that client function? If buf is declared as char* then sizeof(buf) is always 4 on 32-bit compilers.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
buffer=files[i-1]->d_name;
rebruk = write(sock, buffer, sizeof(files));
I think this is also wrong. buffer is a pointer to d_name, but attempting to write sizeof(files) number of bytes. If files is an array of pointers to structures, then sizeof(files) will be 4 * number of pointers in that array. You probably mean this, unless files[i-1]->d_name is also a pointer.
buffer=files[i-1]->d_name;
rebruk = write(sock, buffer, sizeof(files[i-1]->d_name));
In that case why use buffer at all
rebruk = write(sock, files[i-1]->d_name, sizeof(files[i-1]->d_name));
If d_name is also a pointer, then you should probably replace the sizeof() with strlen(d_name)+1
In that case why use buffer at all
rebruk = write(sock, files[i-1]->d_name, strlen(files[i-1]->d_name)+1);
Now for the client side:
Since buf is a pointer, did you allocate memory for it, or what does it point to? please post code for this.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
>>Should I allocate memory for it
not necessary -- what you posted is ok.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343