Mail Archives: djgpp/1998/10/26/15:18:49
Hi all.
I thought I'd write a note explaining everything I had to
do to port client/server programs from UNIX to Win95, using DJGPP,
RSXNTDJ, winsock.h, and wsock32.dll. Note, the project was
originally compiled with gcc on solaris 2.5.
1. get and install dgjpp, and rsxntdj,
use the zip picker found at:
http://www.delorie.com/djgpp/
you'd 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 ended up installing most of the DJGPP software to have a 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), so
you might need more than just the stuff before the more complete
list. 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.
besure 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:
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
and define these in a header:
#define read(sock,buf,len) recv(sock,(LPSTR)buf,len,0)
#define write(sock,buf,len) send(sock,buf,len,0)
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. Using the makelib that came with rsxntdj:
makelib /windows/system/wsock32.dll -o wsock32.a
mv wsock32.a libwsock32.a
10. 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
--
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 -