Alex Salmon wrote:
> #include <stdio.h>
> #include <sys/types.h>
> #include <sys/socket.h>
> #include <netinet/in.h>
>
> It compiles and works nicly in linux with gcc, I am trying to run the prog
> in win but i am having a little bit of trouble compiling it.
Here is some sample code I've used to compile socket-based proggies
on both *nix and Windoze .... I leave it up to you to determine
how to set __UNIX__ or __WIN32__ as appropriate:
// includes: sockets and networking
#if defined(__UNIX__)
#include <netdb.h>
#include <netinet/in.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#elif defined(__WIN32__)
#include <winsock.h>
#endif
// Win32 sockets require this initialisation step (once):
#if defined(__WIN32__)
int const wVersionRequested = MAKEWORD(1,1);
WSAData sockdata;
int const startupcode = WSAStartup(wVersionRequested,&sockdata);
if (startupcode != 0)
{
die or whatever
}
#endif
// Win32 read() does not do sockets ... must use recv e.g.
// NOT: int const readlen = read(sock, buf, buflen);
int const readlen = recv(sock, buf, buflen, 0);
// Win32 write() does not do sockets ... must use send e.g.
// NOT: int const writelen = write(sock, buf, buflen);
int const writelen = send(sock, buf, buflen, 0);
-------------------------------------------------------------------
Win32 socket errors - must call WSAGetLastError()
Finally, read the docs on w32sock.dll or whatever you've got.
Your BCC or MSVC environment should have help for winsock.h
--
Rick Welykochy || Praxis Services Pty Limited
--
SLUG - Sydney Linux User Group Mailing List - http://slug.org.au/
More Info: http://slug.org.au/lists/listinfo/slug