What Smaug says in the movie:
"Come now, don't be shy. Step into the light. Hmmm, there is something
about you. Something you carry. Something made of gold, but far more
In the book Smaug says nothing of the kind. Instead, he tries to get information out of Bilbo and sow him with suspicions about the honesty and intentions of the dwarves (the dwarves said nothing about how he would get his "14th share" of the gold back to Bag End, for example).
The movie script is shorter, more dramatic and is meant to foreshadow the part the ring would play in the subsequent adventures.
If there is a rationale for how Smaug detected the ring, it would be that as an ancient and evil creature he could sense its power. In the movie a parallel is drawn between the eye of Sauron and the eye of Smaug, the two images being juxtaposed. In fact, it is the gaze of Smaug's eye that pressures Bilbo and leads him to take off the ring, with the result that Smaug can see him. Presumably Fran Walsh, the screen writer, had the idea that, like the minions of Sauron, Smaug would sense the ring and be "drawn to it", almost like a ring wraith, or at least be aware of its nature at some level.
As for Smaug's knowledge of Sauron, this is not mentioned in the book, but of course a dragon would know such things. Smaug's abode in the Iron Hills adjoins Mirkwood and he would know of Mirkwood's descent into darkness, and the source of the evil power residing in Dol Guldur in the south of Mirkwood.