TTCPW
WINDOWS NT/95 PORT OF TTCP
N C S T A T E U N I V E R S I T Y
G r e g g G . S e i p p
1
A B S T R A C T
This paper outlines the Windows NT/95 port of TTCP. It includes porting issues, an example
session, and instructions on how to compile and install the program. Appendix A includes the
complete original manual for TTCP.
T A B L E O F C O N T E N T S
ABSTRACT ...............................................................................................................................................................2
TABLE OF CONTENTS.......................................................................................................................................2
INTRODUCTION ..................................................................................................................................................2
PORTING ISSUES AND SOLUTIONS ............................................................................................................3
SOCKETS..................................................................................................................................................................3
TIMING.....................................................................................................................................................................3
ERRATA ....................................................................................................................................................................3
EXAMPLE RUNS....................................................................................................................................................4
INSTALLATION.....................................................................................................................................................6
COMPILATION ......................................................................................................................................................6
APPENDIX A...........................................................................................................................................................7
ORIGINAL TTCP DOCUMENTATION .........................................................................................................7
I N T R O D U C T I O N
TTCPW is a port of TTCP, designed to run on the Windows NT/95 platforms. It is designed to
keep the source code as similar to the original program as possible. As such, I made as few changes as
practical. These changes included adding Win32 specific functions, changing existing calls, and
replacing the code that does the timing. (I decided to strip out the UNIX timing code rather than
#ifdef it because it would have required a large number of #ifdef statements to modify it for Win32
usage.) The positive side of this is code that is much closer to ANSI—it would be very easy to modify
this code to compile and run in UNIX. On the negative side, the timing functions do not contain near
the levels of granularity that was contained in the UNIX code (milliseconds rather than microseconds).
2
P O R T I N G I S S U E S A N D S O L U T I O N S
There were a number of issues involved in porting TTCP to the Windows environment. First and
foremost were the issues surrounding differences between BSD sockets (the sockets used in the UNIX
environment) and Windows sockets.
SOCKETS
Microsoft has implemented several functions specific to their operating systems. Two of these
functions, WSAStartup() and WSACleanup(), must be called by any application using sockets.
WSAStartup() initializes the Windows socket dynamic link library. An application calls WSACleanup()
when it is finished using sockets. These functions were added to TTCP at the top and bottom of the
main() function.
TCP data transfer under Berkeley sockets is performed with the general-purpose I/O functions
read() and write(). In Windows Microsoft chose to implement two socket specific data transfer
functions: recv() and send(). The reason is because of the way Windows sockets are implemented. The
call to socket() under BSD returns an int which can, in many ways, be treated as a file handle. The same
call in Windows returns a socket handle (data type SOCKET). This socket handle is not in any way
compatible with the file system. The following table shows the similarity between the Windows
functions and the BSD functions.
BSD function
Windows function
int write(socket_handle, buffer, count);
int send(socket_handle, buffer, count, flag);
int read(socket_handle, buffer, buffer_size);
int recv(socket_handle, buffer, buffer_size, flag);
As you can see, the only major difference between the two is an extra, rarely used flag parameter at
the end of the Windows calls. BSD sockets closes sockets with the close() function. Again, since
Windows sockets are not implemented as file handles they have implemented a separate function
closesocket() to perform this task.
TIMING
UNIX has a variety of timing functions available which provide clock counts all the way down to
the microsecond. In contrast, Windows has but a few. Only one of these functions provide a
resolution below one second: the clock() function. This is an ANSI compatible function which returns
the number of milliseconds since the computer was turned on. All of the UNIX timing function calls
were reworked to work with this single function. So while the timing routines are now ANSI
compatible, they do not contain the level of accuracy that the original timing functions contain.
ERRATA
1.The rest of the porting issues were concerned with minor differences between the UNIX and
Windows run-time libraries. The read() and write() calls used to read and write to STDIN and STDOUT
were replaced with _read() and _write(), the Microsoft implementations of the same functions. Also
bzero(), was replaced with the ANSI compatible function memset().
评论0