anal glands of each dog emits a unique scent. so the smell from their butts are a "name tag" of sorts. so they sniff each other's butts for identification purposes.

that least that's what i've read.
as for sniffing their own pee... well, they do sniff around for a pee scent to determine where is a good spot to pee or poo. so somehow there is method to their madness i guess....
what i'd like to know is, why does my puppy each his own poo??? now that is GROSS!!!