LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   recv: Bad address (UNIX Socket programming) (http://www.linuxquestions.org/questions/programming-9/recv-bad-address-unix-socket-programming-510194/)

anamericanjoe 12-13-2006 07: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...

Code:

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

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

Code:

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

Code:

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

Quote:

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

Quote:

...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 09: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:
Code:

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

--Ian


All times are GMT -5. The time now is 05:57 AM.