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]

Newbie with socket problems...(pretty long)


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


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