This function closes opened sockets, frees internal buffers. This function
fails only if a blocking call is in progress. In this case, it tries to cancel
the blocking call, thus the next Tcp4uCleanup succeeds.
If Tcp4uInit has not been called, Tcp4uCleanup returns TCP4U_SUCCESS.
The sample below shows a "simple" way to close a application using a Windows
message loop.
Syntax: Tcp4uCleanup ()
Return:
TCP4U_ERROR
|
A
Blocking call is in progress
|
TCP4U_SUCCESS
|
Cleanup
done
|
Example : case WM_TIMER : KillTimer (hWnd, wParam); PostMessage (hWnd, wParam, 0, 0l); break; case WM_CLOSE : if (Tcp4uCleanup ()==TCP4U_ERROR) { SetTimer (hWnd, WM_CLOSE, 500l, 0); return FALSE; } else { DestroyWindow (hWnd); PostQuitMessage (); } break;
This function initializes the internal structures of Tcp4u. The Windows
implementation calls WSAStartup which initializes the module Winsock.Dll.
It must be called by each task which want to use Tcp4u services.
Note: This call is not necessary in order to use the Unix functions, but
required for portability.
Syntax: Tcp4uInit ()
Return:
TCP4U_ERROR
|
(Windows
only) Tcp4w has not found a correct Winsock.Dll.
|
TCP4U_SUCCESS
|
Task
is registered.
|
Example : if (Tcp4uInit ( ) != TCP4U_SUCCESS) { MessageBox (hWnd, "Init Error", "Sample App", MB_OK); PostMessage (hWnd, WM_CLOSE, 0, 0l); }
Tcp4w returns the version number of the package as an integer. The low order
byte is the release number, the high order byte is the major version number.
The function copies in the user's buffer a string which contains information on
the pacakge (name, version, author, copyright). This string is guaranteed not
to exceed 100 characters.
Syntax: Tcp4uVer(LPSTR szVerStr, int nStrSize)
Arguments:
szVerStr
|
a
buffer which is to receive the version information
|
nStrSize
|
its
size
|
Return:
int
|
an
integer which contains the version.
|
Example: char szStr[100]; Tcp4uVer (szStr, sizeof szStr); Mprintf ("Using %s\n", szStr);
This function identifies the local station.
Note : The DWORD type depends on the platform. For Windows, the predefined
DWORD type has been chosen (a 4-bytes integer), for other platforms, this type
is defined as a 4 characters structure.
Syntax: TcpGetLocalID (LPSTR szStrName, int uNameSize, DWORD *lpAddress)
Arguments:
szStrName
|
A
pointer on a string which is to be filled with the name of the station. If the
pointer is NULL, the name of the station is not returned.
|
uNameSize
|
The
size of the buffer szStrName.
|
lpAddress
|
A
pointer on a double word which is to be filled with the IP address of the
station. If this pointer is NULL, the IP-Address is not returned.
|
Returns:
TCP4U_ERROR
|
The
IP-stack was unable to get the name of the local station.
|
TCP4U_OVERFLOW
|
The
name is longer than the given buffer.
|
TCP4U_SUCCESS
|
The
requested data are available.
|
Example: char StationName[64]; DWORD IPAddress; unsigned char *cAdd = (char *) &IPAddress; TcpGetLocalID( StationName, sizeof StationName, & IPAddress); printf ("Local Station is %s, Address %u.%u.%u.%u", StationName, cAdd[0], cAdd[1], cAdd[2], cAdd[3]);
This function causes Tcp4u to log events like errors, socket calls or Tcp4u
calls. It can be used to dump the frames sent and received by Tcp4u both in
hexadecimal and in ASCII.
On Windows platforms, the logs are generated using the OutputDebugString call,
they can be displayed by external tools like DbWin, Dbmon or DbWin32. On other
platforms, the logs are sent on stderr.
The action depends on the uMask argument which is any combination of the
following values :
LOG4U_CALL
|
0x0001
|
log
each tcp socket function
|
LOG4U_DBCALL
|
0x0002
|
log
db socket function
|
LOG4U_INTERN
|
0x0008
|
log
each application level call
|
LOG4U_PROC
|
0x0010
|
log
each Tcp4u/Tn4u APIs call
|
LOG4U_HIPROC
|
0x0020
|
log
each app level call
|
LOG4U_EXIT
|
0x0040
|
log
each Tcp4u/Tn4u APIs exit
|
LOG4U_HIEXIT
|
0x0080
|
log
each application level exit
|
LOG4U_DUMP
|
0x4000
|
dump
received/sent frames in Hexadecimal and ASCII
|
LOG4U_ERROR
|
0x8000
|
log
errors
|
LOG4U_ALL
|
0xFFFF
|
get
all logs
|
Syntax: Tcp4uEnableLog (unsigned uMask)
Arguments:
uMask
|
An
integer which precize the detail of reports
|
Exemple: Tcp4uEnableLog (LOG4U_ERROR | LOG4U_DUMP); HttpGetFile (szURL, NULL, "/tmp/file");
Output: > 47 45 54 20 2F 20 48 54 - 54 50 2F 31 2E 30 0D 0A GET / HTTP/1.0.. > 41 63 63 65 70 74 3A 20 - 69 6D 61 67 65 2F 67 69 Accept: image/gi > 66 2C 20 69 6D 61 67 65 - 2F 78 2D 78 62 69 74 6D f, image/x-xbitm > 61 70 2C 20 69 6D 61 67 - 65 2F 6A 70 65 67 2C 20 ap, image/jpeg, > 69 6D 61 67 65 2F 70 6A - 70 65 67 2C 20 2A 2F 2A image/pjpeg, */* > 0D 0A .. > 55 73 65 72 2D 41 67 65 - 6E 74 3A 20 48 74 74 70 User-Agent: Http > 34 75 20 62 79 20 50 68 - 2E 20 4A 6F 75 6E 69 6E 4u by Ph. Jounin > 20 61 6E 64 20 4C 2E 20 - 4C 65 20 42 72 61 73 0D and L. Le Bras. > 0A . > 0D 0A .. < 48 54 54 50 2F 31 2E 31 - 20 32 30 30 20 4F 4B HTTP/1.1 200 OK < 44 61 74 65 3A 20 54 75 - 65 2C 20 30 39 20 44 65 Date: Tue, 09 De < 63 20 31 39 39 37 20 31 - 33 3A 35 34 3A 30 34 20 c 1997 13:54:04 < 47 4D 54 0D 0A 53 65 72 - 76 65 72 3A 20 41 70 61 GMT..Server: Apa < 63 68 65 2F 31 2E 32 62 - 37 0D 0A 43 6F 6E 6E 65 che/1.2b7..Conne < 63 74 69 6F 6E 3A 20 63 - 6C 6F 73 65 0D 0A 43 6F ction: close..Co < 6E 74 65 6E 74 2D 54 79 - 70 65 3A 20 74 65 78 74 ntent-Type: text < 2F 68 74 6D 6C 0D 0A 4C - 61 73 74 2D 4D 6F 64 69 /html..Last-Modi < 66 69 65 64 3A 20 46 72 - 69 2C 20 31 39 20 53 65 fied: Fri, 19 Se < 70 20 31 39 39 37 20 31 - 32 3A 34 37 3A 31 35 20 p 1997 12:47:15 < 47 4D 54 0D 0A 45 54 61 - 67 3A 20 22 32 39 37 64 GMT..ETag: "297d < 30 2D 38 39 65 2D 33 34 - 32 32 37 34 35 33 22 0D 0-89e-34227453". < 0A 43 6F 6E 74 65 6E 74 - 2D 4C 65 6E 67 74 68 3A .Content-Length: < 20 32 32 30 36 0D 0A 41 - 63 63 65 70 74 2D 52 61 2206..Accept-Ra < 6E 67 65 73 3A 20 62 79 - 74 65 73 0D 0A 0D 0A nges: bytes....