The idea of my socket is receiving and sending SNMP-packets - GetRequest/GetResponse
. However, the socket already receive SNMP-packets
...
unsigned char buf[8192];
...
for (;;) {
// Receive snmp message from snmp manager
recv_len = recvfrom(my_socket, buf, BUFSIZE, 0, (struct sockaddr
*)&remote_addr, &addr_len);
...
Now I want answer the request by a SNMP-Packet which is represents as string. Note: The response contains a GetResponse-PDU
( a2
).
unsigned char * packet = "302902010004067075626c6963a21c...";
int r = sendto(my_socket, packet, strlen(packet), 0, (struct sockaddr *)&remote_addr, addr_len);
The return value or r
is 4
and is definitely wrong because my responding SNMP-packet packet
is larger than 4. Why, because it's a pointer?.
Further, the response SNMP-Packet packet
is not send as SNMP-Packet, it looks different compare to packet
and is not interpret as a SNMP-Packet in Wireshark. It looks like that:
How can I send a valid SNMP-Packet?
Your problem is the strlen(packet) value, which is 4 due to the 00 byte. strlen is meant to be used with ASCII strings, not binary strings.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.