70 #if defined(COSMOS_LINUX_OS) 82 if (tloc != string::npos)
99 if (tloc != string::npos)
116 strcpy(tunnel_ip,argv[1]);
120 printf(
"Usage: agent_tunnel ip_address transmit_device [receive_device]\n");
143 struct ifreq ifr1, ifr2;
144 struct sockaddr_in *addr = (
struct sockaddr_in *)&ifr2.ifr_addr;
146 if ((
tun_fd=open(
"/dev/net/tun", O_RDWR)) < 0)
148 perror(
"Error opening tunnel device");
152 memset(&ifr1, 0,
sizeof(ifr1));
153 ifr1.ifr_flags = IFF_TUN | IFF_NO_PI;
155 if (ioctl(
tun_fd, TUNSETIFF, static_cast<void *>(&ifr1)) < 0)
157 perror(
"Error setting tunnel interface");
161 if((tunnel_sock=socket(AF_INET, SOCK_DGRAM, IPPROTO_IP)) < 0)
163 perror(
"Error opening tunnel socket");
169 ifr2.ifr_addr.sa_family = AF_INET;
173 inet_pton(AF_INET, tunnel_ip, &addr->sin_addr);
174 if (ioctl(tunnel_sock, SIOCSIFADDR, &ifr2) < 0 )
176 perror(
"Error setting tunnel address");
181 inet_pton(AF_INET, static_cast<const char *>(
"255.255.255.0"), &addr->sin_addr);
182 if (ioctl(tunnel_sock, SIOCSIFNETMASK, &ifr2) < 0 )
184 perror(
"Error setting tunnel netmask");
188 if (ioctl(tunnel_sock, SIOCGIFFLAGS, &ifr2) < 0 )
190 perror(
"Error getting tunnel interface flags");
195 ifr2.ifr_flags |= (IFF_UP | IFF_RUNNING);
196 if (ioctl(tunnel_sock, SIOCSIFFLAGS, &ifr2) < 0 )
198 perror(
"Error setting tunnel interface flags");
204 if (ioctl(tunnel_sock, SIOCSIFMTU, &ifr2) < 0 )
206 perror(
"Error setting tunnel interface MTU");
226 sleept = (int32_t)((nmjd -
currentmjd(0.))*86400000000.);
231 COSMOS_USLEEP(sleept);
FILE * get_debug_fd(double mjd=0.)
Definition: agentclass.cpp:2645
string getNode()
Listen for heartbeat.
Definition: agentclass.cpp:2607
static uint32_t txr_baud
Definition: agent_tunnel.cpp:63
Definition: serialclass.h:43
int iretn
Definition: rw_test.cpp:37
#define MAXBUFFERSIZE
Definition: agent_tunnel.cpp:65
int32_t wait(State state=State::RUN, double waitsec=10.)
Definition: agentclass.cpp:398
static string txr_devname
Definition: agent_tunnel.cpp:59
static int tun_fd
Definition: agent_tunnel.cpp:56
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
void tun_write_loop()
Definition: agent_kpc9612p.cpp:277
static string rxr_devname
Definition: agent_tunnel.cpp:58
static char buffer[255]
Definition: propagator_simple.cpp:60
string getAgent()
Definition: agentclass.cpp:2609
Definition: agentclass.h:139
static Serial * rxr_serial
Definition: agent_tunnel.cpp:60
static Agent * agent
Definition: agent_tunnel.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
string utc2iso8601(double utc)
ISO 8601 version of time.
Definition: timelib.cpp:1286
int32_t set_timeout(int, double timeout)
Definition: serialclass.cpp:515
vector< agentstruc > agent
Single entry vector for agent information.
Definition: jsondef.h:4247
static Serial * txr_serial
Definition: agent_tunnel.cpp:61
void tun_read_loop()
Definition: agent_kpc9612p.cpp:250
cosmosstruc * cinfo
Definition: agentclass.h:346
void tcv_write_loop()
Definition: agent_kpc9612p.cpp:416
string mjd2iso8601(double mjd)
Definition: timelib.cpp:1316
int32_t get_error()
Definition: serialclass.cpp:170
static uint32_t rxr_baud
Definition: agent_tunnel.cpp:62
void tcv_read_loop()
Definition: agent_kpc9612p.cpp:358