My code has a problem which I don't understand at all. Here is the code from the server:
usr = uslist_return(&users,i);
if(usr != NULL)
{
send(client,usr,sizeof(usr),0);
//Some extra code
}
else
{
utmp.userid = -1;
send(client,&utmp,sizeof(utmp),0);
}
Here is the code from the client:
recv(sock,tmp,sizeof(tmp),0);
if(tmp->userid > 0)
{
//Some Code
}
else
{
//Some other code
}
The problem here is that although I check that send() doesn't send a NULL pointer, the pointer that send() sends ends up being NULL. Maybe it's from recv(). I don't have the slightest idea.
Ignore uslist_return(...). It's just a function that returns a pointer. And the utmp is the same type (but not a pointer) as usr.
Edit: The server sends a pointer in if brackets and a struct in else brackets. The problem occures when the server sends the pointer usr and the client gets it and saves it in the pointer tmp (same type pointers). I Haven't check the else case yet, due to this.
Edit 2: Thanks Martin James for commenting that. It appears that recv() returns -1. Perror shows that the error is Bad Address. I don't know what this is.
sizeof(usr)is a size of a pointer, not the pointed data.usris a pointersizeof(usr)is the size of the pointer (probably 4 or 8), not the size of what it points to.tmpis not a valid address. I can't tell for sure because your code is incomplete. However, the piece of code you posted does not seem to be correct. You could improve your question by creating a minimal reproducible example.