public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Newbie with socket problems...(pretty long)
@ 1999-08-09 15:19 Simon Gornall
  1999-08-09 15:35 ` Mumit Khan
  1999-08-31 23:49 ` Simon Gornall
  0 siblings, 2 replies; 4+ messages in thread
From: Simon Gornall @ 1999-08-09 15:19 UTC (permalink / raw)
  To: cygwin

I've just downloaded a clean 'full install' of the B20.1 cygnus
development
environment, and I seem to be having problems with sockets. It's all
linking
correctly, and I can't seem to find anyone else with problems recently,
so
I assume I'm linking it incorrectly or something... If anyone cares to
have a
look and see what I'm doing wrong, I'd be very grateful. I'm *almost* at

the stage where I can have the same source tree across PC/Linux/Irix/Sun
:-)

Anyway, here's the code, ripped out of the application and wrapped with
a
'main' function:


extern "C" {
#  include <winsock.h>
};
#include <iostream.h>              // For errors etc.
#include <stdlib.h>                   // For atoi()


void die(char *msg)
 {
 cerr << "FATAL : " << msg << endl;
 exit(-1);
 }

int main(int argc, char **argv)
 {
 int   _debug  = 1;
 char *_host   = argv[1];
 int   _port   = atoi(argv[2]);
    int   _socket = -1;

    //
==================================================================
    // Connect to the server
    //
==================================================================
 struct sockaddr_in sk_addr;   // use sk_addr because s_addr is #defined
under cygwin.

 // Can't find bzero() ...
 for (unsigned int i=0; i<sizeof(sk_addr); i++)
  {
  char *val = ((char*)(&sk_addr+i));
  *val = 0;
  }

 sk_addr.sin_family      = AF_INET;
 sk_addr.sin_addr.s_addr = inet_addr(_host);
 sk_addr.sin_port        = htons(_port);

    //
==================================================================
 // Open a TCP socket
    //
==================================================================
 if ((_socket = socket(AF_INET, SOCK_STREAM, 0)) < 0)
  die("can't open stream socket");

    //
==================================================================
 // Connect to the server.
    //
==================================================================
 if (connect(_socket, (struct sockaddr *) &sk_addr, sizeof(sk_addr)) <
0)
  die("can't connect to server");

 if (_debug)
  cerr << "Fetcher: All initialised OK\n";
    return 0;
    }

This all works fine under Unix - with the correct includes etc - but it
bombs out when calling socket()
under cygwin, so I get the "Can't open stream socket" message. I can
connect to the service using
telnet however, so my server is running fine.

One thing I did have to do was move the libstdc++.a from the mwing32
libraries directory to the 'standard'
directory, or I got loads of 'undefined XXX' errors, where XXX where
obviously global variables.

I'm compiling it using 'c++ -mno-cygwin -o runtest test.cc -lwsock32'
Here's the output from the compiler:

Reading specs from
E:\GNU\CYGWIN~1\H-I586~1\BIN\..\lib\gcc-lib\i586-cygwin32\egcs-2.91.57\specs

gcc version egcs-2.91.57 19980901 (egcs-1.1 release)
 E:\GNU\CYGWIN~1\H-I586~1\BIN\..\lib\gcc-lib\i586-cygwin32\egcs-2.91.57\cpp.exe
-lang-c++ -v -iprefix
E:\GNU\CYGWIN~1\H-I586~1\BIN\..\lib/gcc-lib/i586-cygwin32\egcs-2.91.57\
-undef -D__GNUC__=2 -D__GNUG__=2 -D__cplusplus -D__GNUC_MINOR__=91
-Di386 -D_WIN32 -DWINNT -D_X86_=1 -D__STDC__=1
-D__stdcall=__attribute__((__stdcall__))
-D__cdecl=__attribute__((__cdecl__)) -D__declspec(x)=__attribute__((x))
-D__i386__ -D_WIN32 -D__WINNT__ -D_X86_=1 -D__STDC__=1
-D__stdcall=__attribute__((__stdcall__))
-D__cdecl=__attribute__((__cdecl__)) -D__declspec(x)=__attribute__((x))
-D__i386 -D__WINNT -Asystem(winnt) -Acpu(i386) -Amachine(i386)
-D__EXCEPTIONS -remap -Acpu(i386) -Amachine(i386) -Di386 -D__i386
-D__i386__ -Di586 -Dpentium -D__i586 -D__i586__ -D__pentium
-D__pentium__ -iwithprefixbefore
../../../../i586-cygwin32/include/mingw32 -D__MINGW32__=0.2 test.cc
C:\WINDOWS\TEMP\ccTaaPFf.ii
GNU CPP version egcs-2.91.57 19980901 (egcs-1.1 release) (80386, BSD
syntax)
#include "..." search starts here:
#include <...> search starts here:
 E:\GNU\CYGWIN~1\H-I586~1\BIN\..\lib\gcc-lib\i586-cygwin32\egcs-2.91.57\..\..\..\..\i586-cygwin32\include\mingw32

 E:\GNU\CYGWIN~1\H-I586~1\BIN\..\lib\gcc-lib\i586-cygwin32\egcs-2.91.57\..\..\..\..\..\include\g++

 E:\GNU\CYGWIN~1\H-I586~1\BIN\..\lib\gcc-lib\i586-cygwin32\egcs-2.91.57\..\..\..\..\..\include

 E:\GNU\CYGWIN~1\H-I586~1\BIN\..\lib\gcc-lib\i586-cygwin32\egcs-2.91.57\..\..\..\..\i586-cygwin32\include

 E:\GNU\CYGWIN~1\H-I586~1\BIN\..\lib\gcc-lib\i586-cygwin32\egcs-2.91.57\include

End of search list.
 E:\GNU\CYGWIN~1\H-I586~1\BIN\..\lib\gcc-lib\i586-cygwin32\egcs-2.91.57\cc1plus.exe
C:\WINDOWS\TEMP\ccTaaPFf.ii -quiet -dumpbase test.cc -mno-cygwin
-version -o C:\WINDOWS\TEMP\ccu7RywY.s
GNU C++ version egcs-2.91.57 19980901 (egcs-1.1 release) (i586-cygwin32)
compiled by GNU C version egcs-2.91.57 19980901 (egcs-1.1 release).
 E:\GNU\CYGWIN~1\H-I586~1\BIN\..\lib\gcc-lib\i586-cygwin32\egcs-2.91.57\..\..\..\..\i586-cygwin32\bin\as.exe
-o C:\WINDOWS\TEMP\ccmKtYoW.o C:\WINDOWS\TEMP\ccu7RywY.s
 E:\GNU\CYGWIN~1\H-I586~1\BIN\..\lib\gcc-lib\i586-cygwin32\egcs-2.91.57\collect2.exe
-o t.exe
E:\GNU\CYGWIN~1\H-I586~1\BIN\..\lib\gcc-lib\i586-cygwin32\egcs-2.91.57\..\..\..\..\i586-cygwin32\lib\crt1.o
-LE:\GNU\CYGWIN~1\H-I586~1\BIN\..\lib\gcc-lib\i586-cygwin32\egcs-2.91.57
-LE:\GNU\CYGWIN~1\H-I586~1\BIN\..\lib\gcc-lib
-LE:\GNU\CYGWIN~1\H-I586~1\BIN\..\lib\gcc-lib\i586-cygwin32\egcs-2.91.57\..\..\..\..\i586-cygwin32\lib
-LE:\GNU\CYGWIN~1\H-I586~1\BIN\..\lib\gcc-lib\i586-cygwin32\egcs-2.91.57\..\..\..
C:\WINDOWS\TEMP\ccmKtYoW.o -lwsock32 -lstdc++ -lm -lgcc -lmingw32
-lmoldname -lcrtdll -lkernel32 -ladvapi32 -lshell32 -lgcc



--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com

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

* Re: Newbie with socket problems...(pretty long)
  1999-08-09 15:19 Newbie with socket problems...(pretty long) Simon Gornall
@ 1999-08-09 15:35 ` Mumit Khan
  1999-08-31 23:49   ` Mumit Khan
  1999-08-31 23:49 ` Simon Gornall
  1 sibling, 1 reply; 4+ messages in thread
From: Mumit Khan @ 1999-08-09 15:35 UTC (permalink / raw)
  To: Simon Gornall; +Cc: cygwin

Simon Gornall <simon@unique-id.com> writes:
> I've just downloaded a clean 'full install' of the B20.1 cygnus
> development
> environment, and I seem to be having problems with sockets. It's all
> linking
> correctly, and I can't seem to find anyone else with problems recently,
> so
> I assume I'm linking it incorrectly or something... If anyone cares to
> have a
> look and see what I'm doing wrong, I'd be very grateful. I'm *almost* at

I notice that you're using -mno-cygwin. You certainly want to read my
notes on using -no-cygwin available at:

  http://www.xraylith.wisc.edu/~khan/software/gnu-win32/

Also, while you're at the above URL, you may seriously consider upgrading
your compilers to gcc-2.95.

before doing things like:

> One thing I did have to do was move the libstdc++.a from the mwing32
> libraries directory to the 'standard'
> directory, or I got loads of 'undefined XXX' errors, where XXX where
> obviously global variables.

Remember that you're using Winsock, not Berkeley or POSIX sockets that's
common on Unix systems. For Winsock, you *have* to call WSAStartup
first (see windows docs on microsoft site or in your favorite w32 api
book). Unless you have other problems in the code, this should fix
it.

When you post asking for help, you really ought to try and explain 
better as to what problem you're having. For example, is it not 
connecting? Is it not opening the stream socket? This really saves
time when looking at others' code.

Regards,
Mumit


--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com

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

* Re: Newbie with socket problems...(pretty long)
  1999-08-09 15:35 ` Mumit Khan
@ 1999-08-31 23:49   ` Mumit Khan
  0 siblings, 0 replies; 4+ messages in thread
From: Mumit Khan @ 1999-08-31 23:49 UTC (permalink / raw)
  To: Simon Gornall; +Cc: cygwin

Simon Gornall <simon@unique-id.com> writes:
> I've just downloaded a clean 'full install' of the B20.1 cygnus
> development
> environment, and I seem to be having problems with sockets. It's all
> linking
> correctly, and I can't seem to find anyone else with problems recently,
> so
> I assume I'm linking it incorrectly or something... If anyone cares to
> have a
> look and see what I'm doing wrong, I'd be very grateful. I'm *almost* at

I notice that you're using -mno-cygwin. You certainly want to read my
notes on using -no-cygwin available at:

  http://www.xraylith.wisc.edu/~khan/software/gnu-win32/

Also, while you're at the above URL, you may seriously consider upgrading
your compilers to gcc-2.95.

before doing things like:

> One thing I did have to do was move the libstdc++.a from the mwing32
> libraries directory to the 'standard'
> directory, or I got loads of 'undefined XXX' errors, where XXX where
> obviously global variables.

Remember that you're using Winsock, not Berkeley or POSIX sockets that's
common on Unix systems. For Winsock, you *have* to call WSAStartup
first (see windows docs on microsoft site or in your favorite w32 api
book). Unless you have other problems in the code, this should fix
it.

When you post asking for help, you really ought to try and explain 
better as to what problem you're having. For example, is it not 
connecting? Is it not opening the stream socket? This really saves
time when looking at others' code.

Regards,
Mumit


--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com

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

* Newbie with socket problems...(pretty long)
  1999-08-09 15:19 Newbie with socket problems...(pretty long) Simon Gornall
  1999-08-09 15:35 ` Mumit Khan
@ 1999-08-31 23:49 ` Simon Gornall
  1 sibling, 0 replies; 4+ messages in thread
From: Simon Gornall @ 1999-08-31 23:49 UTC (permalink / raw)
  To: cygwin

I've just downloaded a clean 'full install' of the B20.1 cygnus
development
environment, and I seem to be having problems with sockets. It's all
linking
correctly, and I can't seem to find anyone else with problems recently,
so
I assume I'm linking it incorrectly or something... If anyone cares to
have a
look and see what I'm doing wrong, I'd be very grateful. I'm *almost* at

the stage where I can have the same source tree across PC/Linux/Irix/Sun
:-)

Anyway, here's the code, ripped out of the application and wrapped with
a
'main' function:


extern "C" {
#  include <winsock.h>
};
#include <iostream.h>              // For errors etc.
#include <stdlib.h>                   // For atoi()


void die(char *msg)
 {
 cerr << "FATAL : " << msg << endl;
 exit(-1);
 }

int main(int argc, char **argv)
 {
 int   _debug  = 1;
 char *_host   = argv[1];
 int   _port   = atoi(argv[2]);
    int   _socket = -1;

    //
==================================================================
    // Connect to the server
    //
==================================================================
 struct sockaddr_in sk_addr;   // use sk_addr because s_addr is #defined
under cygwin.

 // Can't find bzero() ...
 for (unsigned int i=0; i<sizeof(sk_addr); i++)
  {
  char *val = ((char*)(&sk_addr+i));
  *val = 0;
  }

 sk_addr.sin_family      = AF_INET;
 sk_addr.sin_addr.s_addr = inet_addr(_host);
 sk_addr.sin_port        = htons(_port);

    //
==================================================================
 // Open a TCP socket
    //
==================================================================
 if ((_socket = socket(AF_INET, SOCK_STREAM, 0)) < 0)
  die("can't open stream socket");

    //
==================================================================
 // Connect to the server.
    //
==================================================================
 if (connect(_socket, (struct sockaddr *) &sk_addr, sizeof(sk_addr)) <
0)
  die("can't connect to server");

 if (_debug)
  cerr << "Fetcher: All initialised OK\n";
    return 0;
    }

This all works fine under Unix - with the correct includes etc - but it
bombs out when calling socket()
under cygwin, so I get the "Can't open stream socket" message. I can
connect to the service using
telnet however, so my server is running fine.

One thing I did have to do was move the libstdc++.a from the mwing32
libraries directory to the 'standard'
directory, or I got loads of 'undefined XXX' errors, where XXX where
obviously global variables.

I'm compiling it using 'c++ -mno-cygwin -o runtest test.cc -lwsock32'
Here's the output from the compiler:

Reading specs from
E:\GNU\CYGWIN~1\H-I586~1\BIN\..\lib\gcc-lib\i586-cygwin32\egcs-2.91.57\specs

gcc version egcs-2.91.57 19980901 (egcs-1.1 release)
 E:\GNU\CYGWIN~1\H-I586~1\BIN\..\lib\gcc-lib\i586-cygwin32\egcs-2.91.57\cpp.exe
-lang-c++ -v -iprefix
E:\GNU\CYGWIN~1\H-I586~1\BIN\..\lib/gcc-lib/i586-cygwin32\egcs-2.91.57\
-undef -D__GNUC__=2 -D__GNUG__=2 -D__cplusplus -D__GNUC_MINOR__=91
-Di386 -D_WIN32 -DWINNT -D_X86_=1 -D__STDC__=1
-D__stdcall=__attribute__((__stdcall__))
-D__cdecl=__attribute__((__cdecl__)) -D__declspec(x)=__attribute__((x))
-D__i386__ -D_WIN32 -D__WINNT__ -D_X86_=1 -D__STDC__=1
-D__stdcall=__attribute__((__stdcall__))
-D__cdecl=__attribute__((__cdecl__)) -D__declspec(x)=__attribute__((x))
-D__i386 -D__WINNT -Asystem(winnt) -Acpu(i386) -Amachine(i386)
-D__EXCEPTIONS -remap -Acpu(i386) -Amachine(i386) -Di386 -D__i386
-D__i386__ -Di586 -Dpentium -D__i586 -D__i586__ -D__pentium
-D__pentium__ -iwithprefixbefore
../../../../i586-cygwin32/include/mingw32 -D__MINGW32__=0.2 test.cc
C:\WINDOWS\TEMP\ccTaaPFf.ii
GNU CPP version egcs-2.91.57 19980901 (egcs-1.1 release) (80386, BSD
syntax)
#include "..." search starts here:
#include <...> search starts here:
 E:\GNU\CYGWIN~1\H-I586~1\BIN\..\lib\gcc-lib\i586-cygwin32\egcs-2.91.57\..\..\..\..\i586-cygwin32\include\mingw32

 E:\GNU\CYGWIN~1\H-I586~1\BIN\..\lib\gcc-lib\i586-cygwin32\egcs-2.91.57\..\..\..\..\..\include\g++

 E:\GNU\CYGWIN~1\H-I586~1\BIN\..\lib\gcc-lib\i586-cygwin32\egcs-2.91.57\..\..\..\..\..\include

 E:\GNU\CYGWIN~1\H-I586~1\BIN\..\lib\gcc-lib\i586-cygwin32\egcs-2.91.57\..\..\..\..\i586-cygwin32\include

 E:\GNU\CYGWIN~1\H-I586~1\BIN\..\lib\gcc-lib\i586-cygwin32\egcs-2.91.57\include

End of search list.
 E:\GNU\CYGWIN~1\H-I586~1\BIN\..\lib\gcc-lib\i586-cygwin32\egcs-2.91.57\cc1plus.exe
C:\WINDOWS\TEMP\ccTaaPFf.ii -quiet -dumpbase test.cc -mno-cygwin
-version -o C:\WINDOWS\TEMP\ccu7RywY.s
GNU C++ version egcs-2.91.57 19980901 (egcs-1.1 release) (i586-cygwin32)
compiled by GNU C version egcs-2.91.57 19980901 (egcs-1.1 release).
 E:\GNU\CYGWIN~1\H-I586~1\BIN\..\lib\gcc-lib\i586-cygwin32\egcs-2.91.57\..\..\..\..\i586-cygwin32\bin\as.exe
-o C:\WINDOWS\TEMP\ccmKtYoW.o C:\WINDOWS\TEMP\ccu7RywY.s
 E:\GNU\CYGWIN~1\H-I586~1\BIN\..\lib\gcc-lib\i586-cygwin32\egcs-2.91.57\collect2.exe
-o t.exe
E:\GNU\CYGWIN~1\H-I586~1\BIN\..\lib\gcc-lib\i586-cygwin32\egcs-2.91.57\..\..\..\..\i586-cygwin32\lib\crt1.o
-LE:\GNU\CYGWIN~1\H-I586~1\BIN\..\lib\gcc-lib\i586-cygwin32\egcs-2.91.57
-LE:\GNU\CYGWIN~1\H-I586~1\BIN\..\lib\gcc-lib
-LE:\GNU\CYGWIN~1\H-I586~1\BIN\..\lib\gcc-lib\i586-cygwin32\egcs-2.91.57\..\..\..\..\i586-cygwin32\lib
-LE:\GNU\CYGWIN~1\H-I586~1\BIN\..\lib\gcc-lib\i586-cygwin32\egcs-2.91.57\..\..\..
C:\WINDOWS\TEMP\ccmKtYoW.o -lwsock32 -lstdc++ -lm -lgcc -lmingw32
-lmoldname -lcrtdll -lkernel32 -ladvapi32 -lshell32 -lgcc



--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com

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

end of thread, other threads:[~1999-08-31 23:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-08-09 15:19 Newbie with socket problems...(pretty long) Simon Gornall
1999-08-09 15:35 ` Mumit Khan
1999-08-31 23:49   ` Mumit Khan
1999-08-31 23:49 ` Simon Gornall

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