home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume20 / etherlib / part01 / src / etherblock.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-10-24  |  890 b   |  46 lines

  1. /* $Id: etherblock.c,v 2.1 89/10/23 15:42:26 dupuy Exp $ */
  2.  
  3. #include <sys/file.h>            /* FNBIO/FNDELAY */
  4.  
  5. #ifdef __STDC__
  6. extern int fcntl (int f, int c, int a);
  7. #else
  8. extern int fcntl ();
  9. #endif
  10.  
  11. #ifdef FNBIO
  12. #define FNOBLOCK FNBIO
  13. #else
  14. #define FNOBLOCK FNDELAY
  15. #endif
  16.  
  17. #define ERR (-1)
  18.  
  19. /*
  20.  * If state is false (0), set ethernet file descriptor fd to be non-blocking,
  21.  * else set fd to be blocking. If there is an error, ether_blocking() returns
  22.  * (-1) and the appropriate value is left in errno.  Normal return status
  23.  * zero.
  24.  */
  25.  
  26. int
  27. ether_blocking (fd, state)
  28. int fd;
  29. int state;
  30. {
  31.     int flags;
  32.  
  33.     if ((flags = fcntl (fd, F_GETFL, -1)) < 0)
  34.     return (ERR);
  35.  
  36.     if (state)
  37.     if (flags & FNOBLOCK)
  38.         state = fcntl (fd, F_SETFL, flags & ~FNOBLOCK);
  39.     else
  40.         state = 0;
  41.     else if ((flags & FNOBLOCK) == 0)
  42.     state = fcntl (fd, F_SETFL, flags | FNOBLOCK);
  43.  
  44.     return (state);
  45. }
  46.