Help answer threads with 0 replies.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 12-13-2006, 07:40 PM   #1
Registered: May 2006
Posts: 69

Rep: Reputation: 16
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?
Old 12-13-2006, 09:25 PM   #2
Senior Member
Registered: Nov 2003
Location: Perth, Western Australia
Distribution: Ubuntu, Debian, Various using VMWare
Posts: 2,088

Rep: Reputation: 62
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(...);


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP UNIX Domain Socket Programming anamericanjoe Programming 2 12-08-2006 03:10 AM
unix/socket programming, which book should i read first ??? b0nd Linux - General 2 05-06-2006 01:47 AM
ERROR reading from socket: Bad address cynthia_thomas Programming 1 02-18-2006 08:02 AM
function recv() in socket husniteja Programming 1 08-18-2004 10:06 AM
Unix socket programming - how to sent a file Scrag Programming 9 03-28-2004 10:54 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:33 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration