Frage

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?

War es hilfreich?

Lösung

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.

Andere Tipps

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().

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top