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

Getting WSAEAFNOSUPPORT on bind attempt

103 views
Skip to first unread message

Ming Chin

unread,
Dec 16, 1999, 3:00:00 AM12/16/99
to
Hi all,

I'm learning winsock programming on my own and I've run into a snag.
When I call bind(), I get
a WSAEAFNOSUPPORT error.

Here's the edited code (I've left out the error checking so that it is
more readable)

SOCKET socketDescriptor = INVALID_SOCKET;
sockaddr_in sin;
int iRetCode = 0;

socketDescriptor = socket( AF_INET, SOCK_STREAM, 0 );
/*
error checking in here
but this call returns successfully
*/
sin.sin_family = AF_INET;
sin.sin_port = htons(10591); // this is an arbitrary port number I've
chosen for my applications
sin.sin_addr.s_addr = htonl( INADDR_ANY );

iRetCode = bind( socketDescriptor, sin, sizeof( SOCKADDR ) );

/*
bind returns SOCKET_ERROR to iRetCode
and WSAGetLastError() indicates error number 10047 (ie. WSAEAFNOSUPPORT
)

the docs describe this error as "An address incompatible with the
requested protocol was used"

I don't get it. What's wrong with AF_INET and SOCK_STREAM ??
*/

Help me out guys! Please!
--
Ming Chin

ming...@home.com
http://members.home.net/mingchin/


"MS-Windows: proof that P.T. Barnum was correct."

Dan Wanderer

unread,
Dec 21, 1999, 3:00:00 AM12/21/99
to Ming Chin
change
sin.sin_addr.s_addr = htonl( INADDR_ANY );
to
sin.sin_addr.s_addr = INADDR_ANY;

Alun Jones

unread,
Dec 21, 1999, 3:00:00 AM12/21/99
to
In article <83o6n0$1b1o$1...@msunews.cl.msu.edu>, Dan Wanderer
<"dlw"@forest(NOSPAM).com> wrote:
> change
> sin.sin_addr.s_addr = htonl( INADDR_ANY );
> to
> sin.sin_addr.s_addr = INADDR_ANY;

That won't help - INADDR_ANY is 0, and htonl(0) is 0.

> Ming Chin wrote:
> >
> > Hi all,
> >
> > I'm learning winsock programming on my own and I've run into a snag.
> > When I call bind(), I get
> > a WSAEAFNOSUPPORT error.
> >
> > Here's the edited code (I've left out the error checking so that it is
> > more readable)
> >
> > SOCKET socketDescriptor = INVALID_SOCKET;
> > sockaddr_in sin;
> > int iRetCode = 0;
> >
> > socketDescriptor = socket( AF_INET, SOCK_STREAM, 0 );
> > /*
> > error checking in here
> > but this call returns successfully
> > */
> > sin.sin_family = AF_INET;
> > sin.sin_port = htons(10591); // this is an arbitrary port number I've
> > chosen for my applications
> > sin.sin_addr.s_addr = htonl( INADDR_ANY );
> >
> > iRetCode = bind( socketDescriptor, sin, sizeof( SOCKADDR ) );

Second parameter to bind should be a "const struct sockaddr FAR *" - in
other words, a _pointer_ to the struct. You're passing the struct itself.
Here's how your bind should look:

iRetCode = bind( socketDescriptor, (LPSOCKADDR)&sin, sizeof( sin ) );

Alun.
~~~~

--
Texas Imperial Software | Try WFTPD, the Windows FTP Server. Find it
1602 Harvest Moon Place | at web site http://www.wftpd.com or email
Cedar Park TX 78613 | us at al...@texis.com. VISA / MC accepted.
Fax +1 (512) 378 3246 | NT based ISPs, be sure to read details of
Phone +1 (512) 378 3246 | WFTPD Pro, NT service version - $100.
*WFTPD and WFTPD Pro now available as native Alpha versions for NT*

0 new messages