- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试执行 SetIpInterfaceEntry功能,但我总是得到 ERROR_INVALID_PARAMETER
结果。我想更改哪个确切参数并不重要,因为即使我不更改任何内容,我也会收到此错误。这是 C++ 代码示例,它没有任何更改,但输出始终相同:
// Initialize MIB_IPINTERFACE_ROW with actual InterfaceLuid:
auto row = MIB_IPINTERFACE_ROW{ AF_INET, 1689399632855040 };
auto result = GetIpInterfaceEntry(&row);
// Just to confirm GetIpInterfaceEntry success print result and InterfaceIndex:
std::cout << "GetIpInterfaceEntry result: " << result << "; InterfaceIndex: " << row.InterfaceIndex << std::endl;
// Try to execute SetIpInterfaceEntry, without any change:
result = SetIpInterfaceEntry(&row);
// Result is always ERROR_INVALID_PARAMETER (87):
std::cout << "SetIpInterfaceEntry result: " << result << std::endl;
这是上一个片段的输出:
GetIpInterfaceEntry result: 0; InterfaceIndex: 13
SetIpInterfaceEntry result: 87
根据 the doc ,ERROR_INVALID_PARAMETER
的可能原因是:
An invalid parameter was passed to the function. This error is returned if a
NULL
pointer is passed in the Row parameter, the Family member of theMIB_IPINTERFACE_ROW
pointed to by the Row parameter was not specified asAF_INET
orAF_INET6
, or both theInterfaceLuid
orInterfaceIndex
members of theMIB_IPINTERFACE_ROW
pointed to by the Row parameter were unspecified.
在我的情况下,这两个都不是真的(我刚刚得到实际的结构)。
我的问题很明显:我做错了什么?该方法可以调用哪种接口(interface)有限制吗? (我调用实体店。)还有其他建议吗?
谢谢!
更新:我忘了说,如果你想执行这段代码,你应该:
#include <winsock2.h>
#include <netioapi.h>
同时链接 iphlpapi.lib
。
最佳答案
解决了,感谢我的同事...
原因是在我的例子中 row.SitePrefixLength
字段最初设置为 64
,根据 MIB_IPINTERFACE_ROW doc page,这是一个非法值:
For an IPv4 address, any value greater than 32 is an illegal value.
只要我在 SetIpInterfaceEntry 之前插入以下行调用,一切正常:
row.SitePrefixLength = 0;
虽然解决了问题,但是还有几个 Unresolved 问题:
0
就是答案,但我不确定。但首先我应该弄清楚 SitePrefixLength
字段/参数的用途是什么。 :)
更新:我刚刚找到了我剩下的第二个问题的答案 - 它在 the same doc page 中一直(因为我没有阅读所有内容而感到羞耻)。所以答案是:
For IPv4, the
SitePrefixLength
member must be set to 0.
关于c++ - SetIpInterfaceEntry 返回 ERROR_INVALID_PARAMETER,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54857292/
我正在尝试执行 SetIpInterfaceEntry功能,但我总是得到 ERROR_INVALID_PARAMETER 结果。我想更改哪个确切参数并不重要,因为即使我不更改任何内容,我也会收到此错误
我是一名优秀的程序员,十分优秀!