The Sniff test - Stop doing that!
The sniff test is a badly ingrained habit that society has been taught, without a clear understanding of what they're actually doing.
When you reach out towards a dog, you are using body pressure AT them, giving them no time to assess whether you are safe & whether they require further investigation to pick up your information.
Especially when on a lead, they know they have nowhere to go, no space if they are sensitive to physical pressure - see Prossemica - , so to make you back-off they can either shut down, shy away or snap at your hand .
People think by offering your hand it can give the dog time to sniff to know you're friendly... they can sniff without being forced to sniff your hand.Their noses are far more superior than ours & they don't need close contact forced upon them to smell you.
Some dogs might not want to know you. You have no relationship with them and that's perfectly fine. They aren't your dog so you don't need to touch them or steal pats for your own satisfaction.
If you are meeting a dog, what should you do?
Ask the owner if you can interact with their dog. Not all people want strangers touching their dogs. Especially strangers who you are unlikely to see again.
Stand up straight & relaxed, with your hands at your side.
Ignore the dog & talk to the owner.
Don't stare at the dog & don't try to force an interaction by going in for a pat. If the dog wants to know you, it will come up to you & sniff around. Usually they will move away & then come back for a second sniffathon. Some dogs will bunt your hands & wag their tails, which are good signs that you're likely an accepted new friend. Give them a few slow pats down their back (NOT THEIR HEAD) & then stop. Is the dog happy? Has it accepted your interaction? This will determine whether you can give it more pats.
This is a more stress free option for dogs & a reason why in consultations we can develop a good level of trust, especially with fearful dogs & aggressive dogs, without a bunch of negative side effects from forced interactions