int socket_fd;
struct sockaddr_in sin;
socket_fd = socket(AF_INET,SOCK_STREAM,0);
if(socket_fd ==-1)
{
return -1;
}
bzero(&sin, sizeof(sin));
sin.sin_family = AF_INET;
sin.sin_port=htons(port);
inet_pton(AF_INET,"0.0.0.0",&sin.sin_addr);
if(bind(socket_fd,(struct sockaddr*)&sin,sizeof(struct sockaddr))<0)
{
printf("The current sport is occupied !!");
close(socket_fd);
return -1;
}
close(socket_fd);
return 0;
本文转自 Linux_woniu 51CTO博客,原文链接:http://blog.51cto.com/linuxcgi/1981208