Windows Server 2012上的SNMP扩展代理无法连接到需要数据的端口
SNMP Extension Agent on Windows Server 2012 unable to connect to a port from which it needs data
更新:因此,在Windows Server 2012上,如果我手动从WindowsSystem32调用snmp.exe以"以管理员身份运行",问题就会消失。在Windows Server 2012上,我无法以管理员身份强制SNMP服务启动。
下面是我的场景:
- 我们的SNMP扩展代理创建一个windows套接字来连接到我们的代理在特定端口号上获取一些配置我们向MIB浏览器传播的信息。
- 当我们重新安装我们的应用程序,然后安装SNMP在Windows Server 2012,一切工作得很好。
- 重启后,对扩展代理的任何SNMP请求都超时MIB browser。我从扩展代理中调试并发现在connect()调用中,我们得到了一个"WSAEACCES"(10013)权限被拒绝错误"。请看下面代码中的注释:
- 同样的事情在Windows Server 2008上运行良好。
struct sockaddr_in dest;
int sockfd;
char buffer;
int bytes_read;
char portNumberStr[10];
int iResult;
struct addrinfo *result = NULL, *ptr = NULL, hints;
WORD wVersionRequested;
WSADATA wsaData;
wVersionRequested = MAKEWORD(2, 2);
iResult = WSAStartup(wVersionRequested, &wsaData);
if (iResult != 0)
{
int WSAError = WSAGetLastError();
return SOAP_NO_SOCKET_ERROR;
}
ZeroMemory( &hints, sizeof(hints) );
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;
sprintf(portNumberStr, "%d", port_number);
iResult = getaddrinfo("127.0.0.1", portNumberStr, &hints, &result);
if (iResult != 0)
{
int WSAError = WSAGetLastError();
WSACleanup();
return SOAP_NO_SOCKET_ERROR;
}
// Loop through the results addrinfo structure
bool connectionSuccess = false;
for(ptr = result; ptr != NULL; ptr = result->ai_next)
{
// Create a socket
sockfd = socket(ptr->ai_family, ptr->ai_socktype, ptr->ai_protocol);
if (INVALID_SOCKET == sockfd)
{
int WSAError = WSAGetLastError();
continue;
}
iResult = connect(sockfd, ptr->ai_addr, (int)ptr->ai_addrlen); // This is the call where I get a WSAEACCES (10013) error.
if (iResult == SOCKET_ERROR)
{
int WSAError = WSAGetLastError();
closesocket(sockfd);
continue;
}
connectionSuccess = true;
break;
}
// Clean up
freeaddrinfo(result);
if(false == connectionSuccess)
{
return SOAP_ERROR;
}
// Form the Request
*localRequest = "Request goes in here"
// Send the message to the agent through a TCP socket.
send(sockfd,localRequest->c_str(),(int)localRequest->length(), 0);
// Clear out the request string so we can use it to hold a response.
*localRequest = "";
// Keep getting bytes from server until finished.
do
{
bytes_read = recv(sockfd, &buffer, sizeof(buffer), 0);
if ( bytes_read > 0 )
{
localRequest->append(1,buffer);
}
}
while ( bytes_read > 0 );
closesocket(sockfd);
WSACleanup();
与独立应用程序相同的代码能够与我们的代理通信并获得所需的数据。
请让我知道我还可以尝试什么,或者如果你需要更多的信息。
谢谢Aditya
这篇KB文章描述了我们的SNMP扩展代理在Windows 8/2012上面临的问题。本文中描述的根本原因如下:
任何试图在Windows Server 2012或Windows 8上执行任何UDP或TCP网络通信的SNMP扩展代理将失败。socket connect()请求将失败,状态码如下:0xC0000022 = STATUS_ACCESS_DENIED {Access Denied}。进程请求访问对象,但未被授予访问权限。
因此,为了解决这个问题,我们需要运行power shell脚本,我在这里找到它来添加SNMP服务的入站和出站规则,以便与我们的代理端口号对话。
connect()
文档说明:
WSAEACCES
试图连接数据报套接字到广播地址失败,因为setsockopt选项SO_BROADCAST未启用。
…对于无连接套接字,名称可以表示任何有效地址,包括广播地址。然而,要连接到广播地址,套接字必须使用setsockopt来启用SO_BROADCAST选项。否则,连接将失败,错误码为WSAEACCES。
相关文章:
- PC中的程序和PHONE中的本机描述应用程序之间的数据连接
- C++ TCP 套接字通信 - 连接按预期工作,几秒钟后失败,没有收到新数据,read() 和 recv() 块
- QTcpSocket 在 RemoteHostClosedError 后重新连接到服务器时无法传输数据
- 数据库连接并将数据从C ++程序保存到MySQL
- 连接到远程存储库并获取数据
- 如何使用 TCP 连接发送大块数据
- 连接UDP套接字,但仍然接收来自其他源的数据报
- 从多个 tcp 连接读取数据
- 将文本和二进制数据连接到一个文件中
- 如何将两个 jlong 数据类型转换为 jstring,然后将两个字符串连接在一起以便从 JNI 将字符串返回给 jav
- 如何通过解析缓冲区并将数据放入正确的结构来处理传入的数据包连接?
- TCP 连接中的超时,没有数据交换
- 如何将 Matlab 与 Visual Studio 连接以进行实时数据交换?
- QNETWORK停止连接并检索数据
- 在服务器关闭的TCP连接上发送数据时的行为不一致
- 使用 Python 连接到数据流
- 是STL中的联合获取(或不连接集)数据结构
- C++从外部设备读取数据 - 连接:光电USB
- 425 无法在我的程序上打开数据连接,而 Filezilla 工作
- visualstudio2008-使用C++将数据连接并插入到MS Access表中