aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/helper
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/traccar/helper')
-rw-r--r--src/main/java/org/traccar/helper/Checksum.java15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/main/java/org/traccar/helper/Checksum.java b/src/main/java/org/traccar/helper/Checksum.java
index 8c3d0063a..db5817275 100644
--- a/src/main/java/org/traccar/helper/Checksum.java
+++ b/src/main/java/org/traccar/helper/Checksum.java
@@ -200,4 +200,19 @@ public final class Checksum {
return (10 - (checksum % 10)) % 10;
}
+ public static int ip(ByteBuffer data) {
+ int sum = 0;
+ while (data.remaining() > 0) {
+ sum += data.get() & 0xff;
+ if ((sum & 0x80000000) > 0) {
+ sum = (sum & 0xffff) + (sum >> 16);
+ }
+ }
+ while ((sum >> 16) > 0) {
+ sum = (sum & 0xffff) + sum >> 16;
+ }
+ sum = (sum == 0xffff) ? sum & 0xffff : (~sum) & 0xffff;
+ return sum;
+ }
+
}