Skip to content
This repository was archived by the owner on May 5, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions src/port_data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void port__data::set_parameter(const char *name, const char *value)
D("%s=%s", name, value);

if (IS_PARAM("src_ip", name)) {
dst_port = inet_addr(value);
src_ip = inet_addr(value);
goto out;
}

Expand Down Expand Up @@ -120,8 +120,8 @@ void port__data::Event_Handler(const fd_set *fds_read,
const fd_set */*error_fds*/,
double /*time_since_last_call*/)
{
if (FD_ISSET(fd, fds_read))
Handle_Fd_Event_Readable(fd);
if (FD_ISSET(fd_r, fds_read))
Handle_Fd_Event_Readable(fd_r);
}

#define S_IN_SIZE sizeof(struct sockaddr_in)
Expand All @@ -141,20 +141,23 @@ void port__data::user_map(const char *system_port)
{
D("system_port: %s", system_port);

if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
E("socket");
if ((fd_w = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
E("write socket");

if (bind(fd, s_in(src_ip, src_port), S_IN_SIZE) == -1)
if ((fd_r = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
E("read socket");

if (bind(fd_r, s_in(src_ip, src_port), S_IN_SIZE) == -1)
E("bind");

if (connect(fd, s_in(dst_ip, dst_port), S_IN_SIZE) == -1)
if (connect(fd_w, s_in(dst_ip, dst_port), S_IN_SIZE) == -1)
E("connect");

{
fd_set fds_read;

FD_ZERO(&fds_read);
FD_SET(fd, &fds_read);
FD_SET(fd_r, &fds_read);

Install_Handler(&fds_read, NULL, NULL, 0);
}
Expand All @@ -163,7 +166,8 @@ void port__data::user_map(const char *system_port)
void port__data::user_unmap(const char * /*system_port*/)
{
Uninstall_Handler();
close(fd);
close(fd_w);
close(fd_r);
}

int32_t _cs(void *data, size_t data_len)
Expand Down Expand Up @@ -304,7 +308,7 @@ void port__data::outgoing_send(const OCTETSTRING& msg)

inet6_chksum(buf, data_len);

if (write(fd, buf, data_len) < data_len)
if (write(fd_w, buf, data_len) < data_len)
E("write");
}

Expand Down
3 changes: 2 additions & 1 deletion src/port_data.hh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ public:
const fd_set *error_fds,
double time_since_last_call);
private:
int fd;
int fd_r;
int fd_w;
int debug;
uint32_t src_ip;
uint16_t src_port;
Expand Down