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.

47 lines
1.1 KiB

#include <sys/param.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include "byte.h"
#include "socket.h"
#include "ip6.h"
#include "haveip6.h"
#include "havesl.h"
int socket_recv6(int s,char *buf,unsigned int len,char ip[16],uint16 *port,uint32 *scope_id)
#ifdef LIBC_HAS_IP6
struct sockaddr_in6 si;
struct sockaddr_in si;
socklen_t Len = sizeof si;
int r;
if ((r = recvfrom(s,buf,len,0,(struct sockaddr *) &si,&Len))<0) return -1;
#ifdef LIBC_HAS_IP6
if (noipv6) {
struct sockaddr_in *si4=(struct sockaddr_in *)&si;
if (ip) {
byte_copy(ip+12,4,(char *) &si4->sin_addr);
if (port) uint16_unpack_big((char *) &si4->sin_port,port);
return r;
if (ip) byte_copy(ip,16,(char *) &si.sin6_addr);
if (port) uint16_unpack_big((char *) &si.sin6_port,port);
if (scope_id) *scope_id=si.sin6_scope_id;
if (ip) {
byte_copy(ip,12,(char *)V4mappedprefix);
byte_copy(ip+12,4,(char *) &si.sin_addr);
if (port) uint16_unpack_big((char *) &si.sin_port,port);
if (scope_id) *scope_id=0;
return r;