Commit 96f9d585 authored by Grigorii Demidov's avatar Grigorii Demidov

swrap: broadcasting were added

parent 6365ebb0
......@@ -79,6 +79,7 @@
#ifdef HAVE_RPC_RPC_H
#include <rpc/rpc.h>
#endif
#include <dirent.h>
enum swrap_dbglvl_e {
SWRAP_LOG_ERROR = 0,
......@@ -4447,11 +4448,16 @@ static ssize_t swrap_sendto(int s, const void *buf, size_t len, int flags,
len = msg.msg_iov[0].iov_len;
if (bcast) {
struct stat st;
unsigned int iface;
unsigned int prt = ntohs(((const struct sockaddr_in *)(const void *)to)->sin_port);
/* struct stat st;
unsigned int iface; */
unsigned int prt = ntohs(((const struct sockaddr_in *)(const void *)to)->sin_port);
unsigned int remote_prt;
unsigned int in4_addr;
char type;
DIR *d;
struct dirent *dir;
/*
type = SOCKET_TYPE_CHAR_UDP;
for(iface=0; iface <= MAX_WRAPPED_INTERFACES; iface++) {
......@@ -4461,7 +4467,7 @@ static ssize_t swrap_sendto(int s, const void *buf, size_t len, int flags,
socket_wrapper_dir(), type, iface, prt);
if (stat(un_addr.sa.un.sun_path, &st) != 0) continue;
/* ignore the any errors in broadcast sends */
/ * ignore the any errors in broadcast sends * /
libc_sendto(s,
buf,
len,
......@@ -4469,6 +4475,30 @@ static ssize_t swrap_sendto(int s, const void *buf, size_t len, int flags,
&un_addr.sa.s,
un_addr.sa_socklen);
}
*/
d = opendir(socket_wrapper_dir());
if (d) {
while ((dir = readdir(d)) != NULL) {
if (dir->d_name[0] == SOCKET_TYPE_CHAR_UDP_LONG)
/* TODO - use S_ISSOCK ? */
if (sscanf(dir->d_name, SOCKET_FORMAT_LONG, &type, &in4_addr, &remote_prt) == 3)
if (prt == remote_prt) {
snprintf(un_addr.sa.un.sun_path,
sizeof(un_addr.sa.un.sun_path),
"%s/%s",
socket_wrapper_dir(),dir->d_name);
libc_sendto(s,
buf,
len,
flags,
&un_addr.sa.s,
un_addr.sa_socklen);
SWRAP_LOG(SWRAP_LOG_DEBUG,"send bcast packet to %s", dir->d_name);
}
}
closedir(d);
}
swrap_pcap_dump_packet(si, to, SWRAP_SENDTO, buf, len);
......@@ -4892,8 +4922,8 @@ static ssize_t swrap_sendmsg(int s, const struct msghdr *omsg, int flags)
}
if (bcast) {
struct stat st;
unsigned int iface;
// struct stat st;
// unsigned int iface;
unsigned int prt = ntohs(((const struct sockaddr_in *)(const void *)to)->sin_port);
char type;
size_t i, len = 0;
......@@ -4902,6 +4932,12 @@ static ssize_t swrap_sendmsg(int s, const struct msghdr *omsg, int flags)
size_t avail = 0;
size_t remain;
unsigned int remote_prt;
unsigned int in4_addr;
DIR *d;
struct dirent *dir;
for (i = 0; i < (size_t)msg.msg_iovlen; i++) {
avail += msg.msg_iov[i].iov_len;
}
......@@ -4923,7 +4959,8 @@ static ssize_t swrap_sendmsg(int s, const struct msghdr *omsg, int flags)
ofs += this_time;
remain -= this_time;
}
/*
type = SOCKET_TYPE_CHAR_UDP;
for(iface=0; iface <= MAX_WRAPPED_INTERFACES; iface++) {
......@@ -4931,12 +4968,32 @@ static ssize_t swrap_sendmsg(int s, const struct msghdr *omsg, int flags)
socket_wrapper_dir(), type, iface, prt);
if (stat(un_addr.sun_path, &st) != 0) continue;
msg.msg_name = &un_addr; /* optional address */
msg.msg_namelen = sizeof(un_addr); /* size of address */
msg.msg_name = &un_addr; / * optional address * /
msg.msg_namelen = sizeof(un_addr); / * size of address * /
/* ignore the any errors in broadcast sends */
/ * ignore the any errors in broadcast sends * /
libc_sendmsg(s, &msg, flags);
}
*/
d = opendir(socket_wrapper_dir());
if (d) {
while ((dir = readdir(d)) != NULL) {
if (dir->d_name[0] == SOCKET_TYPE_CHAR_UDP_LONG)
/* TODO - use S_ISSOCK ? */
if (sscanf(dir->d_name, SOCKET_FORMAT_LONG, &type, &in4_addr, &remote_prt) == 3)
if (prt == remote_prt) {
snprintf(un_addr.sun_path,
sizeof(un_addr.sun_path),
"%s/%s",
socket_wrapper_dir(),dir->d_name);
libc_sendmsg(s, &msg, flags);
SWRAP_LOG(SWRAP_LOG_DEBUG,"send bcast packet to %s", dir->d_name);
}
}
closedir(d);
}
swrap_pcap_dump_packet(si, to, SWRAP_SENDTO, buf, len);
free(buf);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment