开发者

setsockopt returns errno=2

Im creating an UDP socket (centos 6), which i want to send broadcast message. Every开发者_如何学运维thing works, creating socket works - socket(..) returns value=25, but:

int val = 1;
      if (setsockopt(a, SOL_SOCKET, SO_BROADCAST, &val, sizeof(val)) < 1){
          debug("setsockoopt failed with errno: %d, socket %d", errno, a);
      }

setsockopt sets errno to value = 2. Communictaion works, im sending udp packet to x.x.x.255 host, and all my apps recives it, but im wondering from where that errno came (errno=2=no such file or directory)

best regards


Upon successful completion, the value 0 is returned; otherwise the value -1 is returned and the global variable errno is set to indicate the error.

That's from the setsockopt manpage returns 0 on success, so it's just your condition that's wrong. If there was no error, errno's value is not relevant, and that's why here you get a rather absurd value.

if (setsockopt(a, SOL_SOCKET, SO_BROADCAST, &val, sizeof(val)) != 0){

is what you need.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜