rfc2553emu.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: rfc2553emu.h,v 1.2 1999/05/26 04:08:39 jgg Exp $
  4. /* ######################################################################
  5. RFC 2553 Emulation - Provides emulation for RFC 2553 getaddrinfo,
  6. freeaddrinfo and getnameinfo
  7. These functions are necessary to write portable protocol independent
  8. networking. They transparently support IPv4, IPv6 and probably many
  9. other protocols too. This implementation is needed when the host does
  10. not support these standards. It implements a simple wrapper that
  11. basically supports only IPv4.
  12. Perfect emulation is not provided, but it is passable..
  13. Originally written by Jason Gunthorpe <jgg@debian.org> and placed into
  14. the Public Domain, do with it what you will.
  15. ##################################################################### */
  16. /*}}}*/
  17. #ifndef RFC2553EMU_H
  18. #define RFC2553EMU_H
  19. #include <netdb.h>
  20. #include <sys/types.h>
  21. #include <sys/socket.h>
  22. // Autosense getaddrinfo
  23. #if defined(AI_PASSIVE) && defined(EAI_NONAME)
  24. #define HAVE_GETADDRINFO
  25. #endif
  26. // Autosense getnameinfo
  27. #if defined(NI_NUMERICHOST)
  28. #define HAVE_GETNAMEINFO
  29. #endif
  30. // getaddrinfo support?
  31. #ifndef HAVE_GETADDRINFO
  32. #error Boink
  33. // Renamed to advoid type clashing.. (for debugging)
  34. struct addrinfo_emu
  35. {
  36. int ai_flags; /* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST */
  37. int ai_family; /* PF_xxx */
  38. int ai_socktype; /* SOCK_xxx */
  39. int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */
  40. size_t ai_addrlen; /* length of ai_addr */
  41. char *ai_canonname; /* canonical name for nodename */
  42. struct sockaddr *ai_addr; /* binary address */
  43. struct addrinfo *ai_next; /* next structure in linked list */
  44. };
  45. #define addinfo addrinfo_emu
  46. int getaddrinfo(const char *nodename, const char *servname,
  47. const struct addrinfo *hints,
  48. struct addrinfo **res);
  49. void freeaddrinfo(struct addrinfo *ai);
  50. #ifndef AI_PASSIVE
  51. #define AI_PASSIVE (1<<1)
  52. #endif
  53. #ifndef EAI_NONAME
  54. #define EAI_NONAME -1
  55. #define EAI_AGAIN -2
  56. #define EAI_FAIL -3
  57. #define EAI_NODATA -4
  58. #define EAI_FAMILY -5
  59. #define EAI_SOCKTYPE -6
  60. #define EAI_SERVICE -7
  61. #define EAI_ADDRFAMILY -8
  62. #define EAI_SYSTEM -10
  63. #endif
  64. #endif
  65. // getnameinfo support (glibc2.0 has getaddrinfo only)
  66. #ifndef HAVE_GETNAMEINFO
  67. int getnameinfo(const struct sockaddr *sa, socklen_t salen,
  68. char *host, size_t hostlen,
  69. char *serv, size_t servlen,
  70. int flags);
  71. #ifndef NI_MAXHOST
  72. #define NI_MAXHOST 1025
  73. #define NI_MAXSERV 32
  74. #endif
  75. #ifndef NI_NUMERICHOST
  76. #define NI_NUMERICHOST (1<<0)
  77. #define NI_NUMERICSERV (1<<1)
  78. // #define NI_NOFQDN (1<<2)
  79. #define NI_NAMEREQD (1<<3)
  80. #define NI_DATAGRAM (1<<4)
  81. #endif
  82. #endif
  83. #endif