getnetbynm.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * Copyright (c) 1983 Regents of the University of California.
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms are permitted
  6. * provided that the above copyright notice and this paragraph are
  7. * duplicated in all such forms and that any documentation,
  8. * advertising materials, and other materials related to such
  9. * distribution and use acknowledge that the software was developed
  10. * by the University of California, Berkeley. The name of the
  11. * University may not be used to endorse or promote products derived
  12. * from this software without specific prior written permission.
  13. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  14. * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  15. * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  16. */
  17. #define setnetent __setnetent
  18. #define getnetent __getnetent
  19. #define endnetent __endnetent
  20. #define __FORCE_GLIBC
  21. #include <features.h>
  22. #include <netdb.h>
  23. #include <string.h>
  24. extern int _net_stayopen;
  25. struct netent *
  26. getnetbyname(const char *name)
  27. {
  28. register struct netent *p;
  29. register char **cp;
  30. setnetent(_net_stayopen);
  31. while ((p = getnetent())) {
  32. if (__strcmp(p->n_name, name) == 0)
  33. break;
  34. for (cp = p->n_aliases; *cp != 0; cp++)
  35. if (__strcmp(*cp, name) == 0)
  36. goto found;
  37. }
  38. found:
  39. if (!_net_stayopen)
  40. endnetent();
  41. return (p);
  42. }