int flag=1,flaglen=sizeof(int);
if ( (sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
{
perror("socket");
PR_LOG(bluetooth_lm, PR_LOG_DEBUG, ("[%s] socket function fail < 0", __func__) );
return;
}
if( setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &flag, flaglen) == -1)
{
perror("setsockopt");
PR_LOG(bluetooth_lm, PR_LOG_DEBUG, ("[%s] setsockopt fail", __func__) );
return;
}
if (bind(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0)
{
perror("bind");
PR_LOG(bluetooth_lm, PR_LOG_DEBUG, ("[%s] bind function fail < 0", __func__) );
return;
}
socket编程bind出错,因为绑定重复的地址和端口
最新推荐文章于 2023-05-30 15:06:54 发布