Message-ID: <36372657.5842936B@clover.c2d.fedex.com> Date: Wed, 28 Oct 1998 08:12:39 -0600 From: Walter Moore Organization: Federal Express X-Sender: "Walter Moore" (Unverified) X-Mailer: Mozilla 4.04 [en]C-FedExIntl (Win95; I) MIME-Version: 1.0 To: "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 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit 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 and not use the usual include files for networking. Here were my include files: #ifdef __DJGPP__ #include #else #include #include #include #include #include #endif /* DJGPP */ #include #include #include #include #include #include 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