Jump to content
  • Advertisement
Sign in to follow this  
ARC inc

WSAStartup failed null

This topic is 3320 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

Ok, I get WSAStartup failed <null> what does that error mean? I've never seen it before..... -Reason for not posting code: I don't feel the need to do so at the moment I am just looking to find out what that error means....

Share this post


Link to post
Share on other sites
Advertisement
To the best of my knowledge, WSAStartup doesn't print or report anything, it just returns error code. So whatever is generating that error is your error printing routine.

And if it returns 0 (closest to null), then it means it succeeded. Or there is some formatting problem with error printing routine.

Share this post


Link to post
Share on other sites
my error printing is like this....

printf("WSAStartup(): failed %s\n", WSAGetLastErorr);

an with that I get....

WSAStartup(): failed <null>

Share this post


Link to post
Share on other sites
That's obviously not the code you use, since that wouldn't even compile. In addition, WSAGetLastError returns an integer error code, not a string.

Besides, WSAGetLastError doesn't work with WSAStartup (because if WSAStartup fails, the structures used by WSAGetLastError aren't even set up yet). Instead, WSAStartup returns the error directly.

I would say the error is related to what you're passing into WSAStartup, so I think we'll have to see code anyway (in general, you should always assume that we'll need to see code, people cannot read minds. Even if you post code that's not directly related to the problem, post something so that we have some idea what's going on)

Share this post


Link to post
Share on other sites
Quote:
Original post by ARC inc
my error printing is like this....

printf("WSAStartup(): failed %s\n", WSAGetLastErorr);

an with that I get....

WSAStartup(): failed <null>


You are passing function pointer to WSAGetLastError, which printf tries to interpret as C-style string.

Share this post


Link to post
Share on other sites
WSAGetLastError() returns an integer, not a string. It returns 0 for "no error", which also happens to be the value for a null pointer. printf() is able to cope with that (In debug mode at least, I don't know about release), and prints "<null>" instead of crashing the application.

In addition, if WSAStartup() fails, it returns the error; it's not legal to call WSAGetLastError().

You want:

WSADATA data;
int nError = WSAStartup(MAKEWORD(2, 2), &data);
if(nError != 0)
{
printf("WSAStartup() failed with error %d\n", nError);
return -1;
}


Share this post


Link to post
Share on other sites
Quote:
Reason for not posting code: I don't feel the need to do so at the moment


Clearly, actually posting code would probably have been better...

Share this post


Link to post
Share on other sites
#include "config.hpp"
#include "ergodata.h"
#include "server.hpp"
#include <stdlib.h>
#include <stdio.h>
#include <winsock2.h>

int startserver()
{
int DEFAULT_PORT;
int DEFAULT_BUFFER;
int ErgoServ;

DEFAULT_PORT = static_cast<int>(server_config["port"]);
DEFAULT_BUFFER = static_cast<int>(server_config["buffer"]);

WSADATA wsaData;

ErgoServ = WSAStartup(MAKEWORD(2,2), &wsaData);
if(WSAStartup != 0){
printf("WSAStartup() failed: %d\n", ErgoServ);
WSACleanup();
return 1;
}

SOCKET s = socket(AF_INET, SOCK_STREAM, 5);
if(s == INVALID_SOCKET){
printf("socket(): failed %s\n", WSAGetLastError());
closesocket(s);
WSACleanup();
return 1;
}

sockaddr_in sin;

sin.sin_port = htons(DEFAULT_PORT);
sin.sin_family = AF_INET;
sin.sin_addr.s_addr = INADDR_ANY;

if(bind(s,(sockaddr*)&sin, sizeof(sin)) == SOCKET_ERROR){
printf("bind(): failed %s\n", WSAGetLastError());
closesocket(s);
WSACleanup();
return 1;
}

while(listen(s, SOMAXCONN) == SOCKET_ERROR);
SOCKET client;

int lin = sizeof(sin);
client = accept(s,(sockaddr*)&sin, &lin);
char buf[200] = "test\n";
send(client, buf, sizeof(buf), 0);
printf("bytes(): sent %d\n", &buf);
closesocket(s);
closesocket(client);

WSACleanup();
}





I am still getting the problem....here is the code.

Share this post


Link to post
Share on other sites
Quote:
Original post by ARC inc
*** Source Snippet Removed ***

I am still getting the problem....here is the code.


Exactly the same?

printf("socket(): failed %s\n", WSAGetLastError());
is an error, since it tries to print an int as string, which will likely cause a crash when printf will interpret it as pointer to char.

Quote:
if(WSAStartup != 0){
printf("WSAStartup() failed: %d\n", ErgoServ);
WSACleanup();
return 1;
}
Does this compile? What you want is
if(ErgoServ != 0){

Share this post


Link to post
Share on other sites
Ok, so I figured out what I was doing wrong.

Thanks for the help..but now I am getting a new error

socket failed: 10043

I know what the error means but I can't find what I did wrong...I thought I implented the system right...but i dunno

thanks again

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!