2009年9月25日 星期五

gettimeofday

struct timeval now, last;


正確用法:gettimeofday(&now, NULL);


錯誤:缺少參數,gettimeofday(&now); ,這會影響其他的timeval資料,可能會寫到 last 變數裡(寫入值可能是:20 FE FF FF)。

2009年9月24日 星期四

sizeof timeval

Tested:


sizeof(struct timeval) =16 bytes on CentOS 64-bit


sizeof(struct timeval) = 8 bytes on Fedora 9 32-bit

2009年9月22日 星期二

FreeBSD ipfw 欄位

FreeBSD ipfw column.



ipfw show



Index Packets Bytes Rule


----- ------- -------- ----------------------------------------------------------


00050 464266 61021795 count udp from any to any via 192.168.1.99


00051 56582 79785701 count tcp from 192.168.1.99 80 to any via 192.168.1.99


65533 3 144 count tcp from 192.168.1.95 to 192.168.1.99 dst-port 23 in



  • Packets: How many packets counted.

  • Bytes: How many bytes counted. (e.g. The index 65533, 20bytes(IP)+28bytes(TCP)=48bytes, 48*3=144bytes)

2009年9月19日 星期六

to increase PJSUA_MAX_CALLS, PJ_IOQUEUE_MAX_HANDLES

centos 5.3


compiling "pjproject-1.4": (PJSUA_MAX_CALLS, PJ_IOQUEUE_MAX_HANDLES)


cp pjproject-1.4/pjlib/include/pj/config_site.sample.h pjproject-1.4/pjlib/include/pj/config_site.h


vim pjproject-1.4/pjlib/include/pj/config_site.h


#define PJ_CONFIG_MAXIMUM_SPEED 1




Compiling Error:


PJ_IOQUEUE_MAX_HANDLES cannot be greater than FD_SETSIZE


/etc/security/limits.conf


* soft nofile 99999


* soft nofile 99999


[root@ip172 i686-pc-linux-gnu]# grep -R FD_SETSIZE /usr/include/* |grep 1024


/usr/include/bits/typesizes.h:#define __FD_SETSIZE 1024


/usr/include/linux/posix_types.h:#define __FD_SETSIZE 1024


/usr/include/valgrind/vki-linux.h:#define __VKI_FD_SETSIZE 1024




vim /usr/include/bits/typesizes.h


/usr/include/bits/typesizes.h:#define __FD_SETSIZE 10240

2009年6月18日 星期四

Linux 軟體修改網卡MAC位址

方法一:
重開機後也跟著修改的方法。
在/etc/sysconfig/network-scripts/ifcfg-eth0中加入
MACADDR=00:0A:EC:EB:93:3C

方法二:
ifconfig eth0 down
ifconfig eth0 hw ether 00:12:34:56:78:90
ifconfig eth0 up

2009年4月25日 星期六

callback function 範例

#include <cstdlib>
#include <iostream>
using namespace std;

typedef int(*Binary_FT)(int,int);

int multiplyCB(int x, int y)
{
return x * y;
}

int additionCB(int x, int y)
{
return x + y;
}

void printFrameWork(int a, int b, char *str, Binary_FT callback)
{
int c;
c = callback(a, b);
printf("callback = %s\n", str);
printf("result = %d\n", c);
}

int main(int argc, char *argv[])
{
int integer1, integer2;
integer1 = 10;
integer2 = 20;

printf("Two inputs are %d and %d\n", integer1, integer2);
printFrameWork(integer1, integer2, "multiplyCB", multiplyCB);
printFrameWork(integer1, integer2, "additionCB", additionCB);

system("PAUSE");
return EXIT_SUCCESS;
}

執行結果:
Two inputs are 10 and 20
callback = multiplyCB
result = 200
callback = additionCB
result = 30

PJSUA - PJProject

To enable TLS supported.

Requirement:
OpenSSL library
DirectX SDK(maybe optional, but need to be configured)

To find pjproject-1.0.1\pjlib\include\pj\config.h
Add following code in it.
/**
* Support TLS in the library.
*/
#ifndef PJSIP_HAS_TLS_TRANSPORT
# define PJSIP_HAS_TLS_TRANSPORT 1
#endif

Visual Studio 2005 Configuration:
At pjsip_core project, check include path:
/IC:\lib\openssl\include

At pjsua project, it would require "libeay32MT.lib", "ssleay32MT.lib", check library path:
/LIBPATH:"C:\openssl-0.9.8i\lib"