Tech or Treat! Write an article about your scariest tech disaster to win gadgets!Learn more

x
?
Solved

winsock error returned from socket(AF_INET...

Posted on 1999-01-20
3
Medium Priority
?
371 Views
Last Modified: 2006-11-17
I am trying to write a simple DLL that opens a socket
to a Unix machine.  The routine keeps returning
10047 (notsupported) from the connect call.  Actually
I think it's coming from the socket call. TCP is up
on the LAN and all my other apps work great.  Can
anyone see my problem?

__declspec (dllexport) void _stdcall
woe_init (long *out1, long *out2)
{
      SOCKET H = socket(PF_INET,SOCK_STREAM,0);
      struct sockaddr_in sock;
      sock.sin_addr.s_addr = inet_addr("127.0.0.1");
      sock.sin_port=htons(9024);

      int u=0,y=0;
      y=connect(H,(LPSOCKADDR)&sock,sizeof(sock));
      *out1 = WSAGetLastError();
      l=closesocket(H);
      *out2 = WSAGetLastError();
      return;
}
0
Comment
Question by:timothynelson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 4

Accepted Solution

by:
tflai earned 400 total points
ID: 1184632
I believe you forgot this line:
sock.sin_family = PF_INET;

0
 

Author Comment

by:timothynelson
ID: 1184633
Obvious... if I only checked my Unix code!

Do I also need to worry about WSAStartUp???

Thanks for the quick reply, I'll be giving you the points.

0
 
LVL 4

Expert Comment

by:pellep
ID: 1184634
Yes, you should call WSAStartUp. It initializes the winsock dll.
if you do not call it, the socket-functions is likely to behave
unpredictably. Furthermore WSAGetLastError() should defenitly not work.
//example
WORD wVersionRequested;
WSADATA wsaData;
int err;
wVersionRequested = MAKEWORD( 2, 0 );//which version do you need
err = WSAStartup( wVersionRequested, &wsaData );
if ( err != 0 ) {
    /* Tell the user that we couldn't find a usable */
    /* WinSock DLL.                                  */    return;
}

if ( LOBYTE( wsaData.wVersion ) != 2 ||HIBYTE(wsaData.wVersion ) != 0 ) //which version is available
{

WSACleanup( );
    return;
}
struct WSAData {
WORD wVersion;    
WORD wHighVersion;
char szDescription[WSADESCRIPTION_LEN+1];
char szSystemStatus[WSASYSSTATUS_LEN+1];
unsigned short iMaxSockets;
unsigned short iMaxUdpDg;
char FAR *lpVendorInfo;};
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

647 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question