Mirror of :pserver:cvs@cvs.fefe.de:/cvs libowfat https://www.fefe.de/libowfat/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

57 lines
1.1 KiB

  1. #include <sys/types.h>
  2. #ifndef __MINGW32__
  3. #include <unistd.h>
  4. #include <sys/socket.h>
  5. #include <netinet/in.h>
  6. #endif
  7. #include "windoze.h"
  8. #include <errno.h>
  9. #include "haveip6.h"
  10. #include "socket.h"
  11. #include "ndelay.h"
  12. #ifndef EAFNOSUPPORT
  13. #define EAFNOSUPPORT EINVAL
  14. #endif
  15. #ifndef EPFNOSUPPORT
  16. #define EPFNOSUPPORT EAFNOSUPPORT
  17. #endif
  18. #ifndef EPROTONOSUPPORT
  19. #define EPROTONOSUPPORT EAFNOSUPPORT
  20. #endif
  21. int socket_udp6b(void)
  22. {
  23. #ifdef LIBC_HAS_IP6
  24. int s;
  25. __winsock_init();
  26. if (noipv6) goto compat;
  27. s = winsock2errno(socket(PF_INET6,SOCK_DGRAM,0));
  28. if (s == -1) {
  29. if (errno == EINVAL || errno == EAFNOSUPPORT || errno == EPFNOSUPPORT || errno == EPROTONOSUPPORT) {
  30. compat:
  31. s=winsock2errno(socket(AF_INET,SOCK_DGRAM,0));
  32. noipv6=1;
  33. if (s==-1) return -1;
  34. } else
  35. return -1;
  36. }
  37. #ifdef IPV6_V6ONLY
  38. {
  39. int zero=0;
  40. winsock2errno(setsockopt(s,IPPROTO_IPV6,IPV6_V6ONLY,(void*)&zero,sizeof(zero)));
  41. }
  42. #endif
  43. return s;
  44. #else
  45. return socket_udp4b();
  46. #endif
  47. }
  48. int socket_udp6(void) {
  49. int s=socket_udp6b();
  50. if (s!=-1 && ndelay_on(s) == -1) { close(s); return -1; }
  51. return s;
  52. }