Dogs attack for one of three basic reasons:
Dominance aggression is usually directed toward the face or hands of a person when their face looms too close or their hands somehow threaten or interfere with the dog or its possessions. Standing motionless and looking away will often defuse this type of aggression.
Fear aggression often takes the form of a "cheap shot" directed toward a person's calf or thigh as they turn to exit the scene. Standing still can deactivate this type of aggression by halting the perceived challenge while simultaneously holding one's ground.
Predatory aggression is stimulated by motion and commotion, running away and by yelling. It is best to stand still and be quiet to defuse such attacks.
In summary, if a dog is making an aggressive advance – stop running, remain motionless and silent, do not look into the dog's eyes, and keep your hands to yourself. Or, in an extreme situation, drop to the ground, curl in a ball, and protect the nape of your neck with your hands.
For more information, please read How to Protect Yourself From Dog Bites.