socket编程bind出错,因为绑定重复的地址和端口


        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;
        }

猜你喜欢

转载自blog.csdn.net/u013304850/article/details/76485868
今日推荐