File: socket_udp6.c

package info (click to toggle)
libowfat 0.22-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 3,148 kB
  • ctags: 976
  • sloc: ansic: 10,424; makefile: 42
file content (42 lines) | stat: -rw-r--r-- 779 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <sys/types.h>
#ifndef __MINGW32__
#include <sys/socket.h>
#include <netinet/in.h>
#endif
#include "windoze.h"
#include <errno.h>
#include "haveip6.h"
#include "socket.h"

#ifndef EAFNOSUPPORT
#define EAFNOSUPPORT EINVAL
#endif

int socket_udp6(void)
{
#ifdef LIBC_HAS_IP6
  int s;

  __winsock_init();
  if (noipv6) goto compat;
  s = winsock2errno(socket(PF_INET6,SOCK_DGRAM,0));
  if (s == -1) {
    if (errno == EINVAL || errno == EAFNOSUPPORT) {
compat:
      s=winsock2errno(socket(AF_INET,SOCK_DGRAM,0));
      noipv6=1;
      if (s==-1) return -1;
    } else
    return -1;
  }
#ifdef IPV6_V6ONLY
  {
    int zero=0;
    winsock2errno(setsockopt(s,IPPROTO_IPV6,IPV6_V6ONLY,(void*)&zero,sizeof(zero)));
  }
#endif
  return s;
#else
  return socket_udp();
#endif
}