Hello I have a problem when I am writing the server using the socket api. I always get this error: "Socket operation on non-socket"
struct sockaddr_in addr;
int port = 10000;
int sd;
memset((char *) &addr,0, sizeof(addr));
addr.sin_family = PF_INET;
addr.sin_addr.s_addr = htonl(INADDR_ANY);
addr.sin_port = htonl((u_short)port);
if ((sd = socket(PF_INET, SOCK_STREAM, 0) < 0)) {
printf("socket failed");
}
if(bind(sd, (struct sockaddr *)&addr, sizeof(addr)) != 0)
{
printf(strerror(errno));
}
close(sd);
return 0;}
perror()orstrerror(), and (b) don't continue as though the error didn't happen. And it isn't correct to test system calls for!= 0: the correct test is== -1or< 0.