alsmith / multicast-relay

Relay multicast and broadcast packets between interfaces.
GNU General Public License v3.0
318 stars 50 forks source link

Error mdnsForceUnicast #83

Open juliodiz opened 8 months ago

juliodiz commented 8 months ago

multicast-relay.py INFO: [mDNS] Relayed 302 bytes from 10.125.131.10:5353 on eth1.5 [ttl 255] to 224.0.0.251:5353 via eth1.10/10.125.0.1 Traceback (most recent call last): File "multicast-relay.py", line 1048, in sys.exit(main()) ^^^^^^ File "multicast-relay.py", line 1045, in main packetRelay.loop() File "multicast-relay.py", line 628, in loop data = PacketRelay.mdnsSetUnicastBit(data, ipHeaderLength) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "multicast-relay.py", line 396, in mdnsSetUnicastBit labelLength = struct.unpack('B', udpData[ptr:ptr+1])[0] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ struct.error: unpack requires a buffer of 1 bytes

@staticmethod def mdnsSetUnicastBit(data, ipHeaderLength): headers = data[:ipHeaderLength+8] udpData = data[ipHeaderLength+8:]

flags = struct.unpack('!H', udpData[2:4])[0]
if flags & 0x8000 != 0:
    return data

queries = struct.unpack('!H', udpData[4:6])[0]

queryCount = 0
ptr = 12
while ptr < len(udpData):
    if len(udpData[ptr:]) < 1:
        break  # Sair do loop se não houver bytes suficientes para desempacotar

    labelLength = struct.unpack('B', udpData[ptr:ptr+1])[0]
    if not labelLength & 0x3f:
        if labelLength & 0xc0:
            ptr += 1
        queryCount += 1
        if len(udpData[ptr+3:ptr+5]) < 2:
            break  # Sair do loop se não houver bytes suficientes para desempacotar
        data = struct.unpack('!H', udpData[ptr+3:ptr+5])[0]
        udpData = udpData[:ptr+3] + struct.pack('!H', data | 0x8000) + udpData[ptr+5:]
        if queryCount == queries:
            break
        ptr += 5
    else:
        ptr += labelLength+1

return headers + udpData