Socket Accept Problems
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > Socket Accept Problems




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    Socket Accept Problems  
Matt Churchyard


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-23-04 10:21 PM

Hi,

I am having problems accepting connections on a socket.
The accept call returns a 'Bad Address' error which as far as i can see
means "The addr parameter is not in a writable part of the user address
space."

I cannot understand why this could be as the addr structure is allocated
using
malloc which (if i am thinking correctly?) will not return an address
outside the user range.

Heres the code thats causing the problem

===============================
// create space for client address
client.address = (struct sockaddr_in *)malloc(sizeof(struct
sockaddr_in));

if( client.address == NULL )
{
syslog(LOG_ERR, "Couldn't allocate memory for client address
structure");
return;
}

// wait for clients
NEXTCLIENT:
while((client.socket = accept(server.socket, (struct sockaddr
*)client.address, &client_len)))
{
// check socket
if( client.socket < 0 )
{
perror("Socket Failed");

goto NEXTCLIENT;
}
===============================

Any help is greatly appreciated

Thanks,
Matt

--

Regards,
Matt Churchyard
_______________________________
Project Development Manager
Userve Internet
matt@userve.net
http://www.userve.net/







[ Post a follow-up to this message ]



    Re: Socket Accept Problems  
Nils O. examnotes


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-23-04 10:21 PM

In article <3fba0eda$1@news.userve.net>, Matt Churchyard wrote:
quote:
> Hi, > > I am having problems accepting connections on a socket. > The accept call returns a 'Bad Address' error which as far as i can see > means "The addr parameter is not in a writable part of the user address > space."
Which might happen if you don't initialize the client_len
quote:
> > I cannot understand why this could be as the addr structure is allocated > using > malloc which (if i am thinking correctly?) will not return an address > outside the user range. > > Heres the code thats causing the problem > >=============================== > // create space for client address > client.address = (struct sockaddr_in *)malloc(sizeof(struct > sockaddr_in)); > > if( client.address == NULL ) > { > syslog(LOG_ERR, "Couldn't allocate memory for client addre ss > structure"); > return; > } > > // wait for clients > NEXTCLIENT: > while((client.socket = accept(server.socket, (struct sockaddr > *)client.address, &client_len))) > { > // check socket > if( client.socket < 0 ) > { > perror("Socket Failed"); > > goto NEXTCLIENT; > }
Is the server.socket a valid socket, on which you've successfully called bind(2) and listen(2) ? And do you set client_len to the correct (sizeof(struct sockaddr_in))value on each iteration of the loop ? -- Vennlig hilsen/Best Regards Nils Olav Selåsdal <NOS at Utel.no> System Engineer UtelSystems a/s




[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 01:22 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register