fehQlibs 26
Qlibs
Loading...
Searching...
No Matches
socket_recv.c
Go to the documentation of this file.
1#include <sys/types.h>
2#include <sys/param.h>
3#include <sys/socket.h>
4#include <netinet/in.h>
5#include "byte.h"
6#include "ip.h"
7#include "socket_if.h"
8
16int socket_recv(int s,char *buf,unsigned int len,char ip[16],uint16 *port,uint32 *scope_id)
17{
18 struct sockaddr_in6 sa;
19 unsigned int dummy = sizeof(sa);
20 int r;
21
22 byte_zero(&sa,dummy);
23 r = recvfrom(s,buf,len,0,(struct sockaddr *)&sa,&dummy);
24 if (r == -1) return -1;
25
26 if (sa.sin6_family == AF_INET) {
27 struct sockaddr_in *sa4 = (struct sockaddr_in *)&sa;
29 byte_copy(ip + 12,4,(char *)&sa4->sin_addr);
30 uint16_unpack_big((char *)&sa4->sin_port,port);
31 if (scope_id) *scope_id = 0;
32 } else {
33 byte_copy(ip,16,(char *)&sa.sin6_addr);
34 uint16_unpack_big((char *)&sa.sin6_port,port);
35 if (scope_id) *scope_id = sa.sin6_scope_id;
36 }
37
38 return r;
39}
const unsigned char V4mappedprefix[12]
Definition: socket_if.c:18
int socket_recv(int s, char *buf, unsigned int len, char ip[16], uint16 *port, uint32 *scope_id)
Definition: socket_recv.c:16
uint16_t uint16
Definition: uint_t.h:29
uint32_t uint32
Definition: uint_t.h:40
void uint16_unpack_big(char[16], uint16 *)
void byte_copy(void *, unsigned int, const void *)
Definition: byte.c:20
void byte_zero(void *, unsigned int)
Definition: byte.c:65