标签:检查源端口被占用
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,"127.0.0.1",&sin.sin_addr);
if(bind(socket_fd,(struct sockaddr*)&sin,sizeof(struct sockaddr))<0)
{
printf("The current sport is occupied !!");
return -1;
}
close(socket_fd);
return 0;
本文出自 “Linux_woniu” 博客,请务必保留此出处http://linuxcgi.blog.51cto.com/5925801/1981208
标签:检查源端口被占用
原文地址:http://linuxcgi.blog.51cto.com/5925801/1981208