diff --git a/notice.go b/notice.go index af1c032..aa8818b 100644 --- a/notice.go +++ b/notice.go @@ -248,7 +248,13 @@ func DecodeRawNotice(r *RawNotice) (*Notice, error) { var senderAddress net.IP if len(r.HeaderFields) > senderSockaddrIndex { - ipBytes, err := DecodeZcode(r.HeaderFields[senderSockaddrIndex]) + sockaddrField := r.HeaderFields[senderSockaddrIndex] + var ipBytes []byte + if len(sockaddrField) != 0 && sockaddrField[0] == 'Z' { + ipBytes, err = DecodeZcode(sockaddrField) + } else { + ipBytes, err = DecodeZAscii(sockaddrField) + } if err != nil { return nil, err } diff --git a/notice_test.go b/notice_test.go index 29f574e..1c0b9c7 100644 --- a/notice_test.go +++ b/notice_test.go @@ -120,8 +120,16 @@ func TestDecodeNotice(t *testing.T) { } // Value in sender address takes precedence over UID value. - raw.HeaderFields[17] = []byte("Z\x08\x08\x08\x08") - expected.SenderAddress = net.ParseIP("8.8.8.8").To4() + raw.HeaderFields[17] = []byte("Z\xDE\xAD\xBE\xEF") + expected.SenderAddress = net.ParseIP("222.173.190.239").To4() + if notice, err := DecodeRawNotice(raw); err != nil { + t.Errorf("DecodeRawNotice(%v) failed: %v", raw, err) + } else { + expectNoticesEqual(t, notice, expected) + } + + raw.HeaderFields[17] = []byte("0xDEADBEEF") + expected.SenderAddress = net.ParseIP("222.173.190.239").To4() if notice, err := DecodeRawNotice(raw); err != nil { t.Errorf("DecodeRawNotice(%v) failed: %v", raw, err) } else { diff --git a/raw_notice.go b/raw_notice.go index 7c37603..6e4ac4d 100644 --- a/raw_notice.go +++ b/raw_notice.go @@ -130,7 +130,7 @@ const ( multipartIndex // string multiuidIndex // 12-byte zascii // Added in 2009; no version bump - senderSockaddrIndex // zcode + senderSockaddrIndex // zcode or zascii charsetIndex // zascii16 little-endian // Other fields numKnownFields