mongoose start function call use graph
I constructed a mongoose start function call use graphviz.
Links:
1. Visualize function calls with Graphviz http://www.ibm.com/developerworks/library/l-graphvis/
I constructed a mongoose start function call use graphviz.
Links:
1. Visualize function calls with Graphviz http://www.ibm.com/developerworks/library/l-graphvis/
这几天在解析ARP,ICMP 的时候, 要对数据进行移位,由于之前对unsigned 和 singned没有很好的认识,有些莫名奇怪的问题。
比如下面的代码:
#include <stdio.h>
#include <stdint.h>
#include <string.h>#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
int main(void)
{
char mac[6] = {0×80, 0x1E, 0×37, 0x1A, 0x3D, 0x7F};int i = 0;
for(i = 0; i<ARRAY_SIZE(mac); i++) {
printf(“0x%X “, mac[i]);
}
printf(“\n”);write1(mac, 6);
return 0;
}void write1(unsigned char *buf, uint16_t buf_size)
{
int i = 0;
uint16_t cur_word = 0;for (i = 0; i < buf_size; i += 2) {
cur_word = (uint16_t)((buf[i] <<8 ) | buf[i+1]);
printf(“0x%04X buf[i] 0x%02X buf[i+1] 0x%02X\n”, cur_word, buf[i], buf[i+1]);
}
}border@ubuntu:~$ uname -a
Linux ubuntu 2.6.24-21-generic #1 SMP Tue Oct 21 23:43:45 UTC 2008 i686 GNU/Linux
border@ubuntu:~$ ./hello
0xFFFFFF80 0x1E 0×37 0x1A 0x3D 0x7F
0x801E buf[i] 0×80 buf[i+1] 0x1E
0x371A buf[i] 0×37 buf[i+1] 0x1A
0x3D7F buf[i] 0x3D buf[i+1] 0x7F
怎么打印结果不同, 在主函数里面第一个打印出来的是 0xFFFFFF80, 但是在write1函数里面就是正常的0×80了,但是你有可能说
是0x%x 和 0x%02x 的问题,于是程序改为:
char mac[6] = {0x80, 0x1E, 0x37, 0x1A, 0x3D, 0x7F};
int i = 0;
for(i = 0; iprintf("0x%02X ", mac[i]);
}
printf("\n");
就算是改为 %02X,也是输出0xFFFFFF80,和%x的结果一样。
但是如果把char mac[6] 改为 unsigned char mac[6] 主函数就没有问题。
在write1函数里面,如果你把参数unsigned char *buf 改为char *buf, 当大于0x7F的时候,也会溢出,是因为C 里面如果没有定义
类型符合的话默认为singned.
singned的取之范围是-128-127(0×80-0x7F), 所以当大于0x7F的时候会溢出。
unsigned 的取值范围是0-255(0-0xFF).
如果你要进行高低段位移的话,以后要定义为unsigned.
疑问: 为什么%02X输出的也是8个字节,而不是两个字节?
Bian Jiang
http://www.wifihack.net
–EOF–
1. linux/unix
OpenSSH 支持SOCKS4和SOCKS5, 我们可以通过参数 -D 在本地创建一个代理端口. 例如:
ssh -D 12345 myuser@remote_ssh_server
我们已经在本地创建的一个SOCKS的端口12345, 现在你可以通过修改你的IE, Firefox 中的连接方式来用代理上网。比如:
IP 改为 127.0.0.1
端口: 12345
方式改为: SOCKS5
这样我们就可以继续访问 youtube 了。
2. 如果是windows 可以使用 putty的后台命令行程序plink(http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html)
plink -N username@remote.ssh.server -D 127.0.0.1:7070
其中 -N 表示不需要shell
username@remote.ssh.server 换成你ssh帐户名和主机域名或者地址
或者替换成 -load sessionname 也可以,用dreamhost上的帐号试了一下,真的很快
如果你用的是 Firefox 可以用SwitchProxy(https://addons.mozilla.org/en-US/firefox/addon/125), 非常方便的切换。
ssh -D 参数的描述:
-D [bind_address:]port
Specifies a local “dynamic” application-level port forwarding. This works by allocating a
socket to listen to port on the local side, optionally bound to the specified bind_address.
Whenever a connection is made to this port, the connection is forwarded over the secure chan-
nel, and the application protocol is then used to determine where to connect to from the
remote machine. Currently the SOCKS4 and SOCKS5 protocols are supported, and ssh will act as
a SOCKS server. Only root can forward privileged ports. Dynamic port forwardings can also
be specified in the configuration file.IPv6 addresses can be specified with an alternative syntax: [bind_address/]port or by enclos-
ing the address in square brackets. Only the superuser can forward privileged ports. By
default, the local port is bound in accordance with the GatewayPorts setting. However, an
explicit bind_address may be used to bind the connection to a specific address. The
bind_address of “localhost” indicates that the listening port be bound for local use only,
while an empty address or ‘*’ indicates that the port should be available from all inter-
faces.
3.摘自chedong.com
ssh -qTfnN -D 7070 remotehost.
All the added options are for a ssh session that’s used for tunneling.
-q :- be very quite, we are acting only as a tunnel.
-T :- Do not allocate a pseudo tty, we are only acting a tunnel.
-f :- move the ssh process to background, as we don’t want to interact with this ssh session directly.
-N :- Do not execute remote command.
-n :- redirect standard input to /dev/null.
Links:
1. Use ssh create http proxy (http://www.linuxjournal.com/content/use-ssh-create-http-proxy)
2. http://www.chedong.com/blog/archives/001246.html
3. Putty (http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html)
Bian Jiang
http://www.wifihack.net
–EOF–
本文参考: http://notes.jimlindley.com/2008/3/25/git-svn-that-works-for-me
作者: Jim Lindley
The canonical git-svn workflow that I’ve seen goes like this:
标准的git-svn工作流程参考这里:
[code lang="C"]
git svn clone
git checkout -b
...hack...hack...
git commit -a
git checkout master
git merge #NOTE: no need for --squash anymore
git svn rebase
git svn dcommit -e # -e will let you enter a commit message for SVN
[/code]
I’ve had more luck with the following workflow, when integrating changes via SVN from other team members:
我从团队的其他成员学到了更好的工作流程:
[code lang="C"]
# initial setup
git svn clone
# 99% of daily workflow
git checkout -b
...hack...hack...
git commit -a
# switch back to master, then rebase against
# any revisions in the svn repo
git checkout master
git svn rebase
# now that master is current with svn,
# sync working branch to local master
git checkout # These two are the added steps
git rebase master # which help prevent conflicts
# final upstream commit after rebasing
git checkout master
git svn rebase # one last check for new svn check ins
git merge
git svn dcommit -e
[/code]
The extra rebase step seems to do a better job of integrating your patches into the tree. Merge should do the same thing, if I’m reading the man pages right, but splitting the steps is more idiot proof (me-proof) this way.
It also keeps the master local branch from getting messy dealing with conflicts. Instead conflict is kept in the side working branch.
上面虽然很罗嗦但是做的好处在于,我们把所有的工作和从svn代码的合并都放在本地的分支上进行。这样就能保证本地主干与svn服务器进行同步,并且在本地主干没有任何修改。
更多有关git, git-svn, git-reset 的文章:
1. git-svn workflow
2. An introduction to git-svn for Subversion/SVK users and deserters
3. Git reset in depth
2009.4.3
Bian Jiang
–EOF–
CMake 是一个跨平台的自动化建构系统,它使用一个名为 CMakeLists.txt 的文件来描述构建过程,
可以产生标准的构建文件,如 Unix 的 Makefile 或Windows Visual C++ 的 projects/workspaces 。
文件 CMakeLists.txt 需要手工编写,也可以通过编写脚本进行半自动的生成。CMake 提供了比 autoconfig 更简洁的语法.
之前想用automake autoconf来管理项目,但是看了一天也没有搞明白是怎么回事。最后只好投奔cmake.
经过一天的努力终于把项目从Makefile移植到cmake. 在移植的过程中遇到了些问题,简单记录如下.
网上关于cmake的的资料比较少,官方网站上的资料也特别少,有好多看了还看不懂, 哎。
从网上找到一篇“Cmake Practice(cmake 实践)”国人Cjacker写的。可以从这不下载 http://www.scribd.com/doc/13774019/Cmake-Practicecmake-
1. 在cmake中通过EXEC_PROGRAM来调用命令行来取得一些参数. 比如你要想通过取得gtkmm一些头部文件和库的路径。
[code lang="C"]
pkg-config gtkmm --cflags --libs
[/code]
Use the EXEC_PROGRAM command and then use the CACHE option of the SET
command to save the output to a variable like GTK_PKG_FLAGS. Then use
the SET command to add the value. Something like this:
[code lang="C"]
IF(NOT GTK_PKG_FLAGS)
EXEC_PROGRAM(pkg-config ARGS --cflags --libs gtkmm
OUTPUT_VARIABLE GTK_PKG_FLAGS)
SET(GTK_PKG_FLAGS "${GTK_PKG_FLAGS}" CACHE STRING "GTK Flags")
ENDIF(NOT GTK_PKG_FLAGS)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GTK_PKG_FLAGS}")
[/code]
2. 通过execute_process来实现文件, 目录的拷贝
[code lang="C"]
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_SOURCE_DIR}/path/to/www
${CMAKE_BINARY_DIR}/path/to/www)
[/code]
PS: EXECUTE_PROCESS 和 EXEC_PROGRAM 基本相同, EXECUTE_PROCESS是用来替代EXEC_PROGRAM的。
参见: http://www.cmake.org/pipermail/cmake/2006-February/008250.html
参考: http://www.cmake.org/pipermail/cmake/2009-March/028299.html
3. 常用的几个内置变量
通过set语句可以自定义变量,然而,CMake还包含大量的内置变量,这些变量和自定义变量的用法没有区别,下面就列出一些常用的变量:
* CMAKE_C_COMPILER
指定C编译器,通常,CMake运行时能够自动检测C语言编译器。进行嵌入式系统开发时,通常需要设置此变量,指定交叉编译器。
* CMAKE_CXX_COMPILER
指定C++编译器
* CMAKE_C_FLAGS
指定编译C文件时编译选项,比如-g指定产生调试信息。也可以通过add_definitions命令添加编译选项。
* EXECUTABLE_OUTPUT_PATH
指定可执行文件存放的路径。
* LIBRARY_OUTPUT_PATH
指定库文件放置的路径
4. 常用的命令
除了内置变量,我们还可以通过命令来修改编译选项,现将一些常用的命令列出来:
* include_directories
指定头文件的搜索路径,相当于指定gcc编译器的-I参数
* link_directories
动态链接库或静态链接库的搜索路径,相当于指>定gcc的-L参数
* add_subdirectory
包含子目录,当工程包含多个子目录时,此命令有用
* add_definitions
添加编译参数,比如add_definitions(-DDEBUG)将在gcc命令行添加DEBUG宏定义
* add_executable
编译可执行程序
* target_link_libraries
指定链接库,相同于指定-l参数
* AUX_SOURCE_DIRECTORY 将指定目录中的源文件名称赋值给变量DIR_SRCS
AUX_SOURCE_DIRECTORY(. DIR_SECS)
把当前目录下面的所有源文件名称赋值给变量DIR_SRCS
Cmake Practice(cmake 实践) http://www.scribd.com/full/13774019?access_key=key-hkil010h7nnglwgk8x5
Links:
1. http://www.cmake.org/pipermail/cmake/2005-January/006051.html
2. CMake Useful Variables http://www.vtk.org/Wiki/CMake_Useful_Variables
3. http://www.cmake.org/pipermail/cmake/2009-March/028299.html
4. http://www.scribd.com/doc/13774019/Cmake-Practicecmake-
Recent Comments