Re: Help with passing integer poniter to function



manochavishal@xxxxxxxxx wrote:
Hi,

I am having strange problem in my Program.

I cannot paste the whole program as it is huge so just pasting the
lines i think are necessary.

I am passing a integer array pointer to a function.

**********

int sockets[MAX_TCPCLIENTS]; /* an array of connected sockets*/
.....
.....
fprintf(stderr,"The value is %d",sockets);

accept_new_tcp_client(sockets,&readset,listenfd);
......
......
void accept_new_tcp_client(int *sockets, fd_set *readset, int
listenfd) {
struct sockaddr *signaddr;
int addrlength;
int i;
int clientsockfd;
addrlength = sizeof(signaddr);





fprintf(stderr,"\nThe value is %d",sockets);

This is the second 'The value is 12643936' in your list?


/*== First accept the new connection ==*/

if((clientsockfd = accept(listenfd,(struct
sockaddr*)&signaddr,&addrlength))<0)
{
printf("\nSome Problem with accepting connection");
exit(EXIT_FAILURE);
}

fprintf(stderr,"\nAccepted a new Client connection");


fprintf(stderr,"\nThe value is %d",sockets);


And this one produces the error?


********
The print output is

....
The value is 12643936
The value is 12643936
Accepted a new Client connection
The value is 0Segmentation fault (core dumped)


Can anyone explians whats happening???


If my assumptions are correct [above], then I would *guess* that something's
screwing up the stack in your call to 'accept()' - if you comment that out,
the fprintf works ok?

In the call to accept(), you're casting signaddr to a 'struct sockaddr *' -
which it already is ...

struct sockaddr *signaddr

But, you're passing a struct sockaddr ** by using &signaddr.


--
==============
Not a pedant
==============


.



Relevant Pages