小弟写了个调用windows api的 vpn客户端
其中ras.h中 option定义部分
rasEntry.dwfOptions = RASEO_RequireMsEncryptedPw|RASEO_ModemLights; // RASEO_RemoteDefaultGateway
这里取消掉了windows的默认网关,希望通过操作路由表来指定相应IP通过vpn中转
然后就出现问题了.
win7下一切正常,拨号成功后没有默认路由,我可以通过 route add添加指定目标
但是xp下就直接将vpn服务器网关作为默认网关了.
查了相关资料也没有发现其他什么不对的地方.
难道说只能通过遍历网卡地址 定位默认网关,在vpn连接成功之后change网关做相应设置么?
小弟这里拜谢了.
在线等
希望大大帮助下.

解决方案 »

  1.   

    你可以使用Route delete命令先删除网关,然后再通过route add添加,也可以通过API实现这个是添加网关IP,和Route Add命令效果相同
    DWORD   AddIPAddress( 
        IPAddr   Address,           //   IP   address   to   add 
        IPMask   IpMask,             //   subnet   mask   for   IP   address 
        DWORD   IfIndex,             //   index   of   adapter 
        PULONG   NTEContext,     //   Net   Table   Entry   context 
        PULONG   NTEInstance     //   Net   Table   Entry   Instance 
    ); 
    Parameters 
    Address   
    [in]   Specifies   the   IP   address   to   add   to   the   adapter.   
    IpMask   
    [in]   Specifies   the   subnet   mask   for   the   IP   address.   
    IfIndex   
    [in]   Specifies   the   adapter   to   which   to   add   the   address.   
    NTEContext   
    [out]   Pointer   to   a   ULONG   variable   that   points   to   the   Net   Table   Entry   (NTE)   context   for   this   IP   address.   The   caller   can   later   use   this   context   in   a   call   to   DeleteIPAddress.   
    NTEInstance   
    [out]   Pointer   to   a   ULONG   variable   that   points   to   the   NTE   instance   for   this   IP   address.   
    Return   Values 
    If   the   function   succeeds,   the   return   value   is   NO_ERROR. If   the   function   fails,   use   FormatMessage   to   obtain   the   message   string   for   the   returned   error. Res 
    The   IP   address   created   by   AddIPAddress   is   not   persistent.   The   address   exists   only   as   long   as   the   adapter   object   exists.   Rebooting   the   computer   destroys   the   address,   as   does   manually   resetting   the   network   interface   card   (NIC).   Also,   certain   PnP   events   may   destroy   the   address. For   information   about   the   IPAddr   and   IPMask   data   types,   see   Win32   Simple   Data   Types.   To   convert   an   IP   address   between   dotted   decimal   notation   and   IPAddr   format,   use   the   inet_addr   and   inet_ntoa   functions. Requirements   
        Windows   NT/2000   or   later:   Requires   Windows   2000   or   later. 
        Windows   95/98/Me:   Unsupported. 
        Header:   Declared   in   Iphlpapi.h. 
        Library:   Use   Iphlpapi.lib.
    相对应的,还有个DeleteIPAddress 。他们都属于IP   Helper   APIs  
      

  2.   

    Tr0j4n
      这样是曲线救国.我也想到了
    但是删除网关的瞬间会先断线
    客户体验不理想..
    刚刚出去了一下.抱歉这么晚才回帖不知道是否有操作route的相关API
    我只知道如果我想确认默认网关的话
    必须在连接vpn前遍历网卡 搜索mac,再定位到网关.
    连接成功后就是
    1.删除当前网关
    2.添加连接前的本地连接网关
    3.添加指定目标路由.只能这样么..
    客户体验不理想啊.
      

  3.   

    在连接前就取消掉默认网关真的就没希望了么..
    vista及win7下是可以实现的..
    但是在windows下建立连接的时候是可以选择"启用默认网关"相关的选项的.
    帮忙再出出主意?
    如果说这点也没办法实现的话
    那我只能走改网关这条路了.
      

  4.   

    RasEntry.dwfOptions &=~(RASEO_RemoteDefaultGateway)这样呢?
      

  5.   

    LZ,我最近也要做跟你差不多的东西,但是我找不到WINDOWS VPN的API,所以想请教下哪里有这方面的文档