Is there a way to stop a man-in-the-middle attack when communicating addresses?
No. That is impossible if A and B have never communicated through a secure channel to exchange keys before, unless you are willing to trust another user, for example a user, D, you know and have safely exchanged keys before, that says it trust users B address, creating a web of trust or less preferable a certificate authority. This is a known and significant issue in public key exchange.