Commit 0670a4b8 authored by Pavel Tvrdik's avatar Pavel Tvrdik

Revert "fdlhdkajsfkfdsa"

This reverts commit cfa172a0.
parent cfa172a0
CC=cc
CFLAGS=-Wall -gdwarf-4 -g3 -ggdb -O0
CFLAGS=-Wall -g
LDFLAGS=
UNAME_S := $(shell uname -s)
......
......@@ -133,9 +133,6 @@ 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 UNUSED, inetaddr saddr, struct msghdr *msg, void *buf, int blen, struct in_addr laddr)
prepare_tx_cmsgs(int fd, int cf_ifindex, struct msghdr *msg, void *buf, int blen, struct in_addr laddr)
{
#ifdef RAW_USE_HDR
if (cf_type == SK_IP)
......@@ -98,8 +98,7 @@ prepare_tx_cmsgs(int fd, int UNUSED, inetaddr saddr, struct msghdr *msg, void *b
#ifdef IP_SENDSRCADDR
struct cmsghdr *cm;
inetaddr *sa;
int controllen = 0;
struct in_addr *sa;
msg->msg_control = buf;
msg->msg_controllen = blen;
......@@ -108,32 +107,12 @@ prepare_tx_cmsgs(int fd, int UNUSED, inetaddr saddr, struct msghdr *msg, void *b
cm->cmsg_level = IPPROTO_IP;
cm->cmsg_type = IP_SENDSRCADDR;
cm->cmsg_len = CMSG_LEN(sizeof(*sa));
controllen += CMSG_SPACE(sizeof(*sa));
sa = (inetaddr *) CMSG_DATA(cm);
sa->s_addr = htonl(saddr.s_addr);
sa = (struct in_addr *) CMSG_DATA(cm);
*sa = laddr;
msg->msg_controllen = controllen;
msg->msg_controllen = cm->cmsg_len;
#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 ifa_idx, inetaddr UNUSED, struct msghdr *msg, void *buf, int blen, struct in_addr laddr)
prepare_tx_cmsgs(int fd, int cf_ifindex, 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 ifa_idx, inetaddr UNUSED, struct msghdr *msg, void
cm->cmsg_len = CMSG_LEN(sizeof(*pi));
pi = (struct in_pktinfo *) CMSG_DATA(cm);
pi->ipi_ifindex = ifa_idx;
pi->ipi_ifindex = cf_ifindex;
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, inetaddr UNUSED, struct msghdr *msg, void *buf, int blen, struct in6_addr laddr)
prepare_tx_cmsgs(int fd, int cf_ifindex, struct msghdr *msg, void *buf, int blen, struct in6_addr laddr)
{
struct cmsghdr *cm;
struct in6_pktinfo *pi;
......
......@@ -5,8 +5,6 @@ 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,
......@@ -17,8 +15,6 @@ 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)
......@@ -29,9 +25,9 @@ do_sendmsg(int fd, inetaddr saddr, inetaddr daddr, int dport, void *buf, size_t
}
#endif
prepare_tx_cmsgs(fd, cf_ifindex, saddr, &msg, cmsg_buf, sizeof(cmsg_buf), saddr);
prepare_tx_cmsgs(fd, cf_ifindex, &msg, cmsg_buf, sizeof(cmsg_buf), saddr);
return sendmsg(fd, &msg, cf_route ? 0 : MSG_DONTROUTE);
return sendmsg(fd, &msg, 0);
}
int
......@@ -50,14 +46,13 @@ main(int argc, char **argv)
else if (cf_type == SK_UDP)
{
type = SOCK_DGRAM;
// proto = IPPROTO_UDP;
proto = 0;
proto = IPPROTO_UDP;
port = htons(cf_port);
}
else
ERR("unrecognized socket type");
fd = socket(AF_IP, type, proto);
fd = socket(PF_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