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_lenquote:
>
> 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 ]
|