Why would connect() give intermittent EINVAL on port to FreeBSD?

It's interesting that the FreeBSD connect() manpage doesn't list EINVAL A different BSD manpage states.

It's interesting that the FreeBSD connect() manpage doesn't list EINVAL. A different BSD manpage states: EINVAL An invalid argument was detected (e.g. , address_len is not valid for the address family, the specified address family is invalid). Based on the disparate documentation from the different BSD flavours floating around, I would venture that there may be undocumented return code possibilities in FreeBSD, see here for example.

My advice is to print out your address length and the sizeof and contents of your socket address structure before calling connect - this will hopefully assist you to find out what's wrong. Beyond that, it's probably best if you show us the code you use to set up the connection. This includes the type used for the socket address (struct sockaddr, struct sockaddr_in, etc), the code which initialises it, and the actual call to connect.

That'll make it a lot easier to assist.

I've added detailed code per your request. – WilliamKF Oct 31 '10 at 20:29.

You’re silently ignoring errors from bind(2), which seems like not only bad form, but could be causing this issue to begin with!

No, the return from bind() is not ignored: cerr I understand the rationale for comparing a constant to the return to a function or syscall, but every modern compiler will warn you if you accidentally create a bare assignment inside a conditional expression, so I wish people would just use (syscall()! = −1). – Seth Kingsley Feb 25 at 19:23.

I figured out what the issue was, I was first getting a ECONNREFUSED, which on Linux I can just retry the connect() after a short pause and all is well, but on FreeBSD, the following retry of connect() fails with EINVAL. The solution is when ECONNREFUSED to back up further and instead start retrying back to beginning of test() definition above. With this change, the code now works properly.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions