Skip to contentSkip to conversation

Socket vs File descriptor

DISCUSSION KV Pavuram 3 participants 3 messages Sep 24, 2009

lore
Share & tools
lore

KV Pavuram

author
#0 lore raw

Hi,

Is there any ioctl call to determine if a given descriptor is a file descriptor or a socket descriptor.

Similarly, is there a way to find out a socket descriptor type ie.e if it is SOCK_STREAM, or SOCK_DGRAM type.

Thanks
Pav

See the Web's breaking stories, chosen by people like you. Check out Yahoo! Buzz. http://in.buzz.yahoo.com/

#1 lore raw
Quoted 5 lines · KV Pavuram

Hi,

Is there any ioctl call to determine if a given descriptor is a file descriptor or a socket descriptor.

Similarly, is there a way to find out a socket descriptor type ie.e if it is SOCK_STREAM, or SOCK_DGRAM type.

You should look at getsockopt(), getsockname(), etc... I'm pretty sure that one of those will offer you exactly what you need. Also, look at the error codes. Sometimes you can rely on them because you have different types depending on whether the FD you point to is not a socket or is a socket of invalid type.

Regards,
Willy

#2 lore raw
In reply to KV Pavuram
Quoted 3 lines · KV Pavuram

Is there any ioctl call to determine if a given descriptor is a file descriptor or a socket descriptor.

Similarly, is there a way to find out a socket descriptor type ie.e if it is SOCK_STREAM, or SOCK_DGRAM type.

Maybe "lsof" command is your friend.

Or, depending on your purpose, you can use
getsockopt(), listen() etc. to get error
(e.g. ENOTSOCK) to test the type.

--yoshfuji