getnetent.c 374 B

1234567891011121314151617
  1. #include <stdio.h>
  2. #include <netdb.h>
  3. int main(void)
  4. {
  5. struct netent *net;
  6. setnetent(0);
  7. while ((net = getnetent())) {
  8. while (net->n_net && !((net->n_net >> 24) & 0xff)) {
  9. net->n_net <<= 8;
  10. }
  11. printf("%lu.%lu.%lu.%lu\n",
  12. (net->n_net >> 24) & 0xff, (net->n_net >> 16) & 0xff,
  13. (net->n_net >> 8) & 0xff, net->n_net & 0xff);
  14. }
  15. endnetent();
  16. return 0;
  17. }