Current-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

fstat(2) fails on AF_LINK socket descriptor



Hi,

I have some code that tries to detect file type given a descriptor by
using fstat(2) ... and do some specific stuff accordingly, and
specifically for socket descriptors.

It mostly works, except for AF_LINK socket descriptor where fstat(2)
fails with EOPNOTSUPP. Like with the attached sample code.

Looking at the code in src/sys/net/link_proto.c confirms that
behavior :

static int
link_stat(struct socket *so, struct stat *ub)
{
        KASSERT(solocked(so));

        return EOPNOTSUPP;
}

But this is an exception as all other stat functions returns 0 instead
of EOPNOTSUPP.

Any specific reason for this one ?

Thanks.

-- 
Nicolas Joly

Cluster & Computing Group
Biology IT Center
Institut Pasteur, Paris.
#include <sys/socket.h>
#include <sys/stat.h>

#include <assert.h>
#include <unistd.h>

int main() {
  int res, fd;
  struct stat st;

  fd = socket(AF_LINK, SOCK_DGRAM, 0);
  assert(fd != -1);
  res = fstat(fd, &st);
  assert(res != -1);
  assert(S_ISSOCK(st.st_mode) != 0);
  assert(close(fd) != -1);

  return 0; }


Home | Main Index | Thread Index | Old Index