Dogs sniff one another because they are communicating on some basic level. They are communicating with pheromones, odorless molecules that waft from most animals. These powerful molecules carry important messages.
Pheromones tell animals what they are supposed to do, such as run, fight or have sex.
The nice thing about pheromone messages is that animals don't have to worry if they are making the right decision. They have no self-doubt. They are not conflicted. They don't worry about the morality or repercussions of their pheromone-induced actions. Hey, it smelled right, so I did it.