- 博客(14)
- 收藏
- 关注
原创 Python错误和异常
<br />Python允许在程序执行的时候检测错误, 当检测当一个错误时, Python解释器就引发一个异常, 并显示异常的详细信息。<br /> <br />我们可以使用try-except语句块来捕获和处理异常。<br /> <br />>>>try:<br />... a = input("Input: ")<br />... except SyntaxError, e:<br />... print "Error: ", e<br />...<br />Input
2010-07-16 14:56:00
488
原创 Python工厂函数
int(), float(), str(), complex(), list(), tuple(), dict(), file()
2010-07-16 14:43:00
789
原创 列表解析
Python中的一个语言特性, 比较有趣。>>> squared = [ x ** 2 for x in range(4)]>>> print squared[0, 1, 4, 9]更复杂的情况,>>> evens = [ x for x in range(10) if not x % 2]>>> print evens[0, 2, 4, 6, 8]实际用处不知道多不多阿?
2010-07-16 14:29:00
347
原创 怎样注释C/C++代码
<br />简述(brief description)和详述(detailed description)<br /> <br />详述的几种方式<br /> <br />1. JavaDoc style<br /> /**<br /> * ... text ...<br /> */<br />2. Qt style /*!<br /> * ... text ...<br /> */<br />3. C++ comment style
2010-07-14 17:52:00
580
原创 使用select
<br />int pcap_fileno(pcap_t *handle);<br /> <br />pcap_fileno返回pcap的文件描述符, 这样我们就可以使用select函数。<br /> <br />#include <sys/select.h>#include <sys/types.h>#include <unistd.h>#include <pcap.h>#include <stdio.h>int main(int argc, char *argv[]){
2010-07-06 17:42:00
706
原创 select多路事件分离函数
<br />函数原型:<br /> nt select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);<br /> <br /> nfds为readfds, writefds, exceptfds中的fd最大值加1。<br /> <br />timeout的三种情况:<br />1. NULL<br /> 永远等待<br />2. timeout->tv_sec == 0
2010-07-06 17:05:00
770
原创 简单测试libpcap
<br /> <br />我一直以为在一个程序只能打开一次设备, 看样子是可以打开多次的。<br />#include <pcap.h>#include <stdio.h>int main(int argc, char *argv[]){ pcap_t *h1, *h2; /* Session handle */ char *dev; /* The device to sniff o
2010-07-06 16:37:00
640
原创 使用ssh命令实现scp
<br />今天在一个嵌入式设备上工作, 想传文件, 发现没有scp, 记着以前看到过可以使用ssh来传输文件, 所以自己尝试了一下。<br /> <br />$ ssh $REMOTE_HOST 'cat > $DEST_FILE' < $SRC_FILE<br /> <br />比如, 拷贝test.txt到192.168.1.101上去, <br />$ ssh 192.168.1.101 'cat > test.txt' < test.txt
2010-07-06 14:32:00
540
原创 使用dnet操作interface
/* Dump system network interface */#include #include #include #include static int intf_callback(const struct intf_entry *entry, void *arg){ int i; printf("interface: %s/n", entry->intf_name); printf("type = %d/n", entry->in
2010-07-02 18:52:00
983
原创 使用dnet操作ethernet
<br />/* Output eth0 mac address */#include <dnet.h>#include <stdio.h>#include <stdlib.h>#include <memory.h>int main(){ eth_addr_t eddr; unsigned char c[6]; memset(&eddr, 0, sizeof(eddr)); eth_t *eth = eth_open("eth0");
2010-07-02 17:31:00
1508
原创 使用dnet操作arp
<br />/* Dump kernel arp cache */#include <dnet.h>#include <stdio.h>#include <stdlib.h>int arp_callback(const struct arp_entry *entry, void *args){ printf("arp protocol addr: %s/n", addr_ntoa(&entry->arp_pa)); printf("arp hardware addr
2010-07-02 16:34:00
648
原创 初识libdnet
<br />第一次知道libdnet是在nmap中, 现在准备自己写一个扫描器, 也准备使用dnet来操作网卡接口和发送raw数据包。<br /> <br />libdnet下载: http://libdnet.sourceforge.net/<br /> <br />下载下来后直接<br />$ ./configure && make<br />$ sudo make install<br /> <br />为测试文件编写Makefile<br /> <br />SRC = $(wildcard
2010-07-02 15:52:00
3967
原创 简单分析TLS & SSLv3 renegotiation vulnerability
由于TLS & SSLv3 protocol在描述Renegotiation时存在问题, 使得MITM(man in the middle)攻击成为可能。 一般的TLS handshake : Client Server
2010-03-05 11:14:00
6932
原创 vector中push_back的复杂度
问题: 将N个元素使用push_back插入到vector中, 求push_back操作的复杂度。 简单分析如下: 考虑vector每次内存扩充两倍的情况。 如果我们插入N个元素, 则会引发lgN次的内存扩充,而每次扩充引起的元素拷贝次数为 2^0, 2^1, 2^2, ..., 2^lgN
2010-03-04 19:31:00
4765
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人