linux 下的学习

一: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)


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值