|
actually server have priority 0 to 7 whc catagories the level of access by unauthorizes person and save it at syslog txt file! As below:
Numerical Severity<br />
Code<br />
<br />
0 Emergency : system is unusable<br />
1 Alert : action must be taken immediately<br />
2 Critical : critical conditions<br />
3 Error : error conditions<br />
4 Warning : warning conditions<br />
5 Notice : normal but significant condition<br />
6 Informational: informational messages<br />
7 Debug : debug-level messages
the syslog txt file contain priority and ip address as below:
<133>Jul 26 10:32:48 sensor SFIMS: [1:499:4] ICMP Large ICMP Packet [Classification: Potentially Bad Traffic] [Priority: 2] {ICMP} 192.168.2.25 -> 202.76.239.1
I need urs help that hw to automatically shut down the certain pc by knowing the ip address when the priority 0(emergency) is more than lets say 100 times!
-- modified at 2:37 Friday 2nd September, 2005
|
|
|
|
|
I'm trying to call the SystemParametersInfo() function in User32.dll from my C/C++ code on Win2k but it's not working. I've used the same code to successfully call a function from a different dll (kernel32.dll) so I'm confused. The LoadLibrary command works, but the GetProcAddress command is not, thus I get the output:
started it up...
loaded library...trying to find address of function...
proc addr: 0
couldn't get proc addr
I'm compiling with Visual Studio.net 2003. Any suggestions would be greatly appreciated. Thanks.
<br />
<br />
<br />
<br />
#include <stdio.h><br />
#include <windows.h><br />
<br />
#define _WIN32_WINNT 0x0500<br />
<br />
typedef BOOL (*MYPROC) (UINT, UINT, PVOID, UINT);<br />
HINSTANCE hinstLib; <br />
MYPROC ProcAdd; <br />
<br />
BOOL result;
UINT uiAction;
UINT uiParam;
PVOID pvParam;
UINT fWinIni;
<br />
int main()<br />
{<br />
printf("started it up...\n");<br />
hinstLib = LoadLibrary("User32.dll");<br />
<br />
if (hinstLib != NULL) <br />
{ <br />
printf("loaded library...trying to find address of function...\n");<br />
ProcAdd = (MYPROC) GetProcAddress(hinstLib, "SystemParametersInfo"); <br />
printf("proc addr: %d\n", ProcAdd);<br />
if (!ProcAdd) <br />
{<br />
printf("couldn't get proc addr\n");<br />
FreeLibrary(hinstLib);<br />
return 1;<br />
}<br />
printf("got proc addr...calling function\n");<br />
result = (ProcAdd) (uiAction, uiParam, pvParam, fWinIni); <br />
} <br />
else <br />
{<br />
printf("Failed to load lib\n");<br />
}<br />
<br />
FreeLibrary(hinstLib);<br />
printf("freed lib\n");<br />
return 0;<br />
}<br />
|
|
|
|
|
|
Thanks! "SystemParametersInfoA" worked! I never would have gotten that without your help.
|
|
|
|
|
|
how to define a const multileline string as
const string TEMPLATE = "HELLO!
IF YOU CAN HELP ME ,
I WILL THANK YOU VERY MUCH";
this can not pass complie
I love Programming
|
|
|
|
|
const string TEMPLATE = "HELLO!\nIF YOU CAN HELP ME ,\nI WILL THANK YOU VERY MUCH";
|
|
|
|
|
sorry , i don't want the "\n", because it not readable
if there is a solution that present multile line is very good!
I love Programming
|
|
|
|
|
I'm afraid you are not in a position to write the language yourself, you have to live with the language as it exists. Best you can do is this:
#define NEWLINE \r\n
and then use NEWLINE, or something similar.
In any case, \n won't work, it's \r\n ( or \n\r, I forget ).
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
|
the solution as:
const string TEMPLATE =
"HELLO! \n\
IF YOU CAN HELP ME ,\n\
I WILL THANK YOU VERY MUCH!";
I love Programming
|
|
|
|
|
Do you want it to be multiline only in your source code
const string TEMPLATE = "These three string literals will be "
"concatenated and the result assigned "
"to TEMPLATE as a single string";
or do you want it to contain multiple lines
const string TEMPLATE = "These are the first,\r\nsecond,\r\nand third lines";
or both?
const string TEMPLATE = "These are the first,\r\n"
"second,\r\n"
"and third lines";
--
jlr
http://jlamas.blogspot.com/[^]
|
|
|
|
|
very good! what i need is the third solution , both the source code in multiline and the output! thank you! thanks all!
I love Programming
|
|
|
|
|
I want to create a CEdit as a child window of a CListCtrl when CListCtrl is si created and destroy it when CListCtrl is destroyed.
I declare a member var in CListCtrl like this, CEdit m_edit,
and use m_edit.Create(...) in CListCtrl's constructor or CListCtrl's OnCreate,
but it doesn't work, the m_edit.m_hWnd is 0.
|
|
|
|
|
It won't work in the list control constructor because you need to pass the list's hWnd to m_edit.Create and hWnd will be null at that point.
I think it should work in the list's OnCreate, though. Post some code to see how you are doing it...
--
jlr
http://jlamas.blogspot.com/[^]
|
|
|
|
|
in mylist.h
class CMyList:
{
private:
CEdit m_edit;
}
in mylist.cpp
int CMyList::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CListCtrl::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
edit.Create(WS_BORDER|ES_AUTOHSCROLL,CRect(0,0,1,1),this,0);
return 0;
}
|
|
|
|
|
I don't see anything obviously wrong, but the problem might be with using zero as the control id. Try using a non zero id.
As a reference, the example shown in the documentation is as follows:
Create(ES_MULTILINE | WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER,
CRect(10, 10, 100, 100), this, 1);
Hope that helps,
--
jlr
http://jlamas.blogspot.com/[^]
|
|
|
|
|
I edit a program that write by my supervisor and it was a server source code.
After I edit, I found out three error. Can anybody solve it?
#include "stdafx.h"
#define DEFAULT_TCPPORT 1000;
typedef struct
{
SOCKET Skt;
SOCKADDR_IN AddrFrom;
int nAddrFromLen;
LPVOID ParamPointer;
}SOCKETDATA;
SOCKET ServerSkt;
SOCKET eServerSkt;
CString ServerStatus="Waiting for Request(s)....";
CString PortStatus="Starting TCP/IP Services.";
long SocketClosedDelay=DEFAULT_DELAY;
UINT ListenThread(LPVOID lParam)
{
HANDLE hThread;
SOCKADDR_IN SktAddr;
char szMessage[300];
ServerSkt = socket ( AF_INET, SOCK_STREAM, 0 );
if ( ServerSkt == INVALID_SOCKET )
{
printf("Error INVALID_SOCKET 1\n");
}
else
{
SktAddr.sin_family=AF_INET;
SktAddr.sin_port=htons(6000);
SktAddr.sin_addr.s_addr=htonl("127.0.0.1");
if ( bind ( ServerSkt, ( LPSOCKADDR ) &SktAddr, sizeof ( SktAddr ) ) == SOCKET_ERROR )
{
printf("Error INVALID_SOCKET 2\n");
}
else
{
if ( listen ( ServerSkt, SOMAXCONN ) == SOCKET_ERROR )
{
printf("Error INVALID_SOCKET 3\n");
}
else
{
return 0;
}
}
}
return 0;
}
UINT AcceptThread ( LPVOID lParam )
{
SOCKADDR_IN AddrFrom;
int nAddrFromLen = sizeof ( AddrFrom );
SOCKETDATA* psktData;
HANDLE hThread;
char szMessage[300];
while (hHeap!=NULL)
{
psktData -> Skt = accept ( ServerSkt, ( LPSOCKADDR ) &AddrFrom, &nAddrFromLen );
if ( psktData -> Skt == INVALID_SOCKET )
{
printf("Error INVALID_SOCKET 4\n");
HeapFree ( hHeap, 0, psktData ); break;
}
psktData -> AddrFrom = AddrFrom;
psktData -> nAddrFromLen = nAddrFromLen;
psktData -> ParamPointer = lParam;
}
return 0;
}
UINT ClientThread ( LPVOID lParam )
{
SOCKETDATA* psktClient = ( SOCKETDATA* ) lParam;
SOCKET MySkt = psktClient -> Skt;
LPVOID ParamPointer = psktClient ->ParamPointer;
SOCKADDR_IN MyAddrFrom = psktClient -> AddrFrom;
int nMyAddrFromLen = psktClient -> nAddrFromLen;
IN_ADDR InFrom;
long nBytesRecv;
long nBytesSent;
char ReceivedData [400];
char ReceivedDataP[400];
char szMessage[300];
char RequestStr [400];
char RespondStr [400];
char RespondStrA[400];
long Count1;
long Count2;
long i=0, j=0;
BOOL DataRequest=FALSE;
BOOL S;
HeapFree ( hHeap, 0, psktClient );
nBytesRecv = recv ( MySkt, ReceivedData, sizeof(ReceivedData), 0 );
if (nBytesRecv==SOCKET_ERROR)
{
printf("Error INVALID_SOCKET 5\n");
closesocket ( MySkt );
}
else
{
DataRequest=TRUE;
ReceivedData[nBytesRecv]=NULL;
for(i; i<nbytesrecv; i++)
="" {
="" if(((receiveddata[i]="" &="" 0xf0)="" ^="" 0x00="" !="0x00)" &&="" ((receiveddata[i]="" 0x10="" (receiveddata[i]="" 0x80="" 0x90=""
="" 0xa0="" 0xb0="" 0xc0="" 0xd0="" 0xe0="" 0xf0="" if(receiveddata[i]!="0x20)
" receiveddatap[j]="ReceivedData[i];
" j++;
="" }
="" }
="" memcpy="" (="" &infrom,="" &myaddrfrom.sin_addr.s_addr,="" 4="" );
="" if(datarequest="=TRUE)
" wsprintf(requeststr,="" "%s;",="" inet_ntoa="" (infrom));
="" strcat="" (requeststr,="" receiveddatap);
="" strcpy(respondstra,="" cachedatapop(receiveddatap));
="" if(strcmp(respondstra,="" "null")!="0)
" cachehit="TRUE;
" if(cachehit="=FALSE)
" waitforsingleobject(requestqempty,="" infinite);
="" s="RequestStringPush(RequestStr);
" releasesemaphore(requestqfull,="" 1,="" &count1);
="" while(s="=FALSE)
" sleep="" (30);
="" &count1);
="" }=""
="" "%s",="" waitforsingleobject(respondqfull,="" infinite);="" strcpy(respondstr,="" respondstringextract(requeststr));
="" releasesemaphore(respondqempty,="" &count2);
="" while(strcmp(respondstr,="" "null")="=0)
" if(debugsession="=TRUE)
" writerespondlog(respondstr);
="" nbytessent="send" (myskt,="" respondstr,="" lstrlen(respondstr),="" 0);
="" if(nbytessent="=SOCKET_ERROR)
" wsprintf(szmessage,="" "send()="" error.="" unable="" to="" send="" respond="" packet="" %s="" -="" data="" discarded.",="" writesyslog(szmessage);
="" serverstatus="szMessage;" ::sendmessage((hwnd)="" parampointer,="" wm_timer,="" (wparam)="" 25,="" (lparam)="" 0);
="" sleep(socketcloseddelay);
="" closesocket="" (myskt);
="" writetocache(receiveddatap,="" respondstr);
="" wsprintf(respondstr,="" strcat(respondstr,="" respondstra);
="" (myskt);
="" return="" 0;
}
uint="" closeconnection(lpvoid="" lparam)
{
="" char="" szmessage[300];
="" if(serverskt="" (serverskt);
="" if(eserverskt="" (eserverskt);
="" "(closeconnection)="" all="" services="" stopped="" and="" connections="" closed.");
="" 0;
}
uint="" exitlistenthread(lpvoid="" lparam)=""
{
="" handle="" hthread;
="" sockaddr_in="" sktaddr;
="" "(exitlistenthread)="" starting="" tcp="" ip="" initialisations.");
="" eserverskt="socket" af_inet,="" sock_stream,="" 0="" );="" if="" invalid_socket="" )
="" socket()="" create="" server="" socket.");
="" writesyslog(szmessage);
="" else
="" sktaddr.sin_family="AF_INET;
" sktaddr.sin_port="htons(6000);
" sktaddr.sin_addr.s_addr="htonl(INADDR_ANY);
" bind="" eserverskt,="" lpsockaddr="" )="" &sktaddr,="" sizeof="" sktaddr="" socket_error="" printf("error="" 7\n");
="" socket="" binding="" completed="" successfully.");
="" listen="" somaxconn="" 8\n");
="" listening="" stage="" hthread="AfxBeginThread" (exitacceptthread,lparam,thread_priority_normal);
="" null="" 4\n");
="" else="" {="" 0;
="" exitacceptthread="" lpvoid="" lparam="" )
{
="" addrfrom;
="" int="" naddrfromlen="sizeof" addrfrom="" socketdata*="" psktdata;
="" "(exitacceptthread)="" begining="" connection="" accepting="" stage.");
="" eheap="GetProcessHeap();
" if(eheap="=NULL)
" getprocessheap()="" request="" for="" system="" heap.");
="" while="" (eheap!="NULL)
" {
="" psktdata="(" heapalloc="" eheap,="" 0,="" socketdata="" );
="" heapalloc()="" allocate="" memory.");
="" break;
=""> Skt = accept ( eServerSkt, ( LPSOCKADDR ) &AddrFrom, &nAddrFromLen );
if ( psktData -> Skt == INVALID_SOCKET )
{
wsprintf(szMessage, "(ExitAcceptThread) - accept() Error. Server Unable to Accept Connection Request.");
WriteSysLog(szMessage);
HeapFree ( eHeap, 0, psktData );
break;
}
psktData -> AddrFrom = AddrFrom;
psktData -> nAddrFromLen = nAddrFromLen;
psktData -> ParamPointer = lParam;
hThread = AfxBeginThread ( ( AFX_THREADPROC ) ExitClientThread, ( LPVOID ) psktData, THREAD_PRIORITY_NORMAL, 0, 0, NULL );
if ( hThread == NULL )
{
wsprintf(szMessage, "(ExitAcceptThread) - AfxBeginThread() Error. Unable to Create ExitClientThread() Thread.");
WriteSysLog(szMessage);
HeapFree ( eHeap, 0, psktData );
closesocket ( psktData -> Skt );
break;
}
}
return 0;
}
UINT ExitClientThread ( LPVOID lParam )
{
SOCKETDATA* psktClient = ( SOCKETDATA* ) lParam;
SOCKET MySkt = psktClient -> Skt;
LPVOID ParamPointer = psktClient ->ParamPointer;
SOCKADDR_IN MyAddrFrom = psktClient -> AddrFrom;
int nMyAddrFromLen = psktClient -> nAddrFromLen;
IN_ADDR InFrom;
long nBytesRecv;
char ReceivedData [500];
char ReceivedDataP[500];
char RequestStr[600];
char szMessage[300];
long i=0, j=0;
BOOL ShutdownRequest=FALSE;
HeapFree ( eHeap, 0, psktClient );
nBytesRecv = recv ( MySkt, ReceivedData, sizeof(ReceivedData), 0 );
Sleep(SocketClosedDelay);
closesocket ( MySkt );
if (nBytesRecv==SOCKET_ERROR)
{
wsprintf(szMessage, "(ExitClientThread) - recv() Error. Server Shutdown Request Ignored.");
WriteSysLog(szMessage);
}
else if (nBytesRecv==0)
{
wsprintf(szMessage, "(ExitClientThread) - recv() - 0 Byte Data Received. Server Shutdown Request Ignored.");
WriteSysLog(szMessage);
}
else if (nBytesRecv<10)
{
wsprintf(szMessage, "(ExitClientThread) - recv() - Corrupted Shutdown Request Packet Received - Discarded. Server Shutdown Request Ignored.");
WriteSysLog(szMessage);
}
else
{
ShutdownRequest=TRUE;
ReceivedData[nBytesRecv]=NULL;
for(i; i
|
|
|
|
|
It looks like CString is not defined. If you're not using MFC, why not use std::string ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
when I use std::string but got error below:
error C2653: 'std' : is not a class or namespace name
|
|
|
|
|
You also need to include headers for string, it's just easier to get there if your app is not using MFC.
#include <string>
using std::string;
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
It accur more error. I think nevermind.
The program that I edit have AfxBeginThread but I don't want it. But I cant confirm whether it correct or not. Below is the ListenThread and I just disable the AfxBeginThread.
UINT ListenThread(LPVOID lParam)
{
HANDLE hThread;
SOCKADDR_IN SktAddr;
char szMessage[300];
ServerSkt = socket ( AF_INET, SOCK_STREAM, 0 );
if ( ServerSkt == INVALID_SOCKET )
{
printf("Error INVALID_SOCKET 1\n");
}
else
{
SktAddr.sin_family=AF_INET;
SktAddr.sin_port=htons(6000);
//SktAddr.sin_addr.s_addr=htonl(INADDR_ANY);
SktAddr.sin_addr.s_addr=htonl("127.0.0.1");
if ( bind ( ServerSkt, ( LPSOCKADDR ) &SktAddr, sizeof ( SktAddr ) ) == SOCKET_ERROR )
{
printf("Error INVALID_SOCKET 2\n");
}
else
{
if ( listen ( ServerSkt, SOMAXCONN ) == SOCKET_ERROR )
{
printf("Error INVALID_SOCKET 3\n");
}
else
{
/*hThread=AfxBeginThread (AcceptThread,lParam,THREAD_PRIORITY_NORMAL);
if ( hThread == NULL )
{
wsprintf(szMessage, "(ListenThread) - AfxBeginThread() Error. Unable to Create AcceptThread() Thread.");
WriteSysLog(szMessage);
}
else
{
wsprintf(szMessage, "(ListenThread) - AcceptThread() Thread Spinoff Completed Successfully.");
WriteSysLog(szMessage);
return 0;
}*/
}
}
return 0;
}
}
}
return 0;
}
The AfxBeginThread have a AcceptThread, how do I simplify it if I don't want the AfxBeginThread? Below is the AcceptThread code:
UINT AcceptThread ( LPVOID lParam )
{
SOCKADDR_IN AddrFrom;
int nAddrFromLen = sizeof ( AddrFrom );
SOCKETDATA* psktData;
HANDLE hThread;
char szMessage[300];
while (hHeap!=NULL)
{
psktData -> Skt = accept ( ServerSkt, ( LPSOCKADDR ) &AddrFrom, &nAddrFromLen );
if ( psktData -> Skt == INVALID_SOCKET )
psktData -> AddrFrom = AddrFrom;
psktData -> nAddrFromLen = nAddrFromLen;
psktData -> ParamPointer = lParam;
hThread = AfxBeginThread ( ( AFX_THREADPROC ) ClientThread, ( LPVOID ) psktData, THREAD_PRIORITY_NORMAL, 0, 0, NULL );
if ( hThread == NULL )
{
wsprintf(szMessage, "(AcceptThread) - AfxBeginThread() Error. Unable to Create ClientThread() Thread.");
WriteSysLog(szMessage);
HeapFree ( hHeap, 0, psktData );
closesocket ( psktData -> Skt );
break;
}
}
return 0;
}
|
|
|
|
|
In my app I need to right a function to search through all the files in a directory for a particular statement. Is there a way my program can retrieve a list of the files in a directory so that I can step through that list and open one at a time?
Danny
|
|
|
|
|
If you use MFC you might look at CFileFind
Cheers,
|
|
|
|
|
|