Skip to main content
GameDev.net gamedev.net
🔒 Locked

Error Code 10013

Started by marshdabeachy Apr 8, 2007 at 8:27 PM 4 replies 1.8k views
Original Post
marshdabeachy
marshdabeachy
I'm doing a small first-time networking app, and am getting a rather weird problem. In Release mode, I am getting a 10013 "access denied" error message when I try to send a broadcast message. There's no errors prior to actually attempting to send the message, and the problem does not happen in Debug mode. I don't think it happens when I compile from other machines either. So the best I can guess is that it's some kind of optimization that's enabled on my version of Visual Studio '03... Any ideas what could fix this?
Antheus
Antheus
Posting code would help.

Make sure you have "setsockopt(SO_BROADCAST)" option set.
marshdabeachy
marshdabeachy
Here's my socket init...

	// Socket and error variables	int err;	char strMessage [ 128 ];	// Initialize Winsock	WSADATA wsadata;	err = WSAStartup( MAKEWORD( 2, 2 ), &wsadata );	if( err ) ErrorCheck("Initializing Winsock");	// Create socket	sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);	if( sock == INVALID_SOCKET ) ErrorCheck("Creating socket");	// Bind socket	SOCKADDR_IN saBind;	saBind.sin_family = AF_INET;	saBind.sin_port = htons( PORT );	saBind.sin_addr.s_addr = INADDR_ANY;	err = bind(sock, (const sockaddr*)&saBind, sizeof(saBind));	if( err ) ErrorCheck("Binding socket");	// Set socket to nonblocking	unsigned long argp = 1;	err = ioctlsocket( sock, FIONBIO, &argp );	if( err ) ErrorCheck("Setting socket to nonblocking");	// Enable broadcasts	err = setsockopt(sock, SOL_SOCKET, SO_BROADCAST, strMessage, 128);	if( err ) ErrorCheck("Enabling broadcasts");


Which reminds me, my instructor didn't explain it and I could never figure it out... what is the const char* that setsockopt wants for?
PlayerX
PlayerX
If you don't know what an argument to a function is, chances are that's where your problem is. In this case, the fourth argument to setsockopt is a pointer to a value to set the flag to. In your case you want to point this to a non-zero integer to indicate SO_BROADCAST should be enabled.

In other words:

// Enable broadcastsint On = 1;err = setsockopt(sock, SOL_SOCKET, SO_BROADCAST, (const char *)&On, sizeof(On));


I don't know if this is why you're getting access denied, but it seems the most likely reason.
hplus0603
hplus0603
The reason it happens in release mode, and not debug mode, is that, in debug mode, the compiler helpfully smashes uninitialized variables to feeefeee or cdcdcdcd or similar patterns, which count as "true," whereas in release mode, you get whatever happened to be there (which happens to be 0 in this case).
enum Bool { True, False, FileNotFound };

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.