一:sscanf的用法:
如文件中:event system 7 50000 local0可以得到
while( fgets( line, sizeof( line ), fd ) ){
sscanf( line,"%s%*[ \t]%s%*[ \t]%s%*[ \t]%s%*[ \t]%s%*[ \t\n]",name, val1, val2, val3, val4 )
}
二:关于网络字节序和主机字节序:
#include<netinet/in.h>
#include<sys/socket.h>
#include<sys/types.h>
#include<arpa/inet.h>
using namespace std;
int main(){
struct in_addr ia;
inet_aton("192.168.3.144",&ia);
cout<<"big endiean:"<<hex<<ia.s_addr<<endl;
cout<<"little endiean:"<<hex<<ntohl(ia.s_addr)<<endl;
return 0;
}
下面rename函数和unlink结合可以更改一个文件,先rename一下,然后修改,最后删除临时文件
三:rename函数:
rename(oldname,newname);
定义函数 int rename(const char * oldpath,const char * newpath);
函数说明 rename()会将参数oldpath 所指定的文件名称改为参数newpath所指
的文件名称。若newpath所指定的文件已存在,则会被删除。
四:unlink函数
从文件系统中删除一个名称。如果名称是文件的最后一个连接,并且没有其它进程将文件打开,名称对应的文件会实际被删除。
三:关于facility字段,简单的理解就是产生系统日志的来源,比如操作系统,进程,应用程序等
facility 字段,
Syslog uses the User Datagram Protocol (UDP), port 514, for communication. Being a
connectionless protocol, UDP does not provide acknowledgments. Additionally, at the
application layer, syslog servers do not send acknowledgments back to the sender for
receipt of syslog messages. Consequently, the sending device generates syslog messages
without knowing whether the syslog server has received the messages. In fact, the sending
devices send messages even if the syslog server does not exist.
The syslog packet size is limited to 1024 bytes and carries the following information:
• Facility
• Severity
• Hostname
• Timestamp
• Message
A clear understanding of each of the syslog packet parameters can help you easily deploy
syslog systems across your network. Note that the first two parameters, facility and severity,
are often misunderstood.
Facility
Syslog messages are broadly categorized on the basis of the sources that generate them.
These sources can be the operating system, the process, or an application. These categories,
called facility, are represented by integers, as shown in Table 4-1. The local use facilities
are not reserved and are available for general use. Hence, the processes and applications
that do not have pre-assigned facility values can choose any of the eight local use facilities.
As such, Cisco devices use one of the local use facilities for sending syslog messages.
Facility Values
Integer Facility
0 Kernel messages
1 User-level messages
2 Mail system
3 System daemons
4 Security/authorization messages
5 Messages generated internally by Syslogd
6 Line printer subsystem
7 Network news subsystem
8 UUCP subsystem
9 Clock daemon
10 Security/authorization messages
11 FTP daemon
12 NTP subsystem
13 Log audit
14 Log alert
15 Clock daemon
16 Local use 0 (local0)
17 Local use 1 (local1)
18 Local use 2 (local2)
19 Local use 3 (local3)
20 Local use 4 (local4)
21 Local use 5 (local5)
22 Local use 6 (local6)
23 Local use 7 (local7)