Article View: borland.public.cppbuilder.nativeapi
Article #17552SystemHandleInformation
From: Boguslaw Fries
Date: Fri, 14 Mar 2003 10:18
Date: Fri, 14 Mar 2003 10:18
117 lines
4055 bytes
4055 bytes
I did already ask for, but I have some extra observations:
I did:
#define SystemHandleInformation 16
typedef struct _SYSTEM_HANDLE
{
DWORD dwProcessId;
BYTE bObjType;
BYTE bFlags;
WORD uHandle;
DWORD pObject; /*POBJECT*/
ULONG GrantedAccess; /*ACCESS_MASK*/
} SYSTEM_HANDLE, *LPSYSTEM_HANDLE;
typedef struct _SYSTEM_HANDLE
{
DWORD dwProcessId;
BYTE bObjType;
BYTE bFlags;
WORD uHandle;
DWORD pObject; /*POBJECT*/
ULONG GrantedAccess; /*ACCESS_MASK*/
} SYSTEM_HANDLE, *LPSYSTEM_HANDLE;
typedef struct _SYSTEM_HANDLE_INFORMATION
{
DWORD dwNumEntries;
SYSTEM_HANDLE systemHandles[ ANY_SIZE ];
} SYSTEM_HANDLE_INFORMATION, *LPSYSTEM_HANDLE_INFORMATION;
LPSYSTEM_HANDLE lpSystemHandle;
LPSYSTEM_HANDLE_INFORMATION lpSystemHandleInformation;
char szLocalAddr[512];
char szRemoteAddr[512];
int nRet;
SOCKADDR_IN name;
int namelen;
int speernamelen;
int optlen = 4;
int sockType = 0;
SOCKET s;
SOCKADDR_IN speer;
char s_log[ 256 ];
NtQuerySystemInformation( SystemHandleInformation,
lpSystemHandleInformation, dwLength, &dwReturnLength );
lpSystemHandle = ( LPSYSTEM_HANDLE )
lpSystemHandleInformation->systemHandles;
for ( dwCount = 0; dwCount < lpSystemHandleInformation->dwNumEntries;
dwCount++ )
{
hProc = OpenProcess( PROCESS_DUP_HANDLE, 1, lpSystemHandle->dwProcessId;
if ( hProc )
{
DuplicateHandle( hProc, ( HANDLE ) lpSystemHandle->uHandle,
hCurrentProcess, &hDup, STANDARD_RIGHTS_REQUIRED, FALSE, 0 );
CloseHandle( hProc );
}
if ( hDup )
{
name.sin_family = AF_INET;
namelen = sizeof( SOCKADDR_IN );
speernamelen = sizeof( SOCKADDR_IN );
s = ( SOCKET ) hDup;
nRet = getsockname( s, ( SOCKADDR *) &name, &namelen );
if ( nRet != SOCKET_ERROR )
{
nRet = getsockopt( s, SOL_SOCKET, SO_TYPE, (char *) &sockType,
&optlen );
if( ( nRet = getpeername( s, ( SOCKADDR *)&speer,
&speernamelen ) ) != SOCKET_ERROR )
{
sprintf( szRemoteAddr, "%s:%d", inet_ntoa(
speer.sin_addr ), ntohs( speer.sin_port ));
}
else
{
sprintf( szRemoteAddr, " ???.???.???.???:?????
%d\n", WSAGetLastError());
}
sprintf( szLocalAddr, "%s:%d", inet_ntoa(
name.sin_addr ), ntohs( name.sin_port ));
sprintf( s_log, " %d %s %-22s %-22s %d\n",
lpSystemHandle->bObjType, szSockType[ sockType ], szLocalAddr, szRemoteAddr,
lpSystemHandle->dwProcessId );
LogfileWrite( "tcpview.log", s_log ); // my own log
function but in this place doesnt matter
}
CloseHandle( hDup );
}
}
lpSystemHandle++;
}
This is a part of my code
And now my question:
All LocalAddress ARE OK!!! but szSockType[ sockType ] is WRONGLY ALLWAYS
UDP !!!
And szRemoteAddr is ALWAYS ???.???.???.???:????? and error is 10057 , but
of course is allways TRUE
What I did wrong , please help me
Best regards
Boguslaw Fries
Technical Details
Message-ID:
<3e71ab57@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-01!sn-xit-09!supernews.com!news.maxwell.syr.edu!newspeer1.nwr.nac.net!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,dd89ba217156913d,start X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-03-15 08:13:54 PST From: "Boguslaw Fries" <B.Fries@luca-online.de> Newsgroups: borland.public.cppbuilder.nativeapi Subject: SystemHandleInformation Date: Fri, 14 Mar 2003 11:18:42 +0100 Lines: 121 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 NNTP-Posting-Host: 217.225.29.162 Message-ID: <3e71ab57@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1047636823 217.225.29.162 (14 Mar 2003 02:13:43 -0800) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-01!sn-xit-09!supernews.com!news.maxwell.syr.edu!newspeer1.nwr.nac.net!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail