Note that there are some explanatory texts on larger screens.

plurals
  1. POproblems with UDP snmp client Java
    primarykey
    data
    text
    <p>I'm writing an snmp client that connects to a network server via UDP port 161. It will send an ASN formatted message and will receive the response from the server. I've tried everything I can think of, but I can't seem to get it working properly.</p> <p>The program is supposed to receive and parse out the counter field returned from the following command in cmd:</p> <p>snmpget -d -v 2c -c public 129.130.10.43 ip.ipInReceives.0</p> <p>//result of command:</p> <p>{</p> <p>Sending 43 bytes to UDP: [129.130.10.43]:161->[0.0.0.0]</p> <p>0000: 30 29 02 01 01 04 06 70 75 62 6C 69 63 A0 1C 02 0).....public...</p> <p>0016: 04 28 6A DF 1F 02 01 00 02 01 00 30 0E 30 0C 06 .(j........0.0..</p> <p>0032: 08 2B 06 01 02 01 04 03 00 05 00 .+.........</p> <p>Received 47 bytes from UDP: [129.130.10.43]:161->[0.0.0.0]</p> <p>0000: 30 2D 02 01 01 04 06 70 75 62 6C 69 63 A2 20 02 0-.....public. .</p> <p>0016: 04 28 6A DF 1F 02 01 00 02 01 00 30 12 30 10 06 .(j........0.0..</p> <p>0032: 08 2B 06 01 02 01 04 03 00 41 04 1B 49 0C 95 .+.......A..I..</p> <p>IP-MIB::ipInReceives.0 = Counter32: 457772181</p> <p>}</p> <p>//my asn message formatting notes:</p> <p>hex values to save in a byte[] array and pass to the udp server:</p> <p>30 29 02 01 01 04 06 70 75 62 6C 69 63 A0 1C 02</p> <p>04 XX XX XX XX 02 01 00 02 01 00 30 0E 30 0C 06</p> <p>08 2B 06 01 02 01 04 03 00 05 00</p> <p>XX's indicate the request ID XX's will be changed (probably randomized) for each request in order to create a unique Request ID</p> <p>Code:</p> <pre><code> public static void snmpMessage() throws SocketException { DatagramSocket socket = null; byte[] serverResponse = new byte[1024]; InetAddress addy = null; byte[] hex = hexStringToByteArray("302902010004067075626C6963A01C0204121533EA020100020100300E300C06082B060102010403000500"); //note: this hex string is the exact string from the example program, so I know the string is correct addy = InetAddress.getByName("129.130.10.48"); //server IP address socket= new DatagramSocket(); //method that creates unique snmp asn message replacing the XX's with appropriate non-negative hex values hex = messageGenerator(); //Data reproduction from byte[] array System.out.println("byte array integer format:\n" + Arrays.toString(hex)); //correctly prints out integer values System.out.println("\nbyte array length: " + hex.length); //Correctly prints length of sending array (43) System.out.println("\nserver name: " + addy.getCanonicalHostName()); //correctly prints server name String hex2 = toHex(hex); System.out.println("\nbyte array in hex format: \n" + hex2); //correctly reproduces original hex string from byte[] array //at this point, I can only assume that my data is stored correctly //send byte array to server DatagramPacket sendPacket = new DatagramPacket(hex, hex.length, addy, 161); socket.send(sendPacket); //get server's response DatagramPacket receivePacket = new DatagramPacket(serverResponse, serverResponse.length); System.out.println("\nWaiting for server response...\n"); //prints out socket.receive(receivePacket); System.out.println("Response received"); //does not print } </code></pre> <p>My professor has posted an example where he simply passes the pointer to a char string: sendto (sockfd, (char *) s, 43, 0, (struct sockaddr *) &amp;serv_addr, servlen); His code that passes the same hex code works perfectly.</p> <p>The only thing I can think of is that I'm not formatting, sending, or listening correctly, but after pouring over documentation and examples, I can't figure anything out. Does anyone have some pointers?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload