how to decode the result of listenning to port 162 (Snmp Trap)?

独自空忆成欢 提交于 2019-12-06 16:08:28

Short answer; it is the memory address of msg written in octal.

If you are running this code on a little-endian machine with 32-bit int and 64-bit pointers, it is most likely the lower 32 bits of the address of msg.

This is due to a combination of two thins:

  1. The printf format specifier %o interprets the next bytes in the argument data as an integer and prints it in octal.

  2. Passing an array as an argument to a function is converted into passing a pointer to the first element. So these statements are equivalent:

    printf("%p\n", msg);
    printf("%p\n", &msg[0]);
    

To actually print the data you received, add the following:

for (int i = 0; i < n; ++i) {
    printf("%02x ", (unsigned char)msg[i]);
}
printf("\n");
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!