Commit cfa172a0 authored by Pavel Tvrdík's avatar Pavel Tvrdík Committed by Pavel Tvrdik

fdlhdkajsfkfdsa

parent e9380e31
CC=cc
CFLAGS=-Wall -g
CFLAGS=-Wall -gdwarf-4 -g3 -ggdb -O0
LDFLAGS=
UNAME_S := $(shell uname -s)
......
......@@ -133,6 +133,9 @@ init_bind(int fd, inetaddr addr, int port)
if (bind(fd, (struct sockaddr *) &lsa, sizeof(lsa)) < 0)
ERR("bind()");
char buf[60];
printf("bind() %s:%d \n", inet_ntop(lsa.SA(family), (void *) &lsa.SA_ADDR, buf, sizeof(buf)), port);
}
void
......
......@@ -89,7 +89,7 @@ static inline int get_recv_ttl(void)
extern int cf_type;
void
prepare_tx_cmsgs(int fd, int cf_ifindex, struct msghdr *msg, void *buf, int blen, struct in_addr laddr)
prepare_tx_cmsgs(int fd, int UNUSED, inetaddr saddr, struct msghdr *msg, void *buf, int blen, struct in_addr laddr)
{
#ifdef RAW_USE_HDR
if (cf_type == SK_IP)
......@@ -98,7 +98,8 @@ prepare_tx_cmsgs(int fd, int cf_ifindex, struct msghdr *msg, void *buf, int blen
#ifdef IP_SENDSRCADDR
struct cmsghdr *cm;
struct in_addr *sa;
inetaddr *sa;
int controllen = 0;
msg->msg_control = buf;
msg->msg_controllen = blen;
......@@ -107,12 +108,32 @@ prepare_tx_cmsgs(int fd, int cf_ifindex, struct msghdr *msg, void *buf, int blen
cm->cmsg_level = IPPROTO_IP;
cm->cmsg_type = IP_SENDSRCADDR;
cm->cmsg_len = CMSG_LEN(sizeof(*sa));
controllen += CMSG_SPACE(sizeof(*sa));
sa = (struct in_addr *) CMSG_DATA(cm);
*sa = laddr;
sa = (inetaddr *) CMSG_DATA(cm);
sa->s_addr = htonl(saddr.s_addr);
msg->msg_controllen = cm->cmsg_len;
msg->msg_controllen = controllen;
#endif
// #ifdef IP_SENDSRCADDR
// struct cmsghdr *cm;
// struct in_addr *sa;
//
// msg->msg_control = buf;
// msg->msg_controllen = blen;
//
// cm = CMSG_FIRSTHDR(msg);
// cm->cmsg_level = IPPROTO_IP;
// cm->cmsg_type = IP_SENDSRCADDR;
// cm->cmsg_len = CMSG_LEN(sizeof(*sa));
//
// sa = (struct in_addr *) CMSG_DATA(cm);
// *sa = laddr;
//
// msg->msg_controllen = cm->cmsg_len;
// #endif
}
void
......
......@@ -64,7 +64,7 @@ static inline int get_recv_ttl(void)
void
prepare_tx_cmsgs(int fd, int cf_ifindex, struct msghdr *msg, void *buf, int blen, struct in_addr laddr)
prepare_tx_cmsgs(int fd, int ifa_idx, inetaddr UNUSED, struct msghdr *msg, void *buf, int blen, struct in_addr laddr)
{
struct cmsghdr *cm;
struct in_pktinfo *pi;
......@@ -78,7 +78,7 @@ prepare_tx_cmsgs(int fd, int cf_ifindex, struct msghdr *msg, void *buf, int blen
cm->cmsg_len = CMSG_LEN(sizeof(*pi));
pi = (struct in_pktinfo *) CMSG_DATA(cm);
pi->ipi_ifindex = cf_ifindex;
pi->ipi_ifindex = ifa_idx;
pi->ipi_spec_dst = laddr;
pi->ipi_addr = INET_ANY;
......
......@@ -58,7 +58,7 @@ static inline int get_recv_ttl(void)
void
prepare_tx_cmsgs(int fd, int cf_ifindex, struct msghdr *msg, void *buf, int blen, struct in6_addr laddr)
prepare_tx_cmsgs(int fd, int cf_ifindex, inetaddr UNUSED, struct msghdr *msg, void *buf, int blen, struct in6_addr laddr)
{
struct cmsghdr *cm;
struct in6_pktinfo *pi;
......
......@@ -5,6 +5,8 @@ do_sendmsg(int fd, inetaddr saddr, inetaddr daddr, int dport, void *buf, size_t
{
sockaddr dst = { SA_BASE, .SA_ADDR = daddr, .SA_PORT = dport };
unsigned char cmsg_buf[256];
memset(cmsg_buf, '\0', sizeof(cmsg_buf));
struct iovec iov = {buf, len};
struct msghdr msg = {
.msg_name = (struct sockaddr *) &dst,
......@@ -15,6 +17,8 @@ do_sendmsg(int fd, inetaddr saddr, inetaddr daddr, int dport, void *buf, size_t
#ifdef RAW_USE_HDR
unsigned char hdr[20];
memset(hdr, '\0', sizeof(hdr));
struct iovec iov2[2] = { {hdr, sizeof(hdr)}, {buf, len} };
if (cf_type == SK_IP)
......@@ -25,9 +29,9 @@ do_sendmsg(int fd, inetaddr saddr, inetaddr daddr, int dport, void *buf, size_t
}
#endif
prepare_tx_cmsgs(fd, cf_ifindex, &msg, cmsg_buf, sizeof(cmsg_buf), saddr);
prepare_tx_cmsgs(fd, cf_ifindex, saddr, &msg, cmsg_buf, sizeof(cmsg_buf), saddr);
return sendmsg(fd, &msg, 0);
return sendmsg(fd, &msg, cf_route ? 0 : MSG_DONTROUTE);
}
int
......@@ -46,13 +50,14 @@ main(int argc, char **argv)
else if (cf_type == SK_UDP)
{
type = SOCK_DGRAM;
proto = IPPROTO_UDP;
// proto = IPPROTO_UDP;
proto = 0;
port = htons(cf_port);
}
else
ERR("unrecognized socket type");
fd = socket(PF_IP, type, proto);
fd = socket(AF_IP, type, proto);
if (fd < 0)
ERR("socket()");
......
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