LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Windows Sockets - "connect" command error

I am trying to establish a windows sockets connection using the Windows SDK functions.
 
First you need to initialise the dll with "WSAStartup"
then set up the socket using the "socket" command
and then connecting using the "connect" command
 
//establishes a connection to a specified socket.
 SSvrStruct.sin_family = AF_INET;
 SSvrStruct.sin_port = htons(502); // ASA standard port
 SSvrStruct.sin_addr.s_addr = inet_addr(ip_adrs);
 
ConStatus = connect(socketHandle, &SSvrStruct, sizeof(sockaddr_in)); // connecting the socket
 
The connect command fails on my SSvrStruct pointer:
 
Type error in argument 2 to `connect'; found 'pointer to struct sockaddr_in' expected 'pointer to const struct sockaddr'.
 
so the easy solution is to typecast it:
 
But: ConStatus = connect(socketHandle, (sockaddr*)&SSvrStruct, sizeof(sockaddr_in)); // connecting the socket
 
yields another error:  Undeclared identifier 'sockaddr'.
 
I am sure there is a simple solution to this, I just can not figure it out. Any ideas out there?
 
Attached the full source, just include WS2_32.lib in the project.
 
Thanks in advance
 
Jattie van der Linde
Engineering Manager, Software & Automation
TEL Magnetic Solutions Ltd
0 Kudos
Message 1 of 3
(3,462 Views)

In c, the struct keyword is not optional; it is in C++. Replacing "sockaddr" with "struct sockaddr" and "sockaddr_in" with "struct sockaddr_in" should get you going.

A common practice is to typedef names of structs to avoid this limitation; obviously this isn't possible for windows structures, etc., but it is handy for your own stuff.

ie.

typedef struct MyStruct_struct
{
    int structMember;
} MyStruct, *MyStructPtr;

Regards,

-alex

Message 2 of 3
(3,444 Views)
Thanks Alex!
Jattie van der Linde
Engineering Manager, Software & Automation
TEL Magnetic Solutions Ltd
0 Kudos
Message 3 of 3
(3,428 Views)