|
-
Aug 26th, 2001, 05:39 PM
#1
Thread Starter
New Member
Winsock Function Question
Hey All,
I wonder if you can help me, I'm making a program, which, can be set to a port number, then, intercept it so any data coming in, out or both can be viewed to screen and logged, without interupting the program using that port.
I had a program that did this once and it was simply Invaluable!!
I have looked through several winsock control mod's but I'm not sure what method I should use to get this information. Please, someone help me with this because the program will be of great use to me once I finish it!
Thanx!
Jester
-
Sep 1st, 2001, 07:22 PM
#2
Thread Starter
New Member
Library: "Wininet" - Function: "InternetGetLastResponse"
Hey's,
It's me again, to help everybody (and myself) get a grip on this subject a bit more. I have found information about this particular API call located in the Wininet Library. I'm pretty sure this will do what I want it to do.
Here is some code I've got for it:
Declare Function InternetGetLastResponseInfo Lib "wininet.dll" Alias "InternetGetLastResponseInfoA" (lpdwError As Long, ByVal lpszBuffer As String, lpdwBufferLength As Long) As Boolean
Private Sub cmdStart_Click()
Call ShowError
End Sub
Sub ShowError()
Dim lErr As Long, sErr As String, lenBuf As Long
'get the required buffer size
InternetGetLastResponseInfo lErr, sErr, lenBuf
'create a buffer
sErr = String(lenBuf, 0)
'retrieve the last respons info
InternetGetLastResponseInfo lErr, sErr, lenBuf
'show the last response info
lstDataLog.AddItem lErr
End Sub
Now, the lErr variable always returns 0, being the length of the last response from the buffer, and if I replace it with "sErr", this is supposably is supposed to return the actual string of this data, but because the length is 0, it returns nothing.
I need two lots of questions answered here.
1) How can I set it so it only looks at one particular port, not just so just one buffer so it takes care of everything?
2) How can I get it so it returns everything? Not just the error's that get written to this buffer?
I would appreciate any and every bit of help is offered, this is sending me round the bend!
Best Regards,
Jester
-
Sep 2nd, 2001, 05:36 PM
#3
Fanatic Member
Info.
The function won't do what you want. Here is a description of the function from MSDN:
BOOL InternetGetLastResponseInfo(
OUT LPDWORD lpdwError,
OUT LPSTR lpszBuffer,
IN OUT LPDWORD lpdwBufferLength
);
Retrieves the last Win32 Internet function error description or server response on the thread calling this function.
Returns TRUE if error text was successfully written to the buffer, or FALSE otherwise. To get extended error information, callGetLastError. If the buffer is too small to hold all the error text, GetLastError returns ERROR_INSUFFICIENT_BUFFER, and the lpdwBufferLength parameter contains the minimum buffer size required to return all the error text.
lpdwError
Address of a variable that receives an error message pertaining to the operation that failed.
lpszBuffer
Address of a buffer that receives the error text.
lpdwBufferLength
Size of the lpszBuffer buffer. When the function returns, this parameter contains the size of the string written to the buffer.
The FTP and Gopher protocols can return additional text information along with most errors. This extended error information can be retrieved by using the InternetGetLastResponseInfo function wheneverGetLastError returns ERROR_INTERNET_EXTENDED_ERROR (occurring after an unsuccessful function call).
The buffer pointed to by lpszBuffer must be large enough to hold both the error string and a zero terminator at the end of the string. However, note that the value returned in lpdwBufferLength does not include the terminating zero.
InternetGetLastResponseInfo can be called multiple times until another Win32 Internet function is called on this thread. When another function is called, the internal buffer that is storing the last response information is cleared.
I dont think it is possible to monitor other ports for data which don't belong to your application in Visual Basic. You would probably need to use a 'lower level' language, such as C or ASM, and get down to some advanced socket programming...
Hope this helps.
Digital-X-Treme
Contact me on MSN Messenger: [email protected]
[VBCODE]Debug.Print Round(((1097) - ((55 ^ 5 + 311 ^ 3 - 11 ^ 3) _
/ (68 ^ 5))) ^ (1 / 7), 13)[/VBCODE]
-
Sep 3rd, 2001, 12:09 AM
#4
Thread Starter
New Member
GetLastResponse
Hey, thanx for your reponse
I only want it to parse (on a timer basis of about 100ms) the last string that was last written to buffer on "one port at-a-time".
I'm thinking that the function I have given will only parse the error's written to buffer, or does it mean it write's it first to buffer, then checks to see if it has error'ed out?
I wrote some code at home and I used the lErr to show the length of each string that comes in and it prints a 0 on each Call of the Sub (meaning that there is no data in the string) so I wasn't sure if it meant no data was coming in (which there surely must've have been some) or that there was data going through but none of it was an error.
The only language I know at all is VB (besides I know a little bit of Java) so I wouldn't know where to begin with C, nor would I be able to compile it.
But yeah, if any pros out there can shed some more light, it would be greatly appreciated (any help is).
Jester
-
Sep 3rd, 2001, 07:14 AM
#5
Fanatic Member
The function doesn't do what you want it to.Here is a description of the function:
Retrieves the last Win32 Internet function error description or server response on the thread calling this function.
So it either returns an error code, or server response on the thread calling the function. i.e. Unless your program is using a Win32 Internet function(s), you won't get any useful information from this function, as you cannot access information, unless your program created it...
Hope this helps.
Digital-X-Treme
Contact me on MSN Messenger: [email protected]
[VBCODE]Debug.Print Round(((1097) - ((55 ^ 5 + 311 ^ 3 - 11 ^ 3) _
/ (68 ^ 5))) ^ (1 / 7), 13)[/VBCODE]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|