Some of the commentary in this bug doesn't make a lot of sense to me. I don't get the parts about referencing the local addresses variable; a simpler change works fine for me in practice. Anyway, attached is a slightly more complete patch that doesn't move the addresses variable and that adds documentation strings. I've tested this patch and confirmed that it has the desired behavior.