home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / unix / unixlib_1 / !UnixLib37_netlib_netlib_c_inet_netof < prev    next >
Encoding:
Text File  |  1996-07-28  |  907 b   |  48 lines

  1. /****************************************************************************
  2.  *
  3.  * $Source$
  4.  * $Date$
  5.  * $Revision$
  6.  * $State$
  7.  * $Author$
  8.  *
  9.  * $Log$
  10.  ***************************************************************************/
  11.  
  12. static const char rcs_id[] = "$Id$";
  13.  
  14. #include <arpa/inet.h>
  15. #include <netinet/in.h>
  16.  
  17. /*
  18.  * Extract a network number from an internet address
  19.  */
  20. u_long
  21. inet_netof (struct in_addr in)
  22. {
  23.   u_long net;
  24.  
  25.   if (IN_CLASSA (in.s_addr))
  26.     {
  27.       /* Extract a class A network number */
  28.       net = in.s_addr & IN_CLASSA_NET;
  29.     }
  30.   else if (IN_CLASSB (in.s_addr))
  31.     {
  32.       /* Extract a class B network number */
  33.       net = in.s_addr & IN_CLASSB_NET;
  34.     }
  35.   else if (IN_CLASSC (in.s_addr))
  36.     {
  37.       /* Extract a class C network number */
  38.       net = in.s_addr & IN_CLASSC_NET;
  39.     }
  40.   else
  41.     {
  42.       /* Not a known address format */
  43.       net = 0;
  44.     }
  45.  
  46.   return net;
  47. }
  48.