You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.1 KiB
C

24 years ago
#include <sys/types.h>
#include <sys/param.h>
#ifndef __MINGW32__
24 years ago
#include <sys/socket.h>
#include <netinet/in.h>
#endif
#include "windoze.h"
24 years ago
#include <errno.h>
#include "byte.h"
#include "socket.h"
#include "ip6.h"
#include "haveip6.h"
#include "ip4.h"
#include "havescope.h"
24 years ago
ssize_t socket_send6(int s,const char *buf,size_t len,const char ip[16],uint16 port,uint32 scope_id)
24 years ago
{
#ifdef LIBC_HAS_IP6
struct sockaddr_in6 si;
#else
struct sockaddr_in si;
#endif
byte_zero(&si,sizeof si);
#ifdef LIBC_HAS_IP6
if (noipv6) {
#endif
if (ip6_isv4mapped(ip))
return socket_send4(s,buf,len,ip+12,port);
if (byte_equal(ip,16,V6loopback))
return socket_send4(s,buf,len,ip4loopback,port);
#ifdef LIBC_HAS_IP6
errno=EPROTONOSUPPORT;
24 years ago
return -1;
}
si.sin6_family = AF_INET6;
uint16_pack_big((char *) &si.sin6_port,port);
byte_copy((char *) &si.sin6_addr,16,ip);
#ifdef LIBC_HAS_SCOPE_ID
si.sin6_scope_id=scope_id;
#else
si.sin6_scope_id=0;
#endif
return winsock2errno(sendto(s,buf,len,0,(void*) &si,sizeof si));
24 years ago
#else
errno=EPROTONOSUPPORT;
24 years ago
return -1;
#endif
}