Link to home
Start Free TrialLog in
Avatar of bass20
bass20

asked on

Passing sockaddr_in structure won't work

Hey,

I'm passing a sockadd_in struct to a function but when it gets there it's empty:

/*here it prints the address, if requested*/
remove(sockfd,serverAddr);

void remove(int socketfd, struct sockaddr_in serverAddr){

/*here it prints 0.0.0.0*/
printf("%s", inet_ntoa(serverAddr.sin_addr.s_addr));

}
Avatar of bass20
bass20

ASKER

PS: I can't pass the address of the struct because I'll use sendto in function remove() and it needs to use the real address of the struct not the address of a pointer that's been passed. Hence, sendto's perror gives me invalid argument...
Avatar of jkr
I think you got the concept of pointers and adresses wrong - simply use

void remove(int socketfd, struct sockaddr_in* serverAddr){


printf("%s", inet_ntoa(serverAddr->sin_addr.s_addr));

sendto (socketfd, buf, len, flags, serverAddr, sizeof ( struct sockaddr_in));

}


Avatar of bass20

ASKER

In that case, when you do

sendto (socketfd, buf, len, flags, serverAddr, sizeof ( struct sockaddr_in));

you'll be passing sendto the address of serverAddr when it expects the structure itself
>>you'll be passing sendto the address of serverAddr when it expects the structure itself

No.
ASKER CERTIFIED SOLUTION
Avatar of sunnycoder
sunnycoder
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bass20

ASKER

"This old question needs to be finalized"

I'm quite aware of that, and you may notice that I closed two other questions that were awaiting an answer to be accepted; the reason I didn't on this one, is that I tried twice to do so and I couldn't get the Accept button on Mozilla; I had to clear all cache/cookies, log in and reload question twice to get the button.

I wasn't intending to leave the question open forever, if I didn't close it before, it was because I was unable to do so
bass20 - I am sorry to say so, you have no clue how EE works.
Avatar of bass20

ASKER

I know that message was automatic, I posted an answer so none of the people that helped me would think that I didn't pay attention to their posts
>>I know that message was automatic

Well, and you accepted a comment that baiscally said 'jkr has guided you correctly'...