bind() fails with WSAEACCES

This is a discussion on bind() fails with WSAEACCES within the Tech Board forums, part of the Community Boards category; Hi, after installing some (probably wrong) device driver for my umts hardware my software written in C on WinXP always ...

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    519

    bind() fails with WSAEACCES

    Hi,

    after installing some (probably wrong) device driver for my umts hardware my software written in C on WinXP always fails at the point there it tries to bind to a multicast socket with error code WSAEACCES.

    (I'm not 100% sure that the driver is the reason, but it's installation was the last thing I did before running into that problem)

    What I tried to solve it:
    -reboot
    -reset tcp ip stack
    -uninstall the driver
    -try other multicast adress

    nothing seems to to help so far.

    msdn just says:

    Permission denied.

    An attempt was made to access a socket in a way forbidden by its access permissions. An example is using a broadcast address for sendto without broadcast permission being set using setsockopt(SO_BROADCAST).

    Another possible reason for the WSAEACCES error is that when the bind function is called (on Windows NT 4 SP4 or later), another application, service, or kernel mode driver is bound to the same address with exclusive access. Such exclusive access is a new feature of Windows NT 4 SP4 and later, and is implemented by using the SO_EXCLUSIVEADDRUSE option.
    So it seems somehow this driver is accessing/locking my multicast adresses.
    Does anybody has an idea what else I could try?

    Thank you in advance!

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,845
    http://www.sockets.com/ch16.htm#Multicast
    http://beej.us/guide/bgnet/output/ht...alls.html#bind
    My impression is that multicast is a UDP protocol only. If a single receiver fails to receive a packet, there is no way to ask the sender for another copy, without really mucking up what everyone else is doing.

    To that end, you don't bind() to a port, but you use sendto() and recvfrom() instead, which supply that information as extra parameters.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Nov 2006
    Posts
    519
    Sorry Salem, I didn't looked carefully enough. The code which causes the problem wasn't written by me. It has nothing to do with multi cast (which is used in another part of the program). The software is widely used and I'm the only one who suffers from that problem, it doesn't happen on any other computer.

    I extracted the code and was able to reproduce it in the following example:

    Code:
    #include <winsock2.h>
    
    int main()
    {
    	WSADATA wsaData;
    	WORD wVersionRequested = MAKEWORD( 2, 2 );
    	int err = WSAStartup( wVersionRequested, &wsaData );
    	if ( err != 0 ) 
    	{                         
    		return -1;
    	}
    
    	unsigned short port = 8015;
    	unsigned int bind_addr = htonl(INADDR_ANY);
    
    	SOCKET  s = socket(PF_INET, SOCK_DGRAM, 0);
    
    	struct sockaddr_in addr;
    
    	int yes = 1;
    
    	if (s < 0)	return -1;
    
    	memset(&addr, 0, sizeof(addr));
    	addr.sin_family = AF_INET;
    	addr.sin_port = htons(port);
    	addr.sin_addr.s_addr = bind_addr;
    
    	if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char*)&yes, sizeof(yes)) < 0)
    	{
    		int e = WSAGetLastError();
    		closesocket(s);
    		return -1;
    	}
    
    	if (bind(s, (struct sockaddr*)&addr, sizeof(addr)) < 0)
    	{
    		int e = WSAGetLastError();  //e == 10013 which is WSAEACCES
    		closesocket(s);
    		return -1;
    	}
    };
    if I don't set the socket option SO_REUSEADDR I get the error WSAEADDRINUSE.

    Why can't I bind?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 21
    Last Post: 06-24-2009, 10:49 AM
  2. Bind problem
    By moment in forum Networking/Device Communication
    Replies: 2
    Last Post: 04-24-2009, 12:36 PM
  3. bind() chosing a port
    By spank in forum Linux Programming
    Replies: 4
    Last Post: 04-28-2007, 11:22 AM
  4. What does bind() do, exactly?
    By Hunter2 in forum Networking/Device Communication
    Replies: 9
    Last Post: 07-07-2005, 01:12 PM
  5. Bind();
    By SirCrono6 in forum Networking/Device Communication
    Replies: 5
    Last Post: 02-26-2005, 08:01 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21