#include
#include
int main () {WSADATA data; SOCKET s; sockaddr_in addr; sockaddr_in to; sockaddr_in from; int fromlen = sizeof (from); unsigned char buf [1025]; int ret; HANDLE hSocketEvent; WSANETWORKEVENTS NetWorkEvents; WSAStartup (MAKEWORD (2, 2), & data); s = socket (AF_INET, SOCK_DGRAM, IPPROTO_UDP); if (s == -1) Return 0; addr.sin_family = AF_INET; addr.sin_port = htons (2227); addr.sin_addr.s_un.s_addr = INET_ADDR ("192.168.0.92"); to.sin_family = AF_INET; TO.SIN_PORT = HTONS (161); to.sin_addr.s_un.s_addr = inet_addr ("192.168.0.92"); RET = Bind (s, (SockAddr *) & addr, sizeof (addr)); if (RET == -1) Return 0; BUF [0] = 48; BUF [1] = 38; // Version BUF [2] = 0x02; buf [3] = 1; BUF [4] = 0; // Community Name BUF [5] = 0x4; // Len of Community Name BUF [6] = 6; // Community Name BUF [7] = 'P'; buf [8] = 'u'; buf [9] = 'b'; buf [10] = 'L'; buf [11] = 'i'; buf [12] = 'c'; // Get Request buf [13] = 160; BUF [14] = 25; // ID word nrand = rand (); memcpy (& Buf [15], & rand, 2); buf [15] = 0x02; buf [16] = 0x01; buf [17] = 0; // Error BUF [18] = 0x02; BUF [19] = 0x01; BUF [20] = 0x00; // Index BUF [21] = 0x02; BUF [22] = 0x01; BUF [23] = 0x00; // varbind list buf [24] = 0x30; buf [25] = 14; // var Bind BUF [26] = 48; BUF [27] = 12; // Object ID BUF [28] = 6; BUF [29] = 8; BUF [30] = 43; buf [31] = 0x06; BUF [32] = 0x01; BUF [33] = 0x02; BUF [34] = 0x01; BUF [35] = 0x01; BUF [36] = 0x04; buf [37] = 0x00; buf [ 38] = 0x05; BUF [39] = 0x00; hsocketevent = CreateEvent (Null, True, False, Null);