Skip to content

Commit 6c13227

Browse files
committed
Reject packets which are unlikely meter updates. Resolves #2
1 parent 1259eb4 commit 6c13227

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

shm-et340.go renamed to main.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,17 @@ func msgHandler(src *net.UDPAddr, n int, b []byte) {
246246
// 0-28: SMA/SUSyID/SN/Uptime
247247
log.Debug("----------------------")
248248
log.Debug("Received datagram from meter")
249+
250+
if binary.BigEndian.Uint32(b[20:24]) == 0xffffffff {
251+
log.Debug("Implausible serial, rejecting")
252+
return
253+
}
254+
if n < 500 {
255+
log.Debug("Received packet is probably too small. Size: ", n)
256+
log.Debug("Serial: ", binary.BigEndian.Uint32(b[20:24]))
257+
return
258+
}
259+
249260
log.Debug("Uid: ", binary.BigEndian.Uint32(b[4:8]))
250261
log.Debug("Serial: ", binary.BigEndian.Uint32(b[20:24]))
251262

0 commit comments

Comments
 (0)