找回密码
 加入
搜索
查看: 6519|回复: 7

[网络通信] iphlpapi.dll 操作路由表失败!XP下提示 87 求助

  [复制链接]
发表于 2013-5-23 15:55:27 | 显示全部楼层 |阅读模式
本帖最后由 风雨网络 于 2013-5-23 16:34 编辑

WIN7 测试通过  XP 失败了!
#Region ;**** 参数创建于 ACNWrapper_GUI ****
#PRE_UseUpx=n
#PRE_UseX64=n
#PRE_Res_requestedExecutionLevel=None
#EndRegion ;**** 参数创建于 ACNWrapper_GUI ****
Const $IPHLPAPI = DllOpen("iphlpapi.dll")
Const $tagMIB_IPFORWARDROW = "long Destination;long NetworkMask;long Policy;long NextHop;long IfIndex;long Type;long Proto;long Age;long NextHopAS;long Metric1;long Metric2;long Metric3;long Metric4;long Metric5"
 
Func _EnumIpForwordEntries()
        Local $iResult, $tBuffer, $tBinary, $pBinary, $tNumberofEntries, $aResult[1][14] = [[0]]
 
        $iResult = DllCall($IPHLPAPI, "long", "GetIpForwardTable", "ptr", 0, "long*", 0, "bool", 1)
        If ($iResult[2] < 4) Then Return SetError($iResult[0], 0, $aResult)
 
        $tBinary = DllStructCreate("ubyte Binary[" & $iResult[2] & "]")
        $pBinary = DllStructGetPtr($tBinary)
 
        $iResult = DllCall($IPHLPAPI, "long", "GetIpForwardTable", "ptr", $pBinary, "long*", $iResult[2], "bool", 1)
        If ($iResult[0]) Then Return SetError($iResult[0], 0, $aResult)
 
        $tNumberofEntries = DllStructCreate("long NumberofEntries", $pBinary)
        $aResult[0][0] = DllStructGetData($tNumberofEntries, "NumberofEntries")
        Redim $aResult[$aResult[0][0] + 1][14]
 
        For $i = 1 To $aResult[0][0]
                $tBuffer = DllStructCreate($tagMIB_IPFORWARDROW, $pBinary + 4 + ($i - 1) * 56)
 
                For $j = 0 To 13
                        $aResult[$i][$j] = DllStructGetData($tBuffer, $j + 1)
                Next
                $aResult[$i][0] = _ConvertUlongToChars($aResult[$i][0])
                $aResult[$i][1] = _ConvertUlongToChars($aResult[$i][1])
                $aResult[$i][3] = _ConvertUlongToChars($aResult[$i][3])
        Next
 
        Return $aResult
EndFunc ;==>_EnumIpForwordEntries
 
Func _ConvertUlongToChars($iUlong)
        Local $iResult = DllCall("Ws2_32.dll", "str", "inet_ntoa", "ulong", $iUlong)
        Return $iResult[0]
EndFunc ;==>_ConvertUlongToChars
 
Func _ConvertCharsToUlong($sChars)
        Local $iResult = DllCall("Ws2_32.dll", "long", "inet_addr", "str", $sChars)
        Return $iResult[0]
EndFunc ;==>_ConvertCharsToUlong
 
Func _CreateIpForwardEntry($sDestination, $sNetworkMask, $sNextHop, $iIfIndex, $iType, $iMetric)
        Local $tBuffer, $iResult
 
        If $iIfIndex = -1 Then $iIfIndex = _GetBestInterface($sNextHop)
 
        $tBuffer = DllStructCreate($tagMIB_IPFORWARDROW)
        DllStructSetData($tBuffer, "Destination", _ConvertCharsToUlong($sDestination))
        DllStructSetData($tBuffer, "NetworkMask", _ConvertCharsToUlong($sNetworkMask))
        DllStructSetData($tBuffer, "NextHop", _ConvertCharsToUlong($sNextHop))
        DllStructSetData($tBuffer, "IfIndex", $iIfIndex)
        DllStructSetData($tBuffer ,"Type", $iType)
        DllStructSetData($tBuffer, "Proto", 3)
        DllStructSetData($tBuffer, "Policy", 0)
        DllStructSetData($tBuffer, "Age", 0)
        DllStructSetData($tBuffer, "NextHopAS", 0)
        DllStructSetData($tBuffer, "Metric1", $iMetric)
        DllStructSetData($tBuffer ,"Metric2", -1)
        DllStructSetData($tBuffer ,"Metric3", -1)
        DllStructSetData($tBuffer ,"Metric4", -1)
        DllStructSetData($tBuffer ,"Metric5", -1)
 
        $iResult = DllCall($IPHLPAPI, "long", "CreateIpForwardEntry", "ptr", DllStructGetPtr($tBuffer))
        Return SetError($iResult[0], 0, $iResult[0] = 0)
EndFunc ;==>_CreateIpForwardEntry
 
Func _DeleteIpForwardEntry($sDestination, $sNetworkMask, $sNextHop, $iIfIndex, $iProto = 3)
        Local $iResult, $tBuffer
 
        If $iIfIndex = -1 Then $iIfIndex = _GetBestInterface($sNextHop)
 
        $tBuffer = DllStructCreate($tagMIB_IPFORWARDROW)
        DllStructSetData($tBuffer, "Destination", _ConvertCharsToUlong($sDestination))
        DllStructSetData($tBuffer, "NetworkMask", _ConvertCharsToUlong($sNetworkMask))
        DllStructSetData($tBuffer, "NextHop", _ConvertCharsToUlong($sNextHop))
        DllStructSetData($tBuffer, "IfIndex", $iIfIndex)
        DllStructSetData($tBuffer, "Proto", $iProto)
 
        $iResult = DllCall($IPHLPAPI, "long", "DeleteIpForwardEntry", "ptr", DllStructGetPtr($tBuffer))
        Return SetError($iResult[0], 0, $iResult[0] = 0)
EndFunc ;==>_DeleteIpForwardEntry
 
Func _GetBestInterface($sAddress)
        Local $iResult
 
        $iResult = DllCall($IPHLPAPI, "long", "GetBestInterface", "long", _ConvertCharsToUlong($sAddress), "long*", 0)
        Return SetError($iResult[0], 0, $iResult[2])
EndFunc ;==>_GetBestInterface
 
If _CreateIpForwardEntry("221.239.208.1", "255.255.255.255", "192.168.0.215", -1, 3, 60) Then
        MsgBox(48, "OK", "Done")
Else
        MsgBox(48, "Error", "Failed with error " & @error)
EndIf
 
If _DeleteIpForwardEntry("221.239.208.1", "255.255.255.255", "192.168.0.215", -1) Then
        MsgBox(48, "OK", "Done")
Else
        MsgBox(48, "Error", "Failed with error " & @error)
EndIf

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2013-5-23 18:23:05 | 显示全部楼层
本帖最后由 ceoguang 于 2013-5-23 18:24 编辑
87为ERROR_INVALID_PARAMETER(参数错误)
An input parameter is invalid, no action was taken. This error is returned if the pRoute parameter is NULL, the dwForwardProto member of MIB_IPFORWARDROW was not set to MIB_IPPROTO_NETMGMT, the dwForwardMask member of the PMIB_IPFORWARDROW structure is not a valid IPv4 subnet mask, or one of the other members of the MIB_IPFORWARDROW structure is invalid.
发表于 2013-5-23 18:24:18 | 显示全部楼层
87为ERROR_INVALID_PARAMETER(参数错误)
An input parameter is invalid, no action was taken. This error is returned if the pRoute parameter is NULL, the dwForwardProto member of MIB_IPFORWARDROW was not set to MIB_IPPROTO_NETMGMT, the dwForwardMask member of the PMIB_IPFORWARDROW structure is not a valid IPv4 subnet mask, or one of the other members of the MIB_IPFORWARDROW structure is invalid.
 楼主| 发表于 2013-5-23 18:27:15 | 显示全部楼层
回复 3# ceoguang


    参数没错误吧! WIN7 上测试OK 的!  不知道为何XP 不行!
发表于 2013-5-23 18:29:21 | 显示全部楼层
如果上面的提示还不够清析,那么请参考http://msdn.microsoft.com/en-us/library/windows/desktop/aa366850(v=vs.85).aspx关于dwForwardProto成员的说明
 楼主| 发表于 2013-5-23 19:02:56 | 显示全部楼层
回复 5# ceoguang

版主这个看得云里雾里! 我刚把这个发给别人XP 测试提示OK 是可以的! 我自己到2003上运行也是可以的!

应该是系统上精简或者优化了什么导致的! 只是我现在找不到修改系统上的那些东西导致的这个问题!
发表于 2013-5-23 19:42:35 | 显示全部楼层
回复  ceoguang

版主这个看得云里雾里! 我刚把这个发给别人XP 测试提示OK 是可以的! 我自己到2003上运 ...
风雨网络 发表于 2013-5-23 19:02

抱嫌我没看清你的代码,dwForwardProto成员在你的代码中是指定了MIB_IPPROTO_NETMGMT的.并没有问题.
而按你的返回提示,MSDN上指出是因为MIB_IPFORWARDROW结构中一个或多个成员未设置值.
 楼主| 发表于 2013-5-24 21:05:30 | 显示全部楼层
回复 7# ceoguang

版主 ("221.239.208.1", "255.255.255.255", "x.x.x.x", -1)   在XP 上这个里的X 如果是本机IP 地址或者VPN 获取到的IP 运行就会失败返回87 如果这个IP是不存在的就会提示OK !我要实现的是将221.239.208.1添加到本地IP地址或者VPN获取到的IP 看了你说的这个!还是不懂怎么解决!
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-11-22 01:13 , Processed in 0.082192 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表