Mail Archives: cygwin/1998/09/24/10:52:35
I want to use Win32 sockets. I have taken the steps outlined in the FAQ for doing this.
I cannot get the following code to compile using gcc.
#define Win32_Winsock
#include <windows.h>
#include <iostream.h>
#include <time.h>
void main(int argc, char *argv[])
{
time_t t;
int s;
struct sockaddr_in a;
struct hostent *h;
WSADATA wsaData;
if (argc != 2)
{
cout << "Usage: gettime" << argv[0] << " <host>\n";
exit(1);
}
if(WSAStartup(0x101, &wsaData))
{
cout << "Unable to initialize WinSock library.\n";
exit(1);
}
h = gethostbyname(argv[1]);
if (h == NULL)
{
cout << "Cannot resolve hostname\n";
WSACleanup();
exit(1);
}
a.sin_family = AF_INET;
a.sin_port = htons(37);
memcpy(&(a.sin_addr.s_addr), h->h_addr, sizeof(int));
s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (s == 0)
{
cout << "Cannot establish connection: "
<< WSAGetLastError() << '\n';
WSACleanup();
exit(1);
}
if (connect(s, (struct sockaddr *)&a, sizeof(a)))
{
cout << "Cannot establish connection: "
<< WSAGetLastError() << '\n';
WSACleanup();
exit(1);
}
if (recv(s, (char *)&t, 4, 0) != 4)
cout << "Unable to obtain time.\n";
else
{
t = ntohl(t) - 2208988800;
cout << asctime(localtime(&t));
}
closesocket(s);
WSACleanup();
}
/** THE FOLLOWING ERRORS ARE GENERATED **/
In file included from C:\\CYGNUS\\B19\\H-I386~1\\lib\\gcc-lib\\i386-cygwin32\\2.
7-B19\\../../../../i386-cygwin32/include/windows.h:66,
from gettime.cpp:2:
C:\\CYGNUS\\B19\\H-I386~1\\lib\\gcc-lib\\i386-cygwin32\\2.7-B19\\../../../../i38
6-cygwin32/include/Windows32/Sockets.h:783: parse error before `__attribute__'
C:\\CYGNUS\\B19\\H-I386~1\\lib\\gcc-lib\\i386-cygwin32\\2.7-B19\\../../../../i38
6-cygwin32/include/Windows32/Sockets.h:818: parse error before `__attribute__'
C:\\CYGNUS\\B19\\H-I386~1\\lib\\gcc-lib\\i386-cygwin32\\2.7-B19\\../../../../i38
6-cygwin32/include/Windows32/Sockets.h:821: parse error before `__attribute__'
C:\\CYGNUS\\B19\\H-I386~1\\lib\\gcc-lib\\i386-cygwin32\\2.7-B19\\../../../../i38
6-cygwin32/include/Windows32/Sockets.h:825: parse error before `__attribute__'
C:\\CYGNUS\\B19\\H-I386~1\\lib\\gcc-lib\\i386-cygwin32\\2.7-B19\\../../../../i38
6-cygwin32/include/Windows32/Sockets.h:827: parse error before `__attribute__'
C:\\CYGNUS\\B19\\H-I386~1\\lib\\gcc-lib\\i386-cygwin32\\2.7-B19\\../../../../i38
6-cygwin32/include/Windows32/Sockets.h:830: parse error before `__attribute__'
C:\\CYGNUS\\B19\\H-I386~1\\lib\\gcc-lib\\i386-cygwin32\\2.7-B19\\../../../../i38
6-cygwin32/include/Windows32/Sockets.h:832: parse error before `__attribute__'
It appears to have trouble with lines containing funtion prototypes returning pointers.
Any ideas?
regards
mike agee
mike AT aztek-eng DOT com
-----
Free e-mail group hosting at http://www.eGroups.com/
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request AT cygnus DOT com" with one line of text: "help".
- Raw text -