libowfat/socket/socket_connect6.c

45 lines
1004 B
C
Raw Normal View History

2001-02-02 17:54:47 +00:00
#include <sys/param.h>
2001-02-04 01:28:45 +00:00
#include <sys/types.h>
#ifndef __MINGW32__
2001-02-04 01:28:45 +00:00
#include <sys/socket.h>
#include <netinet/in.h>
#endif
#include "windoze.h"
2001-02-04 01:28:45 +00:00
#include <errno.h>
2001-02-02 17:54:47 +00:00
#include "byte.h"
#include "socket.h"
#include "ip6.h"
#include "haveip6.h"
#include "uint32.h"
2001-02-05 22:03:11 +00:00
#include "ip4.h"
#include "havescope.h"
2001-02-02 17:54:47 +00:00
int socket_connect6(int s,const char ip[16],uint16 port,uint32 scope_id)
{
#ifdef LIBC_HAS_IP6
struct sockaddr_in6 sa;
if (noipv6) {
#endif
if (ip6_isv4mapped(ip))
return winsock2errno(socket_connect4(s,ip+12,port));
2001-02-02 17:54:47 +00:00
if (byte_equal(ip,16,V6loopback))
return winsock2errno(socket_connect4(s,ip4loopback,port));
2001-02-02 17:54:47 +00:00
#ifdef LIBC_HAS_IP6
}
byte_zero(&sa,sizeof sa);
sa.sin6_family = PF_INET6;
uint16_pack_big((char *) &sa.sin6_port,port);
sa.sin6_flowinfo = 0;
#ifdef LIBC_HAS_SCOPE_ID
2001-02-02 17:54:47 +00:00
sa.sin6_scope_id = scope_id;
#endif
2001-02-02 17:54:47 +00:00
byte_copy((char *) &sa.sin6_addr,16,ip);
return winsock2errno(connect(s,(void*) &sa,sizeof sa));
2001-02-02 17:54:47 +00:00
#else
2001-10-15 14:34:02 +00:00
errno=EPROTONOSUPPORT;
2001-02-02 17:54:47 +00:00
return -1;
#endif
}