There are all kinds of worms that dogs get. heartworms, whip worms, roundworms, hookworms, tapeworms. Some come from bites, others from food, and other from walking where an infected dog did its business.
Ingested fly poop is another way. You should look for matter ( yellowish white pus-like stuff in the inside corners of your dog's eyes) and unusual white things in their stool. Sometimes still moving. Take a moist sample to the vet regularly to have it checked for worms.