Jump to content
  • Advertisement
Sign in to follow this  

Error Code 10013

This topic is 4270 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post

Link to post
Share on other sites
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

if( sock == INVALID_SOCKET ) ErrorCheck("Creating socket");

// Bind socket
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?

Share this post

Link to post
Share on other sites
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 broadcasts
int 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.

Share this post

Link to post
Share on other sites
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).

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!