Sign in to follow this  
marshdabeachy

Error Code 10013

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
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?

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this