pcap 是 packet capture 的缩写,一般是 tcpdump 或者 wireshark 抓包后存盘的文件。
一般情况下,我们可以使用 wireshark 来直观的查看 pcap 的内容,并且借助 wireshark 强大的过滤器,从浩如烟海的数据包中过滤出我们需要的数据包,进行网络流量分析。
而如果需要自己写代码来读取 pcap 文件,就需要明确 pcap 的文件…… 阅读全文
Monthly Archives: April 2013
使用代码块来缩小变量作用域
今天突发奇想,想到这么一个写法
#include <stdio.h>
int main() {
char c = 'A';
{
int a = 1;
printf("%d\n", a);
printf("%c\n", c);
}
{
int a = 2;
printf("%d\n", a);
printf("%c\n&qu…… 阅读全文
UDP 包的边界
首先明确一个问题,如果定义了一个数据结构,大小是,比方说 32 个字节,然后 UDP 客户端连续向服务端发了两个包。现在假设这两个包都已经到达了服务器,那么服务端调用 recvfrom 来接收数据,并且缓冲区开得远大于 64,例如,开了 1024 个字节,那么,服务端的 recvfrom 函数是会一次收到两个数据包呢,还是只能收到一个…… 阅读全文
linux smartctl
http://bbs.linuxtone.org/threa…
什么是S.M.A.R.T.
SMART是一种磁盘自我分析检测技术,早在90年代末就基本得到了普及
每一块硬盘(包括IDE、SCSI)在运行的时候,都会将自身的若干参数记录下来
这些参数包括型号、容量、温度、密度、扇区、寻道时间、传输、误码率等
硬盘运行了几千小时后,很多内在的物理参数都会…… 阅读全文
note a disk crash
for some reason the i can not input in chinese, so note the message in english
first, system crash, win 7, and then auto run chkdsk, for a long time
then, i restart the computer into a USB portable system, runing WinPE
i can copy the data from the old disk(500G) to the new disk (2TB), but too slo…… 阅读全文
Linux 多进程监听 socket
首先来看代码
#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <sys/wait.h>
int main() {
int sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd…… 阅读全文
Linux TCP UDP 混合
基本的思路是这样的:在服务器端,有两个机器,一个对外开启 TCP 监听,然后把监听到的请求内容送到后面的另外一台,或者多台轮询机器上,内网之间使用 UDP,然后等待业务逻辑机器处理完成,这个地方可以做成异步的,然后再返回到用户。
即是这样: client server_front server_back
下面来看代码,首先是 server_fro…… 阅读全文
Linux UDP 收发实例
首先我们需要一个 struct.h
#ifndef STRUCT_H
#define STRUCT_H
typedef struct _UDP_MSG {
int add1;
int add2;
int sum;
char str1[128];
char str2[128];
char cat[256];
} UDP_MSG;
#endif /* STRUCT_H */
然后是服务端的
#include <sys/types.h>
#include <…… 阅读全文
Javascript 执行一次 MD5 或 SHA1 需要多久
首先是 Javascript 算 MD5 的问题,看到这里,http://pajhome.org.uk/crypt/md…,于是就是加一个时间打点,然后跑了
<script>
/*
* A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
* Digest Algorithm, as defined in RFC 1321.
* Version 2.2 Copyright (C) Paul Joh…… 阅读全文