fehQlibs 26
Qlibs
Loading...
Searching...
No Matches
socket_send.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_send4(int s,const char *buf,unsigned int len,const char ip[4],uint16 port)
17{
18 struct sockaddr_in sa;
19
20 byte_zero(&sa,sizeof(sa));
21
22 sa.sin_family = AF_INET;
23 uint16_pack_big((char *)&sa.sin_port,port);
24 byte_copy((char *)&sa.sin_addr,4,ip);
25
26 return sendto(s,buf,len,0,(struct sockaddr *)&sa,sizeof(sa));
27}
28
29int socket_send6(int s,const char *buf,unsigned int len,const char ip[16],uint16 port,uint32 scope_id)
30{
31 struct sockaddr_in6 sa;
32
33 byte_zero(&sa,sizeof(sa));
34
35 sa.sin6_family = AF_INET6;
36 sa.sin6_scope_id = scope_id;
37 uint16_pack_big((char *)&sa.sin6_port,port);
38 byte_copy((char *)&sa.sin6_addr,16,ip);
39
40 return sendto(s,buf,len,0,(struct sockaddr *)&sa,sizeof(sa));
41}
42
43int socket_send(int s,const char *buf,unsigned int len,const char ip[16],uint16 port,uint32 scope_id)
44{
45 if (ip6_isv4mapped(ip))
46 return socket_send4(s,buf,len,ip + 12,port);
47 else
48 return socket_send6(s,buf,len,ip,port,scope_id);
49}
50
51int socket_broadcast4(int s,const char *buf,unsigned int len,uint16 port)
52{
53 struct sockaddr_in sa;
54
55 byte_zero(&sa,sizeof(sa));
56
57 sa.sin_family = AF_INET;
58 uint16_pack_big((char *)&sa.sin_port,port);
59 byte_copy((char *)&sa.sin_addr,4,V4broadcast);
60
61 return sendto(s,buf,len,0,(struct sockaddr *)&sa,sizeof(sa));
62}
int socket_send6(int s, const char *buf, unsigned int len, const char ip[16], uint16 port, uint32 scope_id)
Definition: socket_send.c:29
int socket_send4(int s, const char *buf, unsigned int len, const char ip[4], uint16 port)
Definition: socket_send.c:16
int socket_broadcast4(int s, const char *buf, unsigned int len, uint16 port)
Definition: socket_send.c:51
int socket_send(int s, const char *buf, unsigned int len, const char ip[16], uint16 port, uint32 scope_id)
Definition: socket_send.c:43
void uint16_pack_big(char[16], uint16)
uint16_t uint16
Definition: uint_t.h:29
uint32_t uint32
Definition: uint_t.h:40
#define ip6_isv4mapped(ip)
Definition: ip.h:105
void byte_copy(void *, unsigned int, const void *)
Definition: byte.c:20
void byte_zero(void *, unsigned int)
Definition: byte.c:65