86 std::string tunnel_ip;
87 std::vector<uint8_t>
buffer;
99 printf(
"Error opening %s as receiver\n",
rxr_devname);
107 printf(
"Error opening %s as transmitter\n",
txr_devname);
117 printf(
"Usage: agent_tunnel ip_address transmit_device [receive_device]\n");
144 #if defined(COSMOS_LINUX_OS) 149 struct ifreq ifr1, ifr2;
150 struct sockaddr_in *addr = (
struct sockaddr_in *)&ifr2.ifr_addr;
152 if ((
tun_fd=open(
"/dev/net/tun", O_RDWR)) < 0)
154 perror(
"Error opening tunnel device");
158 memset(&ifr1, 0,
sizeof(ifr1));
159 ifr1.ifr_flags = IFF_TUN | IFF_NO_PI;
161 if (ioctl(
tun_fd, TUNSETIFF, (
void *)&ifr1) < 0)
163 perror(
"Error setting tunnel interface");
167 if((tunnel_sock=socket(AF_INET, SOCK_DGRAM, IPPROTO_IP)) < 0)
169 perror(
"Error opening tunnel socket");
175 ifr2.ifr_addr.sa_family = AF_INET;
179 inet_pton(AF_INET, tunnel_ip.c_str(), &addr->sin_addr);
180 if (ioctl(tunnel_sock, SIOCSIFADDR, &ifr2) < 0 )
182 perror(
"Error setting tunnel address");
187 inet_pton(AF_INET, (
char *)
"255.255.255.0", &addr->sin_addr);
188 if (ioctl(tunnel_sock, SIOCSIFNETMASK, &ifr2) < 0 )
190 perror(
"Error setting tunnel netmask");
194 if (ioctl(tunnel_sock, SIOCGIFFLAGS, &ifr2) < 0 )
196 perror(
"Error getting tunnel interface flags");
201 ifr2.ifr_flags |= (IFF_UP | IFF_RUNNING);
202 if (ioctl(tunnel_sock, SIOCSIFFLAGS, &ifr2) < 0 )
204 perror(
"Error setting tunnel interface flags");
210 if (ioctl(tunnel_sock, SIOCSIFMTU, &ifr2) < 0 )
212 perror(
"Error setting tunnel interface MTU");
234 sleept = (int32_t)((nmjd -
currentmjd(0.))*86400000000.);
239 COSMOS_USLEEP(sleept);
241 tun_read_thread.join();
242 port_read_thread.join();
243 tcv_read_thread.join();
244 tun_write_thread.join();
245 tcv_write_thread.join();
char txr_devname[20]
Definition: agent_kpc9612p.cpp:69
kpc9612p_handle rxr_handle
Definition: agent_kpc9612p.cpp:72
int32_t kpc9612p_connect(char *dev, kpc9612p_handle *handle, uint8_t flag)
Definition: kpc9612p_lib.cpp:78
int tun_fd
Definition: agent_kpc9612p.cpp:65
int32_t request_transmit_port(string &req, string &response, Agent *)
Definition: agent_kpc9612p.cpp:465
void tun_read_loop()
Definition: agent_kpc9612p.cpp:250
int i
Definition: rw_test.cpp:37
int iretn
Definition: rw_test.cpp:37
void tcv_write_loop()
Definition: agent_kpc9612p.cpp:416
uint16_t running()
Check if we're supposed to be running.
Definition: agentclass.cpp:391
#define MAXBUFFERSIZE
Definition: agent_kpc9612p.cpp:77
bool open_tunnel
Definition: agent_kpc9612p.cpp:66
static char buffer[255]
Definition: propagator_simple.cpp:60
void port_read_loop()
Definition: agent_kpc9612p.cpp:323
int32_t add_request(string token, external_request_function function, string synopsis="", string description="")
Add internal request to Agent request list with description and synopsis.
Definition: agentclass.cpp:312
void tcv_read_loop()
Definition: agent_kpc9612p.cpp:358
Definition: agentclass.h:139
Agent * agent
Definition: agent_kpc9612p.cpp:49
cssl_t * serial
Definition: kpc9612p_lib.h:90
double currentmjd(double offset)
Current UTC in Modified Julian Days.
Definition: timelib.cpp:65
void tun_write_loop()
Definition: agent_kpc9612p.cpp:277
vector< agentstruc > agent
Single entry vector for agent information.
Definition: jsondef.h:4247
char rxr_devname[20]
Definition: agent_kpc9612p.cpp:68
cosmosstruc * cinfo
Definition: agentclass.h:346
#define KPC9612P_MTU
Definition: kpc9612p_lib.h:49
#define AGENT_ERROR_JSON_CREATE
Definition: cosmos-errno.h:105
kpc9612p_handle txr_handle
Definition: agent_kpc9612p.cpp:73