This is the mail archive of the cygwin@sourceware.cygnus.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: compiling winsock apps


> I have tried the lines you have indicated below but I get a bunch of =
> errors like
> the one below:
> 
> C:=5C=5Cgnuwin32=5C=5Cb18=5C=5CH-i386-cygwin32=5C=5Clib=5C=5Cgcc-lib=5C=5Ci=
> 386-cygwin32=5C=5Ccygnus-2.7.2-970404=5C=5C../../../../i386-cygwin32/includ=
> e/Windows32/Sockets.h:824: syntax error before `__attribute__=27

I don't get any errors like that.  Here is an example program that
compiles and runs for me:


/*
 * winsock.c
 * 	example of using winsock calls with cygwin
 *
 * to build: gcc winsock.c -lwsock32
 */

#define Win32_Winsock
#include <windows.h>

void
xperror(int bool, char *mesg)
{
    if(bool) {
        printf("%s: error %d\n", mesg, GetLastError());
        exit(1);
    }
}

void
init()
{
    static int initdone = 0; 
    static WSADATA data;

    if(initdone == 0) {
        WSAStartup(MAKEWORD(1, 1), &data);   
        initdone = 1;
    }
}

int
main(int argc, char **argv)
{
    SOCKADDR_IN ad;
    SOCKET s;
    int addr, res;

    init();
    if(argc != 2) {
        printf("usage: %s hostIP\n", argv[0]);
        exit(1);
    }
    addr = inet_addr(argv[1]);

    s = socket(AF_INET, SOCK_STREAM, 0);
    xperror(s == INVALID_SOCKET, "socket");

    memset(&ad, 0, sizeof(ad));
    ad.sin_family = AF_INET;
    ad.sin_port = htons(23);
    ad.sin_addr.s_addr = addr;

    res = connect(s, (LPSOCKADDR)&ad, sizeof(ad));
    xperror(res == SOCKET_ERROR, "connect");

    printf("connected\n");
    closesocket(s);
    return 0;
}

-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]