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_a ddr.s_addr ));
}
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_a
}
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_add r));
sendto (socketfd, buf, len, flags, serverAddr, sizeof ( struct sockaddr_in));
}
void remove(int socketfd, struct sockaddr_in* serverAddr){
printf("%s", inet_ntoa(serverAddr->sin_
sendto (socketfd, buf, len, flags, serverAddr, sizeof ( struct sockaddr_in));
}
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
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.
No.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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.
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'...
Well, and you accepted a comment that baiscally said 'jkr has guided you correctly'...
ASKER