73 #if defined(COSMOS_LINUX_OS) 90 if (tloc != string::npos)
101 if (tloc != string::npos)
120 strcpy(tunnel_ip,argv[1]);
124 printf(
"Usage: agent_tunnel ip_address transmit_device [receive_device]\n");
147 struct ifreq ifr1, ifr2;
148 struct sockaddr_in *addr = (
struct sockaddr_in *)&ifr2.ifr_addr;
150 if ((
tun_fd=open(
"/dev/net/tun", O_RDWR)) < 0)
152 perror(
"Error opening tunnel device");
156 memset(&ifr1, 0,
sizeof(ifr1));
157 ifr1.ifr_flags = IFF_TUN | IFF_NO_PI;
159 if (ioctl(
tun_fd, TUNSETIFF, static_cast<void *>(&ifr1)) < 0)
161 perror(
"Error setting tunnel interface");
165 if((tunnel_sock=socket(AF_INET, SOCK_DGRAM, IPPROTO_IP)) < 0)
167 perror(
"Error opening tunnel socket");
173 ifr2.ifr_addr.sa_family = AF_INET;
177 inet_pton(AF_INET, tunnel_ip, &addr->sin_addr);
178 if (ioctl(tunnel_sock, SIOCSIFADDR, &ifr2) < 0 )
180 perror(
"Error setting tunnel address");
185 inet_pton(AF_INET, static_cast<const char *>(
"255.255.255.0"), &addr->sin_addr);
186 if (ioctl(tunnel_sock, SIOCSIFNETMASK, &ifr2) < 0 )
188 perror(
"Error setting tunnel netmask");
192 if (ioctl(tunnel_sock, SIOCGIFFLAGS, &ifr2) < 0 )
194 perror(
"Error getting tunnel interface flags");
199 ifr2.ifr_flags |= (IFF_UP | IFF_RUNNING);
200 if (ioctl(tunnel_sock, SIOCSIFFLAGS, &ifr2) < 0 )
202 perror(
"Error setting tunnel interface flags");
208 if (ioctl(tunnel_sock, SIOCSIFMTU, &ifr2) < 0 )
210 perror(
"Error setting tunnel interface MTU");
230 sleept = (int32_t)((nmjd -
currentmjd(0.))*86400000000.);
235 COSMOS_USLEEP(sleept);
static uint32_t txr_baud
Definition: agent_tunnel2.cpp:66
FILE * get_debug_fd(double mjd=0.)
Definition: agentclass.cpp:2645
void tun_write_loop()
Definition: agent_kpc9612p.cpp:277
string getNode()
Listen for heartbeat.
Definition: agentclass.cpp:2607
Definition: serialclass.h:43
static Serial * rxr_serial
Definition: agent_tunnel2.cpp:63
int iretn
Definition: rw_test.cpp:37
int32_t wait(State state=State::RUN, double waitsec=10.)
Definition: agentclass.cpp:398
void tun_read_loop()
Definition: agent_kpc9612p.cpp:250
static uint16_t tun_mtu
Definition: agent_tunnel2.cpp:57
string cosmos_error_string(int32_t cosmos_errno)
Definition: cosmos-errno.cpp:45
uint16_t running()
Check if we're supposed to be running.
Definition: agentclass.cpp:391
static string rxr_devname
Definition: agent_tunnel2.cpp:61
static int tun_fd
Definition: agent_tunnel2.cpp:56
static char buffer[255]
Definition: propagator_simple.cpp:60
string getAgent()
Definition: agentclass.cpp:2609
Definition: agentclass.h:139
static uint32_t rxr_baud
Definition: agent_tunnel2.cpp:65
static Agent * agent
Definition: agent_tunnel2.cpp:43
double data_ctime(string path)
Definition: datalib.cpp:1910
double currentmjd(double offset)
Current UTC in Modified Julian Days.
Definition: timelib.cpp:65
static Serial * txr_serial
Definition: agent_tunnel2.cpp:64
string utc2iso8601(double utc)
ISO 8601 version of time.
Definition: timelib.cpp:1286
void tcv_write_loop()
Definition: agent_kpc9612p.cpp:416
vector< agentstruc > agent
Single entry vector for agent information.
Definition: jsondef.h:4247
static string txr_devname
Definition: agent_tunnel2.cpp:62
cosmosstruc * cinfo
Definition: agentclass.h:346
#define MAXBUFFERSIZE
Definition: agent_tunnel2.cpp:68
string mjd2iso8601(double mjd)
Definition: timelib.cpp:1316
void tcv_read_loop()
Definition: agent_kpc9612p.cpp:358