warning: passing argument 2 of ‘getsockname’ from incompatible pointer type
I can't figure this out. Can anyone tell me why I am getting this error:
warning: passing argument 2 of ‘getsockname’ from incompatible pointer type
In the following code:
#include
#include
#include
#include
#include
#include
int main() {
int sd;
struct sockaddr_in my_addr;
bzero(&my_addr,sizeof(my_addr));
my_addr.sin_family = AF_INET;
my_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
my_addr.sin_port = htons(0);
my_addr.sin_addr.s_addr = INADDR_ANY;
socklen_t my_addr_size = sizeof my_addr;
if((sd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
fprintf(stdout, "Cannot create socket for master socket.\n");
fprintf(stdout, "Terminating program\n\n");
exit(1);
}
if (bind(sd, (struct sockaddr *)&my_addr, sizeof(my_addr)) < 0) {
fprintf (stdout, "Binding failed for master socket\n\n");
perror("bind failed");
exit (1);
}
if (getsockname(sd, &my_addr, &my_addr_size) == -1) {
perror("getsockname() failed");
return -1;
}
}
Solved
The second argument to getsockname should be a struct sockaddr *. You're passing the address of a struct sockaddr_in.
Comments
Post a Comment