Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Socket error 68

516 views
Skip to first unread message

PeteCTM

unread,
Mar 20, 2009, 3:16:41 PM3/20/09
to
We have a program that uses sockets that runs flawlessly on AIX 4.3.3,
but on AIX 5.2 and above it immediately fails to bind to the socket
with an error code 68. Any clues?

/* Create server socket. */
sock= socket(AF_INET, SOCK_STREAM, 0);
if (sock < 0)
{
sprintf(message, "ERROR: couldn't create server socket : %d\n",
errno);
logerr_exit1(message);
}
else
{
sprintf(message, "Server socket number: %d has been created.",
sock);
logmsg(message);
}

/* Name socket using wildcards. */
server.sin_family = AF_INET;
server.sin_len = sizeof(server);
server.sin_port = serverPort;
option_toggle= 0; /* Turn OFF address re-use toggle */
socketoption_errcode= setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,
(char *)&option_toggle,
sizeof(option_toggle));
if (socketoption_errcode)
{
sprintf(message,
"ERROR - setting socket option SO_REUSEADDR to %d",
option_toggle);
logmsg(message);
}

if (bind(sock, (struct sockaddr *)&server, sizeof(server)))
{
sprintf(message, "ERROR: binding server socket %d : %d\n",
serverPort, errno);
logmsg(message);

if (errno == EADDRINUSE)
{
/* The port is already in use - probably because things didn't
get shut
* down properly, so try to bind to it allowing re-use of the
port */
sprintf(message, "Port already bound - trying to re-use
address...");
logmsg(message);

option_toggle= 1; /* Turn ON address re-use toggle */
/* Attempt to clear error status on socket */
socketoption_errcode= getsockopt(sock, SOL_SOCKET, SO_ERROR,
(char *)&option_toggle,
&size_val);
if (socketoption_errcode)
{
sprintf(message, "ERROR - clearing socket error using
SO_ERROR");
logmsg(message);
}

socketoption_errcode= setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,
(char *)&option_toggle,
sizeof(option_toggle));
if (socketoption_errcode)
{
sprintf(message,
"ERROR - setting socket option SO_REUSEADDR to %d",
option_toggle);
logmsg(message);
}
if (bind(sock, (struct sockaddr *)&server, sizeof(server)))
{
/* Still can't bind port - fail out */
sprintf(message, "ERROR: couldn't re-bind server socket %d : %d
\n", serverPort, errno);
logerr_exit1(message);
}
}
else
{
/* Error was not an "Address in use" error - fail out */
sprintf(message, "ERROR: couldn't bind server socket %d : %d\n",
serverPort, errno);
logerr_exit1(message);
}
}

Rick Jones

unread,
Mar 20, 2009, 7:22:51 PM3/20/09
to
PeteCTM <pete.ru...@gmail.com> wrote:
> We have a program that uses sockets that runs flawlessly on AIX
> 4.3.3, but on AIX 5.2 and above it immediately fails to bind to the
> socket with an error code 68. Any clues?

What is errno 68 on AIX 5.2? If this were HP-UX I would do something
akin to:

grep 68 /usr/include/sys/errno.h

to find the mnemonic and perhaps get more clues as to what was
going-on.

rick jones
--
firebug n, the idiot who tosses a lit cigarette out his car window
these opinions are mine, all mine; HP might not want them anyway... :)
feel free to post, OR email to rick.jones2 in hp.com but NOT BOTH...

bennet...@con-way.com

unread,
Mar 20, 2009, 7:26:36 PM3/20/09
to

Pete,

68 is defined in sys/errno.h as EADDRNOTAVAIL

bind's man page says this about that error:

EADDRNOTAVAIL The specified address is not available from
the local machine.

Is it possible that you are passing it an invalid "port number"...???

Additionally, I have never populated the "sin_len"... we always just
"memset" the
sockaddr_in structure (which I believe you call 'server'), then
populate the necessary fields
Like this:
struct sockaddr_in ServerAddress;

memset(&ServerAddress,0,sizeof(ServerAddress));
ServerAddress.sin_family = AF_INET;
ServerAddress.sin_addr.s_addr= htonl(INADDR_ANY);
ServerAddress.sin_port = htons(*ServerTCPPort);

We've used this methodology successfully as far back as AIX 3.2....

-tony

PeteCTM

unread,
Mar 20, 2009, 8:24:22 PM3/20/09
to
> -tony- Hide quoted text -
>
> - Show quoted text -

We are typically passing 9876 as the port number, but our current
workaraound is to compile on an AIX 4.3.3 server and copy the binary
to the AIX 5.2 server, the code works on the AIX 5.2 server when
compiled this way. This leads me to beleive something changed in AIX.
But I will try the memset method and see if it works.

Thanks

Pete

PeteCTM

unread,
Mar 20, 2009, 8:40:14 PM3/20/09
to
On Mar 20, 7:26 pm, bennett.t...@con-way.com wrote:
> -tony- Hide quoted text -
>
> - Show quoted text -

The memset method worked!

Thanks again, Tony

0 new messages