Exemplo n.º 1
0
int
socket_tcp6b(void) {
#ifdef LIBC_HAS_IP6
  int s;

#if WINDOWS_NATIVE
  __winsock_init();
#endif

  if(noipv6)
    goto compat;
  s = winsock2errno(socket(PF_INET6, SOCK_STREAM, 0));
  if(s == -1) {
    if(errno == EINVAL || errno == EAFNOSUPPORT || errno == EPFNOSUPPORT || errno == EPROTONOSUPPORT) {
    compat:
      s = winsock2errno(socket(AF_INET, SOCK_STREAM, 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_tcp4b();
#endif
}
Exemplo n.º 2
0
int socket_udp4(void) {
  int s;
  __winsock_init();
  s = winsock2errno(socket(PF_INET,SOCK_DGRAM,IPPROTO_UDP));
  if (s == -1) return -1;
  if (ndelay_on(s) == -1) { close(s); return -1; }
  return s;
}
Exemplo n.º 3
0
int io_socketpair(int64* d) {
    int fds[2];
    __winsock_init();
    if (socketpair(AF_UNIX,SOCK_STREAM,0,fds)==-1)
        if (socketpair(AF_INET6,SOCK_STREAM,IPPROTO_TCP,fds)==-1)
            if (socketpair(AF_INET,SOCK_STREAM,IPPROTO_TCP,fds)==-1)
                return 0;
    if (io_fd(fds[1]) && io_fd(fds[0])) {
        d[0]=fds[0];
        d[1]=fds[1];
        return 1;
    }
    io_close(fds[1]);
    io_close(fds[0]);
    return 0;
}
Exemplo n.º 4
0
PRIVATE socket_t *socket_udp6(uint32_t scope_id)
{
    socket_t *s = socket_new6(scope_id);
    if (s == NULL) {
        return NULL;
    }
#if defined(HAVE_LIBC_IPV6)
    __winsock_init();
    if (ip6disabled) {
        goto compat;
    }
    s->fd = __winsock_errno(socket(PF_INET6, SOCK_DGRAM, IPPROTO_UDP));
    if (s->fd == -1) {
        if (errno == EINVAL ||
            errno == EAFNOSUPPORT ||
            errno == EPFNOSUPPORT ||
            errno == EPROTONOSUPPORT) {
compat:
            s->fd = __winsock_errno(socket(AF_INET, SOCK_DGRAM, 0));
            ip6disabled = true;
            if (s->fd == -1) {
                socket_free(s);
                return NULL;
            }
        }
        if (s->fd == -1) {
            socket_free(s);
            return NULL;
        }
        return s;
    }
#if defined(IPV6_V6ONLY)
    int zero = 0;
    __winsock_errno(setsockopt(s->fd, IPPROTO_IPV6, IPV6_V6ONLY, (void *)&zero, sizeof(zero)));
#endif
    if (socket_nodelay(s->fd) == -1) {
        close(s->fd);
        socket_free(s);
        return NULL;
    }
    return s;
#else // HAVE_LIBC_IPV6
    return s;
#endif
}
Exemplo n.º 5
0
PRIVATE socket_t *socket_udp4(void)
{
    socket_t *s = socket_new4();
    if (s == NULL) {
        errno = EINVAL;
        return NULL;
    }
    __winsock_init();
    s->fd = __winsock_errno(socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP));
    if (s->fd == -1) {
        socket_free(s);
        return NULL;
    }
    if (socket_nodelay(s->fd) == -1) {
        close(s->fd);
        socket_free(s);
        return NULL;
    }
    return s;
}