www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/10/28/08:14:18

Message-ID: <36372657.5842936B@clover.c2d.fedex.com>
Date: Wed, 28 Oct 1998 08:12:39 -0600
From: Walter Moore <walter AT clover DOT c2d DOT fedex DOT com>
Organization: Federal Express
X-Sender: "Walter Moore" <walter AT clover DOT c2d DOT fedex DOT com> (Unverified)
X-Mailer: Mozilla 4.04 [en]C-FedExIntl (Win95; I)
MIME-Version: 1.0
To: "djgpp AT delorie DOT com" <djgpp AT delorie DOT com>, eliz AT is DOT elta DOT co DOT il
Subject: UPDATE: port socket based client server from Unix to Win95
Reply-To: djgpp AT delorie DOT com

I had a few typos and found I had to add something to the makefile
to make everything work perfectly, so I figured I'd update my
little FAQ on porting sockets (TCP/IP) based client server apps
from Unix to Win95. The port ran on Win98, whether or not I 
recompiled on that platform.

These are the steps I had to undergo to sucessfully port my
TCP/IP sockets client-server application from Unix (Solaris 2.5) 
to Win95, using DJGPP, RSXNTDJ, winsock.h, and wsock32.dll.

1. Get and install dgjpp, and rsxntdj, and the complete unix-like
   environment (djdev201, djlsr201, djst201, djcrx201,
   faq210b, rhide11b, binutils, bash, bison, diffutils, fileutils,
   findutils, fles, gcc, gdb, gpp, grep, awk, gzip, ispell, libg++,
   less, make, ObjC, path, sed, sh-utils, textutils, rsxntdj). 
   Use the zip picker found at:
   http://www.delorie.com/djgpp/
   You'll need C, C++ and assembler, you can get rhide if you like
   integrated environments, I never used it, though I did install it.
   I did not need the extra documentation formats, as the zip files
   with the binaries had the man pages. You'll DEFINITELY need RSX,
   so as to be able to use the Win95 wsock32.dll.

   I also ended up moving all the *.1 *.5n and *.7n files from 
   c:\djgpp\info into c:\djgpp\man\man1, man5, and man7,
   renaming the *.5n to *.5 and *.7n to *.7 so man would work better.

   Be sure to read each readme file that comes with the various
   packages, as there is often something that needs to be added to
   autoexec.bat or c:\djgpp\djgpp.env.

2. Get, install and patch the MSSDK headers for use with RSXNTDJ:
   get http://webhome.idirect.com/~eschunk/mssdk/rsxpatch.zip
   unzip rsxpatch.zip (assume to \tmp)
   get
   http://mssjus.www.conxion.com/msdownload/platformsdk/i386/iBLDENV.Exe
   run iBLDENV.Exe (assume to c:\MSSDK)
   copy c:\MSSDK\include\*.* \rsxntdj\include\mssdk
   copy c:\tmp\patch.exe c:\djgpp\contrib\rsxntdj\include\mssdk
   copy c:\tmp\sdkpatch.dif c:\djgpp\contrib\rsxntdj\include\mssdk
   cd c:\djgpp\contrib\rsxntdj\include\mssdk
   patch<sdkpatch.dif
   copy c:\tmp\specspat.dif c:\djgpp\contrib\rsxntdj\lib

   Now patch the original rsxntdj specs file:
   mv patch.exe c:\djgpp\contrib\rsxntdj\lib
   patch<specspat.dif

   If you have problems getting the MicroSoft Software
   Development Kit, go to http://msdn.microsoft.com/developer/sdk/
   to read more about it, or to find its new location. If the site
   is busy, you can find another site by going to
   http://www.microsoft.com/msdownload/platformsdk/bldenv.htm
   and  then get and install the Microsoft Software Dev. Kit, so
   you can use the include directory (you might have to register
   for this, but its free, I think).

3. You can ensure the changes you make to code is strictly for
   ths DJGPP compiler by putting those changes between
  #ifdef __DJGPP__
  #endif

4. I had to use <winsock.h> and not use the usual include files
   for networking. Here were my include files:

   #ifdef __DJGPP__
   #include     <winsock.h>
   #else
   #include     <netdb.h>
   #include     <sys/types.h>
   #include     <sys/socket.h>
   #include     <netinet/in.h>
   #include     <arpa/inet.h>
   #endif /* DJGPP */
   #include     <unistd.h>
   #include     <stdio.h>
   #include     <stdlib.h>
   #include     <errno.h>
   #include     <time.h>
   #include     <string.h>

5. If you used getopt(), you'll need to redefine the following:
   #define getopt _getopt
   #define optarg _optarg
   #define optind _optind

   Along these lines, if you use the 'extern int environ',
   you will have to declare it in the main definition, like:
   main(int argc, char **argv, char **environ)
   and you'll have to pass it to any subroutines, otherwise,
   the compiler will try to link in winmain().
   You may also have to #define environ _environ (although since
   I did the above definition of main, it was not necessary).

6. If you used read() and write(), and declared the sockets as int,
   you'll have to change declarations of sockets from int to SOCKET,
   and change all error checking of sockets from -1 or < 0 to check
   for INVALID_SOCKET, and define read as recv, and write as send:
   check bind() result for SOCKET_ERROR, rather than <0
   check accept() result for INVALID_SOCKET rather than -1
   check socket() result for INVALID_SOCKET rather than -1
   check connect() result for SOCKET_ERROR rather than -1

   This is how I did the defines in a header:
   #ifdef __DJGPP__
   #define read(sock,buf,len) recv(sock,(LPSTR)buf,len,0)
   #define write(sock,buf,len) send(sock,buf,len,0)
   #else /* Not DJGPP, so must define these to work in UNIX */
   #define INVALID_SOCKET -1
   #define SOCKET_ERROR -1
   #endif /* DJGPP */

7. Start MS Windows' socket API at beginning of main():

  #ifdef __DJGPP__
    /****************************************************************/
    /* Lets let the Windows Socket API startup,                     */
    /* telling it we want Winsock 1.1.                              */
    /****************************************************************/
    WSADATA wsaData;
    if (WSAStartup(MAKEWORD(1,1), &wsaData) != 0) {
        return 255;
    }
  #endif

8. Shutdown the MS Windows' socket API at end of main():

  #ifdef __DJGPP__
    /****************************************************************/
    /* Lets let the Windows Socket API cleanup.                     */
    /****************************************************************/

    /* blocking call ? */
    if (WSAIsBlocking())  {
          WSACancelBlockingCall ();
    }
    WSACleanup ();
  #endif

9. Create a library that you can link to by using the 
   makelib that came with rsxntdj and the wsock32 that 
   comes with Win95 - my experiments show programs compiled
   on a Win95 machine will work on a Win98 machine with no
   changes or recompilation:

   makelib /windows/system/wsock32.dll -o wsock32.a
   mv wsock32.a libwsock32.a

10. Add a line to the make file:
   SHELL = /bin/sh
    and then copy $DJGPP/bin/bash to $DJGPP/bin/sh
    and ensure $DJGPP/bin is in your path. in the PC world,
    Make will search your path for the location of sh, if 
    it is not located in /bin, but in the UNIX world, it 
    will always be in existence.  This will ensure the 
    makefile will work on PC and UNIX.

11. Be sure to compile with the -Zwin32 flag and link with
   the -I. -lwsock32 flags, ensuring the right things are compiled
   and linked in.

Good luck!
-- 
Walter Moore                Sr. Programmer Analyst
Federal Express             wbmoore AT fedex DOT com
2813 Business Park          Memphis TN 38118 USA
work: 901-369-2640          fax: 901-369-3634

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019