문제

I was seeing EADDRNOTAVAIL errors in connect() calls. I dig deeper found that naming of sockets were being done of over zero ip addresses . See following where both calls were sucessful:-

setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char *)&y, sizeof(y)); /* y is int with value 1 */

bind(s, (struct sockaddr *)lockaddr, sizeof(rtinetaddr_tp));

where

lockaddr={.sin_family=2, .sin_port=0, .sin_addr={.s_addr=0}, .sin_zero=""}

This, I found in RH site and also I have the same kernel.

My question is what if I remove doing any bind() at client side of the application? Will that be a quick cure OR will lead to any disaster?

Other way I have running sample programs without bind at client. But the app I am talking about that establishes hundreds of connections. So what may happen in worst case?

도움이 되었습니까?

해결책

Binding to a zero address is the same as binding to INADDR_ANY (which is defined as zero). This means you can make a connection on any local IP address (server side) or use the egress interface IP address (client side). This is quite normal.

다른 팁

If you are not interessed in using any particular address:port on the client side, the calls to bind() aren't necessary.

The Kernel will chose the suitable interface and a random port to establish the outgoing connection initiated by the client's call to connect().

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top