my_net.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /* Copyright (C) 2000 MySQL AB
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation; version 2 of the License.
  5. This program is distributed in the hope that it will be useful,
  6. but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8. GNU General Public License for more details.
  9. You should have received a copy of the GNU General Public License
  10. along with this program; if not, write to the Free Software
  11. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
  12. /*
  13. thread safe version of some common functions:
  14. my_inet_ntoa
  15. This file is also used to make handling of sockets and ioctl()
  16. portable accross systems.
  17. */
  18. #ifndef _my_net_h
  19. #define _my_net_h
  20. C_MODE_START
  21. #include <errno.h>
  22. #ifdef HAVE_SYS_SOCKET_H
  23. #include <sys/socket.h>
  24. #endif
  25. #ifdef HAVE_NETINET_IN_H
  26. #include <netinet/in.h>
  27. #endif
  28. #ifdef HAVE_ARPA_INET_H
  29. #include <arpa/inet.h>
  30. #endif
  31. #ifdef HAVE_POLL
  32. #include <sys/poll.h>
  33. #endif
  34. #ifdef HAVE_SYS_IOCTL_H
  35. #include <sys/ioctl.h>
  36. #endif
  37. #if !defined(__WIN__) && !defined(HAVE_BROKEN_NETINET_INCLUDES) && !defined(__BEOS__) && !defined(__NETWARE__)
  38. #include <netinet/in_systm.h>
  39. #include <netinet/in.h>
  40. #include <netinet/ip.h>
  41. #if !defined(alpha_linux_port)
  42. #include <netinet/tcp.h>
  43. #endif
  44. #endif
  45. #if defined(__WIN__)
  46. #define O_NONBLOCK 1 /* For emulation of fcntl() */
  47. /*
  48. SHUT_RDWR is called SD_BOTH in windows and
  49. is defined to 2 in winsock2.h
  50. #define SD_BOTH 0x02
  51. */
  52. #define SHUT_RDWR 0x02
  53. #endif
  54. /*
  55. On OSes which don't have the in_addr_t, we guess that using uint32 is the best
  56. possible choice. We guess this from the fact that on HP-UX64bit & FreeBSD64bit
  57. & Solaris64bit, in_addr_t is equivalent to uint32. And on Linux32bit too.
  58. */
  59. #ifndef HAVE_IN_ADDR_T
  60. #define in_addr_t uint32
  61. #endif
  62. /* On some operating systems (e.g. Solaris) INADDR_NONE is not defined */
  63. #ifndef INADDR_NONE
  64. #define INADDR_NONE -1 /* Error value from inet_addr */
  65. #endif
  66. /* Thread safe or portable version of some functions */
  67. void my_inet_ntoa(struct in_addr in, char *buf);
  68. /*
  69. Handling of gethostbyname_r()
  70. */
  71. #if !defined(HPUX10)
  72. struct hostent;
  73. #endif /* HPUX */
  74. #if !defined(HAVE_GETHOSTBYNAME_R)
  75. struct hostent *my_gethostbyname_r(const char *name,
  76. struct hostent *result, char *buffer,
  77. int buflen, int *h_errnop);
  78. void my_gethostbyname_r_free();
  79. #elif defined(HAVE_PTHREAD_ATTR_CREATE) || defined(_AIX) || defined(HAVE_GETHOSTBYNAME_R_GLIBC2_STYLE)
  80. struct hostent *my_gethostbyname_r(const char *name,
  81. struct hostent *result, char *buffer,
  82. int buflen, int *h_errnop);
  83. #define my_gethostbyname_r_free()
  84. #if !defined(HAVE_GETHOSTBYNAME_R_GLIBC2_STYLE) && !defined(HPUX10)
  85. #define GETHOSTBYNAME_BUFF_SIZE sizeof(struct hostent_data)
  86. #endif /* !defined(HAVE_GETHOSTBYNAME_R_GLIBC2_STYLE) */
  87. #elif defined(HAVE_GETHOSTBYNAME_R_RETURN_INT)
  88. #define GETHOSTBYNAME_BUFF_SIZE sizeof(struct hostent_data)
  89. struct hostent *my_gethostbyname_r(const char *name,
  90. struct hostent *result, char *buffer,
  91. int buflen, int *h_errnop);
  92. #define my_gethostbyname_r_free()
  93. #else
  94. #define my_gethostbyname_r(A,B,C,D,E) gethostbyname_r((A),(B),(C),(D),(E))
  95. #define my_gethostbyname_r_free()
  96. #endif /* !defined(HAVE_GETHOSTBYNAME_R) */
  97. #ifndef GETHOSTBYNAME_BUFF_SIZE
  98. #define GETHOSTBYNAME_BUFF_SIZE 2048
  99. #endif
  100. /* On SCO you get a link error when refering to h_errno */
  101. #ifdef SCO
  102. #undef h_errno
  103. #define h_errno errno
  104. #endif
  105. C_MODE_END
  106. #endif