Path: utzoo!utgpu!watmath!iuvax!purdue!bu-cs!madd
From: madd@bu-cs.BU.EDU (Jim Frost)
Newsgroups: comp.unix.questions
Subject: Re: is it a socket or is it not?
Message-ID: <36319@bu-cs.BU.EDU>
Date: 12 Aug 89 05:15:22 GMT
References: <8@dgis.daitc.mil>
Reply-To: madd@buit15.bu.edu (Jim Frost)
Followup-To: comp.unix.questions
Organization: Software Tool & Die
Lines: 24

In article <8@dgis.daitc.mil> generous@dgis.daitc.mil (Curtis Generous) writes:
|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 :-)

Probably the easiest way is:

int isASocket(s)
	int s;
{ struct sockaddr name;
  int             len;

  if ((getsockname(s, &name, &len) < 0) && (errno == ENOTSOCK))
    return(0);
  else
    return(1);
}

You could probably use a variety of other functions, but this seems
safe enough.

jim frost
software tool & die
madd@std.com