-   Programming (
-   -   recv: Bad address (UNIX Socket programming) (

anamericanjoe 12-13-2006 06:40 PM

recv: Bad address (UNIX Socket programming)
I'm working on sending messages from a client program to a server using UNIX domain sockets. I am using send and recv to pass messages.

I have a pointer to an array of char pointers...


char* args[3];
 * Fill the array with strings appropriately...

Later, I try to send this pointer from my client to my server like so:


int send_status = send(socket_descriptor, args, sizeof(args), FLAGS);
On the server side, I am receiving the message like this:


char** str;
message_length = recv(connected_socket_descriptor, str, MESSAGE_SIZE, FLAGS);

Everything compiles fine, but when I eventually try to pass a message from my client to my server I get the error message


recv: Bad address
Thanks to Google Groups, I was able to determine that


...the message refers to the address of the receive buffer.
Perhaps you have an uninitialized pointer?
Which means that str in my server's recv command is somehow uninitialized. What does that mean? How can I avoid fix it? How can I avoid it in the future?

IBall 12-13-2006 08:25 PM

From memory, you don't want a pointer to a string, you just want a string. Also, in C you need to set a size for the string, so memory can be allocated. Say you "#define MAXLINE 4096" Therefore:

char str[MAXLINE];
message_length = recv(...);


All times are GMT -5. The time now is 08:56 AM.