Muhammad bin Abdullah bin Abi Ya'qub narrates from Rabah something of the same meaning, and at its end it says that the Messenger of Allah (peace and blessings be upon him) "judged the child to belong to the owner of the bed, and for the adulterer is the stone." He is your son: you inherit from him and he inherits from you. I said: "Subhan Allah (Glory be to Allah)!" He said: "That is how it is." So I used to put him to sleep between the two of them: these two are black and this one is white.
Hadith Referenceالسنن الكبرى للبيهقي / كتاب اللعان / 15332