Xref: utzoo comp.unix.wizards:17408 comp.unix.questions:15276 Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!cs.utexas.edu!uunet!daitc!dgis!generous From: generous@dgis.daitc.mil (Curtis Generous) Newsgroups: comp.unix.wizards,comp.unix.questions Subject: is it a socket or is it not? Keywords: workaround, fstat, bug Message-ID: <8@dgis.daitc.mil> Date: 29 Jul 89 17:49:15 GMT Followup-To: comp.unix.questions Organization: DTIC Special Projects Office (DTIC-SPO), Alexandria VA Lines: 23 What's a good method of determining whether a file descriptor is a socket or not? The fstat(2) call does not work well on sockets (and it even says so in the man page :-) This is what I would like to do but doesn't work: if (fstat(fildes, &statb) == 0) { if ((statb.st_mode &= S_IFMT) == S_IFSOCK) sockflag++; } Is there a better/cleaner way? Do you go through the list of possibles and work by elimination (S_IFREG, S_IFDIR, ...)? Can I assume that fstat(2) will _always_ return a zeroed buffer as mentioned in the BUGS of the man page? The OS is More/BSD 4.3 on a VAX 780, but I think this spans many BSD derivatives --curtis -- Curtis C. Generous DTIC Special Projects Office (DTIC-SPO) ARPA: generous@daitc.mil UUCP: {uunet,vrdxhq,lll-tis}!daitc!generous