public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* RE: compiling winsock apps
@ 1997-10-29  2:35 Colin Peters
  0 siblings, 0 replies; 7+ messages in thread
From: Colin Peters @ 1997-10-29  2:35 UTC (permalink / raw)
  To: 'Ben Miller'; +Cc: 'GNU-Win32'

Ben Miller[SMTP:bgmiller@dccinc.com] wrote:
>try renaming the file to winsock.cpp and then compiling it.  It will generate these errors.  Is there something I am missing in order to be able to compile in c++ mode rather that c mode?

The C++ parser has some problems with parting function prototypes with
__attributes__ separated from the function names. I think that you will
need to go through the entries in Sockets.h that cause the errors and
change them to put the PASCAL word at the end of the line (I think this
works). E.g.

char PASCAL *inet_ntoa (struct in_addr in);

becomes

char *inet_ntoa (struct in_addr in) PASCAL;

It doesn't look nice, but it seems to work (won't work with non GNU
compilers though, but neither will a lot of other stuff in those
headers).

Good luck,
Colin.

-- Colin Peters - Saga Univ. Dept. of Information Science
-- colin@bird.fu.is.saga-u.ac.jp - finger for PGP public key
-- http://www.fu.is.saga-u.ac.jp/~colin/index.html
-- http://www.geocities.com/Tokyo/Towers/6162/

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: compiling winsock apps
@ 1997-10-28 18:40 Ben Miller
  0 siblings, 0 replies; 7+ messages in thread
From: Ben Miller @ 1997-10-28 18:40 UTC (permalink / raw)
  To: newsham; +Cc: gnu-win32

I have tried the lines you have indicated below but I get a bunch of errors like
the one below:

C:\\gnuwin32\\b18\\H-i386-cygwin32\\lib\\gcc-lib\\i386-cygwin32\\cygnus-2.7.2-970404\\../../../../i386-cygwin32/include/Windows32/Sockets.h:824: syntax error before `__attribute__'

----------------------------------------
Benjamin G. Miller
Consultant
Data Communications Consulting inc.
----------------------------------------
This message transmited on 100% recycled electrons.


>>> Tim Newsham <newsham@aloha.net> 10/28 3:42 PM >>>
> I have read the archives, the faq's, the docs (that I could find) and I still can't find how to compile a winsock application.  I can't even get all the headers to compile properly.  Can anyone out there offer some help or simple samples on how to get a standard winsock cpp application to compile and run properly.

^^ you should hit the enter key once every 70 characters.

You need to do:

    #define Win32_Winsock
    #include <windows.h>

to pull in the winsock defines rather than the cygwin (bsd style)
socket defines.

> Benjamin G. Miller

                                      Tim N.

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: compiling winsock apps
@ 1997-10-28 18:40 Ben Miller
  0 siblings, 0 replies; 7+ messages in thread
From: Ben Miller @ 1997-10-28 18:40 UTC (permalink / raw)
  To: newsham; +Cc: gnu-win32

try renaming the file to winsock.cpp and then compiling it.  It will generate these errors.  Is there something I am missing in order to be able to compile in c++ mode rather that c mode?

----------------------------------------
Benjamin G. Miller
Consultant
Data Communications Consulting inc.
----------------------------------------
This message transmited on 100% recycled electrons.


>>> Tim Newsham <newsham@aloha.net> 10/28 4:22 PM >>>
> 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".

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: compiling winsock apps
  1997-10-27 12:51 Ben Miller
@ 1997-10-28 18:40 ` Tim Newsham
  0 siblings, 0 replies; 7+ messages in thread
From: Tim Newsham @ 1997-10-28 18:40 UTC (permalink / raw)
  To: Ben Miller; +Cc: gnu-win32

> I have read the archives, the faq's, the docs (that I could find) and I still can't find how to compile a winsock application.  I can't even get all the headers to compile properly.  Can anyone out there offer some help or simple samples on how to get a standard winsock cpp application to compile and run properly.

^^ you should hit the enter key once every 70 characters.

You need to do:

    #define Win32_Winsock
    #include <windows.h>

to pull in the winsock defines rather than the cygwin (bsd style)
socket defines.

> Benjamin G. Miller

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: compiling winsock apps
       [not found] <s4560e79.017@dccinc.com>
@ 1997-10-28 18:40 ` Tim Newsham
  0 siblings, 0 replies; 7+ messages in thread
From: Tim Newsham @ 1997-10-28 18:40 UTC (permalink / raw)
  To: Ben Miller; +Cc: newsham, gnu-win32

> 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".

^ permalink raw reply	[flat|nested] 7+ messages in thread

* RE: compiling winsock apps
@ 1997-10-27 23:51 Sergey Okhapkin
  0 siblings, 0 replies; 7+ messages in thread
From: Sergey Okhapkin @ 1997-10-27 23:51 UTC (permalink / raw)
  To: gnu-win32, 'Ben Miller'

Ben Miller wrote:
> I have read the archives, the faq's, the docs (that I could find) and I 
still can't find how to compile a winsock application.  I can't even get 
all the headers to compile properly.  Can anyone out there offer some help 
or simple samples on how to get a standard winsock cpp application to 
compile and run properly.

If you want to use the standard berkeley socket functions, but not winsock 
extensions, just include <sys/socket.h>.

--
Sergey Okhapkin, http://www.lexa.ru/sos
Moscow, Russia
Looking for a job.


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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* compiling winsock apps
@ 1997-10-27 12:51 Ben Miller
  1997-10-28 18:40 ` Tim Newsham
  0 siblings, 1 reply; 7+ messages in thread
From: Ben Miller @ 1997-10-27 12:51 UTC (permalink / raw)
  To: gnu-win32

Greetings,

I have read the archives, the faq's, the docs (that I could find) and I still can't find how to compile a winsock application.  I can't even get all the headers to compile properly.  Can anyone out there offer some help or simple samples on how to get a standard winsock cpp application to compile and run properly.

Thanks in advance,
  Ben

----------------------------------------
Benjamin G. Miller
Consultant
Data Communications Consulting inc.
----------------------------------------
This message transmited on 100% recycled electrons.


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

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~1997-10-29  2:35 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-10-29  2:35 compiling winsock apps Colin Peters
     [not found] <s4560e79.017@dccinc.com>
1997-10-28 18:40 ` Tim Newsham
  -- strict thread matches above, loose matches on Subject: below --
1997-10-28 18:40 Ben Miller
1997-10-28 18:40 Ben Miller
1997-10-27 23:51 Sergey Okhapkin
1997-10-27 12:51 Ben Miller
1997-10-28 18:40 ` Tim Newsham

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).