LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 12-13-2006, 06:40 PM   #1
anamericanjoe
Member
 
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...

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

Rep: Reputation: 61
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
 
  


Reply


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 02:10 AM
unix/socket programming, which book should i read first ??? b0nd Linux - General 2 05-06-2006 12:47 AM
ERROR reading from socket: Bad address cynthia_thomas Programming 1 02-18-2006 07:02 AM
function recv() in socket husniteja Programming 1 08-18-2004 09:06 AM
Unix socket programming - how to sent a file Scrag Programming 9 03-28-2004 09:54 PM


All times are GMT -5. The time now is 12:13 PM.

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