2010年12月6日 星期一

function pointer 的用法

//local 宣告function pointer
int (*netcmd)(uint16,int(*)(cbuf_t*,uint16,void*,uint16),void*,uint16,void*,uint16*,uint32,int*);

//指定成不同的function pointer 根據傳入的參數
netcmd = (block) ? netcmdBlockSend : netcmdNonblockSend;

//可以直接call不需dereference 但是(*netcmd)才是比較一般的作法 參考這個網址
err_code=netcmd
    EVT_ARP_ADD, netexeArpAdd, &add, sizeof(cmdArpAdd_t),
    NULL, NULL, 5000, &result);

 

一些介紹function pointer的link:

pointer的加減

每次都忘記, 人真的老了

char * p ; p++時, p=p+1
int *
p ; p++時, p=p+4
memh_t *
p ; p++時, p = p + sizeof(memh_t)  

所以當

void* blk;
mp = (memh_t *)blk-1;
則mp 會指向 blk 往前推 memh_t 的位置

2010年11月25日 星期四

[好code分享] 利用掛function pointer 對同一堆data structure做不同的操作

int ecmpIprtNextHopIterate(
    void    (*exefunc)(ecmpRtNhEntry_t* ,ecmpNhEntry_t *,void*),
    void * data
){
    ecmpRtNhEntry_t* ecmpRtNhEntry_p = NULL;
    ecmpNhEntry_t* ecmpNhEntry_p = NULL;
    int32 bits,hashVal;
    for ( bits = IPRT_ECMP_NETMASK-1; bits >= 0; bits--)
    {
        for(hashVal = HASHMOD-1; hashVal >= 0; hashVal--){
            TAILQ_FOREACH(ecmpRtNhEntry_p, &ecmpRtNhTable[bits][hashVal],link) 
            {
                TAILQ_FOREACH(ecmpNhEntry_p, &(ecmpRtNhEntry_p->nhList),link){
                    if(exefunc){
                        exefunc(ecmpRtNhEntry_p, ecmpNhEntry_p,data);
                    }
                }
            }
        }
    }
    return ZYNOS_E_NONE;
}

要一直對相同的一堆data structure做不同的處理時用的, 感覺還不錯

印很多變數 檢查null的方式

if (str && buf && hw_addr){
    IPRT_ECMP_LOG(ECMP_DB_INFO,
        "update nexthop =%s hw addr = %02x:%02x:%02x:%02x:%02x:%02x    flags = %s caller = 0x%x\n",
        buf, MACADDR_LIST(hw_addr), str, addr);
}

我喜歡這個 很乾淨

2010年11月2日 星期二

passwd

帳號: 公司mail

密碼: real name

2010年11月1日 星期一

Sample.c

/*
* $Id: $
*/
/****************************************************************************/
/*
*    Copyright <Company logo>
*/
/****************************************************************************/
/*
* $Log: $
*/
#include <time.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include "global.h"


#ifdef SAMPLE_SUPPORT

#if 1 /* macro */
/*************************************************************
*
* macro
*
*************************************************************/
#endif /* macro */

#if 1 /* prototype */
/**************************************************************
*
* prototype
*
**************************************************************/
#endif /* prototype */

#if 1 /* global variable */
/**************************************************************
*
* global variable
*
**************************************************************/
#endif /* global variable */

#if 1 /* local variable */
/**************************************************************
*
* local variable
*
**************************************************************/
#endif  /* local variable */

#if 1 /* local function */
/**************************************************************
*
* local function
*
**************************************************************/
#endif  /* local function */

#if 1 /* global function */
/**************************************************************
*
* global function
*
**************************************************************/
#endif /* global function */

#endif /* SAMPLE_SUPPORT */

Sample.h

/*
* $Id:  $
*/

/****************************************************************************/
/*
*    Copyright <Company logo>
*/
/****************************************************************************/

/*
* $Log:  $
*/

#ifndef _SAMPLE_H_
#define _SAMPLE_H_

#if 1  /* define */
/**************************************************************
*
* define
*
**************************************************************/
#endif /* define */

#if 1  /* enum */
/**************************************************************
*
* enum
*
**************************************************************/
#endif /* enum */

#if 1  /* type */
/**************************************************************
*
* type
*
**************************************************************/
#endif /* type */

#if 1  /* prototype */
/**************************************************************
*
* prototype
*
**************************************************************/
#endif /* prototype */

#endif /* !_SAMPLE_H_ */

Comment Templete

/*
* Function:
*      <function name>
* Purpose:
*      <purpose>
* Parameters:
*      <p1 name> - <parameter 1 description>
*      <p2 name> - <parameter 2 description>
*      <p3 name> - <parameter 3 description>
* Returns:
*     <error 1 enum>    - <ERROR 1 description>
*     <error 2 enum>    - <ERROR 2 description>
*     <error 3 enum>    - <ERROR 3 description>
*     <error 4 enum>    - <ERROR 4 description>
*     <error 5 enum>    - <ERROR 5 description>
* Notes:
*/

Auto fill function name

/*----------------------------------------------------
*/
/* This file try auto fill funciton name in the begin of debug 20090703 smo
*/
/* Key word: __VA_ARGS__         
*/
/*------------------------------------------------------
*/

#include <stdio.h>
#include <stdarg.h>

/*if no ##, there must be one argument at least. */
#define mldsnppxyFuncPrint(a,...) mldsnppxyDbg(__PRETTY_FUNCTION__,a,##__VA_ARGS__)

int mldsnppxyDbg(char* funcName,char* format,...)
{
    char buffer[256];
    printf("@%s: ",funcName);
    va_list args;
    va_start (args, format);
    vsprintf (buffer,format, args);
    printf (buffer);
    va_end (args);
    return 0;
}

int main()
{
    int testInt=3;
    char testStr[]="smo";
    mldsnppxyFuncPrint("int =%d, string= %s\n\n",testInt,testStr);   
    return 0;
}

Error return

static int
_l2mldpxyHst_insertToGroupDB(
l2mldpxyHstVlanInfo_t * hstInfo_p,
l2mldpxyHstGroup_t *group_p
)
{

int ret=L2MLDPXY_E_NONE;
in6_addr_t * addr_p =(&group_p->groupAddr);
int hashValue=_l2mldpxyHst_hashGroup(addr_p);


l2mldpxyFuncPrint("@_l2mldpxyHst_insertToGroupDB\n");

/*sanity check*/
if (!hstInfo_p){
  ret = -1;
  goto exit;
}


LIST_INSERT_HEAD(hstInfo_p->groupDB[hashValue],group_p,linkHead_hash);

exit:
if (ret) l2mldpxyFuncPrint("Fail! ret code=%d\n", ret); 
return ret;

}

一些window的網路設定command

之前不知道從那裡抓來的

#=========
# 介面設定
#=========
pushd interface

reset all

popd
# 介面設定結束

#=========
# 介面設定
#=========
pushd interface ipv6

install
reset

popd
# 介面設定結束

# ----------------------------------
# ISATAP 設定
# ----------------------------------
pushd interface ipv6 isatap

popd
# ISATAP 設定結束

# ----------------------------------
# 6to4 設定
# ----------------------------------
pushd interface ipv6 6to4

reset

popd
# 6to4 設定結束

#========================
# 連接埠 Proxy 設定
#========================
pushd interface portproxy

reset

popd
# 連接埠 Proxy 設定結束

# ----------------------------------
# 介面 IP 設定        
# ----------------------------------
pushd interface ip

# "VMware Network Adapter VMnet8" 的介面 IP 設定

set address name="VMware Network Adapter VMnet8" source=static addr=192.168.226.1 mask=255.255.255.0
set dns name="VMware Network Adapter VMnet8" source=static addr=none register=PRIMARY
set wins name="VMware Network Adapter VMnet8" source=static addr=none

# "VMware Network Adapter VMnet1" 的介面 IP 設定

set address name="VMware Network Adapter VMnet1" source=static addr=192.168.233.1 mask=255.255.255.0
set dns name="VMware Network Adapter VMnet1" source=static addr=none register=PRIMARY
set wins name="VMware Network Adapter VMnet1" source=static addr=none

# "Dlink" 的介面 IP 設定

set address name="Dlink" source=dhcp
set dns name="Dlink" source=dhcp register=PRIMARY
set wins name="Dlink" source=dhcp

# "BCM" 的介面 IP 設定

set address name="BCM" source=static addr=192.168.1.100 mask=255.255.255.0
add address name="BCM" addr=192.168.0.100 mask=255.255.255.0
set dns name="BCM" source=static addr=none register=PRIMARY
set wins name="BCM" source=static addr=none

popd
# 介面 IP 設定結束

# ------------------------------------
# 橋接器設定 (不支援)
# ------------------------------------

# ------------------------------------
# 橋接器設定結束
# ------------------------------------

# ----------------------------------------
# 有線區域網路設定
# ----------------------------------------
pushd lan

popd

# 有線區域網路設定結尾。

# ==========================================================
# 網路存取保護用戶端設定
# ==========================================================
pushd nap client

# ----------------------------------------------------------
# 信任的伺服器群組設定
# ----------------------------------------------------------

reset trustedservergroup

# ----------------------------------------------------------
# 密碼編譯服務提供者 (CSP) 設定
# ----------------------------------------------------------

set csp name = "Microsoft RSA SChannel Cryptographic Provider" keylength = "2048"

# ----------------------------------------------------------
# 雜湊演算法設定
# ----------------------------------------------------------

set hash oid = "1.3.14.3.2.29"

# ----------------------------------------------------------
# 強制設定
# ----------------------------------------------------------

set enforcement id = "79617" admin = "disable" id = "79618" admin = "disable" id = "79619" admin = "disable" id = "79620" admin = "disable" id = "79621" admin = "disable" id = "79623" admin = "disable"
# ----------------------------------------------------------
# 追蹤設定
# ----------------------------------------------------------

set tracing state = "disable" level = "basic"

# ----------------------------------------------------------
# 使用者介面設定
# ----------------------------------------------------------

reset userinterface

popd
# NAP 用戶端設定的結尾

# -----------------------------------------
# RAS 設定                        
# -----------------------------------------
pushd ras

set authmode mode = standard
delete authtype type = PAP
delete authtype type = SPAP
delete authtype type = MD5CHAP
delete authtype type = MSCHAP
delete authtype type = MSCHAPv2
delete authtype type = EAP
add authtype type = MSCHAP
delete link type = SWC
delete link type = LCP
add link type = SWC
add link type = LCP
delete multilink type = MULTI
delete multilink type = BACP
add multilink type = MULTI
add multilink type = BACP

set user name = __vmware_user__ dialin = policy cbpolicy = none
set user name = Administrator dialin = policy cbpolicy = none
set user name = Guest dialin = policy cbpolicy = none
set user name = HelpAssistant dialin = policy cbpolicy = none
set user name = smo dialin = policy cbpolicy = none
set user name = SUPPORT_388945a0 dialin = policy cbpolicy = none

set tracing component = * state = disabled

popd

# RAS 設定結束。                 

# -----------------------------------------
# RemoteAccess AppleTalk 設定     
# -----------------------------------------
pushd ras appletalk

set negotiation mode = allow
set access mode = all

popd

# RemoteAccess AppleTalk 設定結束。

# -----------------------------------------
# RAS IP 設定                     
# -----------------------------------------
pushd ras ip

delete pool

set negotiation mode = allow
set access mode = all
set addrreq mode = deny
set broadcastnameresolution mode = disabled
set addrassign method = auto

popd

# RAS IP 設定結束。              

# -----------------------------------------
# RAS IPX 設定                     
# -----------------------------------------
pushd ras ipx

set negotiation mode = allow
set access mode = all
set nodereq mode = allow
set netassign method = autosame

popd

# RAS IPX 設定結束。              

# -----------------------------------------
# RAS NBF 設定                     
# -----------------------------------------
pushd ras netbeui

set negotiation mode = allow
set access mode = all

popd

# RAS NBF 設定結束。              

# -----------------------------------------
# RAS AAAA 設定                   
# -----------------------------------------
pushd ras aaaa

set authentication provider = windows
set accounting provider = windows

delete authserver name = *
delete acctserver name = *

popd

# RAS AAAA 設定結束。            
# 路由設定
pushd routing
reset
popd

#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!#
#                                                         #
#   在執行這個指令檔前                            #
#                                                         #
# 您必須先從 [網路] 連線資料夾中     #
# 解除 IPX 的安裝,然後重新再安裝一次,   #
# 才能還原 IPX 路由器設定。                                      #
#                                                         #
#   這樣做會刪除舊的 IPX 路由器設定,         #
#   並將 IPX 路由器設定還原成它的      #
#   預設值                                               #
#                                                         #
#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!#

#----------------------------------------------------------
# IPX 設定
#----------------------------------------------------------

pushd routing ipx

#----------------------------------------------------------
# IPX 介面設定
#----------------------------------------------------------

#----------------------------------------------------------
# IPX 流量篩選器設定
#----------------------------------------------------------

#----------------------------------------------------------
# IPX 靜態路由設定
#----------------------------------------------------------

#----------------------------------------------------------
# IPX 靜態服務設定
#----------------------------------------------------------

popd

# 完成 IPX 設定

#----------------------------------------------------------
# IPX RIP 設定
#----------------------------------------------------------

pushd routing ipx rip
popd

# IPX RIP 設定結束

#----------------------------------------------------------
# IPX SAP 設定
#----------------------------------------------------------

pushd routing ipx sap
popd

# 完成 IPX SAP 設定

#----------------------------------------------------------
# IPX NETBIOS 設定
#----------------------------------------------------------

pushd routing ipx netbios
popd

# 完成 IPX NB 設定
# IP 設定
pushd routing ip
reset
set loglevel error
add preferenceforprotocol proto=LOCAL preflevel=1
add preferenceforprotocol proto=NetMgmt preflevel=10
add preferenceforprotocol proto=STATIC preflevel=3
add preferenceforprotocol proto=NONDOD preflevel=5
add preferenceforprotocol proto=AUTOSTATIC preflevel=7
add preferenceforprotocol proto=OSPF preflevel=110
add preferenceforprotocol proto=RIP preflevel=120
add interface name="VMware Network Adapter VMnet8" state=enable
set filter name="VMware Network Adapter VMnet8" fragcheck=disable
add interface name="Dlink" state=enable
set filter name="Dlink" fragcheck=disable
add interface name="VMware Network Adapter VMnet1" state=enable
set filter name="VMware Network Adapter VMnet1" fragcheck=disable
add interface name="BCM" state=enable
set filter name="BCM" fragcheck=disable
add interface name="內部" state=enable
set filter name="內部" fragcheck=disable
add interface name="回送" state=enable
set filter name="回送" fragcheck=disable
popd
# IP 設定結束

# ----------------------------------
# DNS Proxy 設定           
# ----------------------------------
pushd routing ip dnsproxy
uninstall

popd
# 結束 DNS proxy 設定

# ----------------------------------
# IGMP 設定        
# ----------------------------------
pushd routing ip igmp
uninstall

popd
# 結束 IGMP 設定

# ----------------------------------
# NAT 設定                 
# ----------------------------------
pushd routing ip nat
uninstall

popd

# ----------------------------------
# OSPF 設定               
# ----------------------------------

pushd routing ip ospf
uninstall

popd
# 結束 OSPF 設定

# ----------------------------------
# DHCP 轉接代理設定    
# ----------------------------------
pushd routing ip relay
uninstall

popd
# 結束 DHCP 轉接設定

# ----------------------------------
# RIP 設定                 
# ----------------------------------
pushd routing ip rip
uninstall

popd
# 結束 RIP 設定

# ----------------------------------
# 路由器搜索設定    
# ----------------------------------
pushd routing ip routerdiscovery
uninstall
add interface name="VMware Network Adapter VMnet8" disc=disable minint=7 maxint=10 life=30 level=0
add interface name="Dlink" disc=disable minint=7 maxint=10 life=30 level=0
add interface name="VMware Network Adapter VMnet1" disc=disable minint=7 maxint=10 life=30 level=0
add interface name="BCM" disc=disable minint=7 maxint=10 life=30 level=0
add interface name="內部" disc=disable minint=7 maxint=10 life=30 level=0
add interface name="回送" disc=disable minint=7 maxint=10 life=30 level=0

popd

# ----------------------------------
# DHCP 配置器設定      
# ----------------------------------
pushd routing ip autodhcp
uninstall

popd
# 結束 DHCP 配置器設定

Cell phone watchdog

今天看到朋友寄信來提到這個: cell phone watchdog (約台幣二千多) 我真的超需要的

手機其實本來就一直開著也一直在收訊號 應該不難做吧

如果有下一個領域可以換就來試手機的系統好了  還是先把OS弄熟之後再去有做手機的系統廠研究這個

不掉東西的路邁進

2010年10月19日 星期二

win 7 run win xp program

Try this out

寄mail 記帳

寄到email 使用特殊格式 for example [記帳] 20101019 支出 咖哩番

就能做出表格 for show

2010年10月17日 星期日

My ab

Try it out

嘗試寫出一樣的軟體

2010年8月24日 星期二

how to become a hacker

http://catb.org/esr/faqs/hacker-howto.html

建立google document. about 心路歷程
提高工作效率 每天七點下班.

2010年3月2日 星期二