Don't rely on the TERM variable to help you out here. You might have TERM set to linux in other situations also.
I'm not the most qualified person to answer this, because almost all my experience has been on Slackware. But it might help. I'm answering because nobody has answered you for more than a day. Maybe any misinformation I give you might spur someone else to give a real answer.
On Slackware, there's a file called "/etc/inittab". Among other things, it contains information about all the non-X ways you can log in. Search it for the word "serial". Close to that word, you should see the names of the tty devices which are used for serial port login. (Any which start with "#" have been commented out, and don't count.) On my system, I see "ttyS0" and "ttyS1" as those two devices.
If /etc/inittab isn't there on your distribution, try this at the command line:
grep -lr tty6 /etc 2> /dev/null
and look through the resultant list for the appropriate file.
Then, if you're in a script or at the command line, do this:
ls -l /proc/$$/fd/0
and see whether the device named in the symbolic link matches one of the serial login devices.
In C or elsewhere, do the programmatic equivalent.
Hope this helps.