Skip to Main Content

DevOps, CI/CD and Automation

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

bind Error: Address family not supported by protocol family

807575May 28 2003 — edited Jun 6 2003
Hi,

I am using Sun Solaris Forte Compiler 7 using c++ compiler.

I need some help to understand the error I am geting when I use bind in my code.
It is failing with an error number 124 which does not explain in the man bind page.
The bind function is called as follows.(all code attached below)

Status = bind(
SockFd,
(struct sockaddr *) &SockAddr,
sizeof ( SockAddr ) );

The return value of Status is -1.

When I print the errno(system) I get 124.
errno = 124
This error :"Address family not supported by protocol family"
What does this means!!!!!!!!Help!

Following is my diagnostic print statements output

These values are passed to bind call.
SockFd =3,
&SockAddr = 0x454ba,
sizeof(SockAddr) = 16

The bind call internally set these parameters which I printed for diagnostic as described in the man page.
eacces = 13
eio = 5
eisdir = 21
eaddrinuse = 125
eaddrnotavial = 126
ebadf = 9
einval = 22
enosr = 63
enosock = 95
eloop = 90
enoent = 2
enotdir = 20
erofs = 30
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
The C++ socket open code, it is failing at bind call.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
AppErr_t SocketRecv_c::Open(
const char *Name,
const char *Path,
const int BufSize )
{
if ( IsSocketUsed( Name ) ) {
ErrLogWrite( EL_SYS, String( "SocketRecv_c::Open: " ) <<
"Socket: " << Name << " is in use which means this" <<
" program may already be running." );
cout << "1st fail" << endl;
return ( FAIL );
}
// Check if socket open:
if ( SockFd < 0 ) {
if ( SocketDgram_c::Open() != SUCCESS ) {
ErrLogWriteErrno( EL_SYS, String("SocketRecv_c::Open:")
<< "Failed to open underlying socket" );
return FAIL;
}
}
int Status;
Status = setsockopt(
SockFd,
SOL_SOCKET,
SO_RCVBUF,
&BufSize,
sizeof ( BufSize ) );
if ( Status != 0 ) {
ErrLogWriteErrno( EL_SYS, String( "SocketRecv_c::Open: " ) <<
"Failed to set buffer size of receive socket" );
return ( FAIL );
}
SetSockPath( Path );
SetSockName( Name );
// If the socket already exists with a different user to the current
// one, then FAIL
struct stat FileBuf;
if ( stat( SockAddr_un.sun_path, &FileBuf ) == 0 ) {
uid_t ThisUser = getuid();
if ( FileBuf.st_uid != ThisUser ) {
ErrLogWrite( EL_SYS, String( "SocketRecv_c::Open: " ) <<
"Socket already exists for" << SockAddr_un.sun_path <<
" Previous UID=" << (long) FileBuf.st_uid <<
" This UID=" << (long) ThisUser <<
".This means the previous user did not exit properly or" <<
" is still running. Systems should manually delete the"
" socket if the previous user has finished." );
return FAIL;
}
}
BindOK = FALSE;
Status = bind(
SockFd,
&SockAddr,
sizeof ( SockAddr ) );
if ( Status < 0 ) {
// If the bind address is in use, then try and delete it and the
// re-create it:
if ( errno == EADDRINUSE ) {
if ( unlink( SockAddr_un.sun_path ) < 0 ) {
ErrLogWriteErrno( EL_SYS, String( "SocketRecv_c::Open: " ) <<
"Failed to unlink bind address for receiver" <<
", Name=" << SockAddr_un.sun_path
);
return ( FAIL );
}
else {
Status = bind( SockFd, &SockAddr, sizeof ( SockAddr ) );
if ( Status < 0 ) {
ErrLogWriteErrno( EL_SYS,
String( "SocketRecv_c::Open: " ) <<
"Failed in 2nd attempt to bind for receiver" );
return ( FAIL );
}
}
}
else {
ErrLogWriteErrno( EL_SYS, String( "SocketRecv_c::Open: " ) <<
"Failed to bind name to socket" );
cout << " eacces " << EACCES << endl << " eio " << EIO
<< endl << " eisdir " << EISDIR << endl << "eaddrinuse " << EADDRINUSE << endl
<< "eaddrnotavial " << EADDRNOTAVAIL << endl << " ebadf " << EBADF << endl <
< "einval " << EINVAL <<endl << " enosr " << ENOSR <<endl << " enosock " << EN
OTSOCK << endl << " eloop " << ELOOP << endl << "enoent " << ENOENT << endl <
< " enotdir " << ENOTDIR << endl << " erofs " << EROFS << endl;
cout << "7th fail errno = " << errno << endl;
perror("Error"); // To print the system error 124
return ( FAIL ); // This is where it is failing.
}
}
BindOK = TRUE;
// Make the socket read/write for all:
chmod( SockAddr_un.sun_path, 0777 );
return ( SUCCESS );
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 4 2003
Added on May 28 2003
2 comments
896 views