mirror of
https://github.com/lxsang/antd-tunnel-publishers
synced 2025-08-31 16:22:04 +02:00
initial commit
This commit is contained in:
12
vterm/Makefile.am
Normal file
12
vterm/Makefile.am
Normal file
@@ -0,0 +1,12 @@
|
||||
AUTOMAKE_OPTIONS = foreign
|
||||
|
||||
|
||||
|
||||
AM_CPPFLAGS = -W -Wall -g -std=c99
|
||||
|
||||
# bin
|
||||
bin_PROGRAMS = vterm
|
||||
# source files
|
||||
vterm_SOURCES = vterm.c ../tunnel.c
|
||||
vterm_CPPFLAGS= -I../
|
||||
# antd_LDADD = libantd.la
|
BIN
vterm/vterm
Executable file
BIN
vterm/vterm
Executable file
Binary file not shown.
71
vterm/vterm.c
Normal file
71
vterm/vterm.c
Normal file
@@ -0,0 +1,71 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/socket.h>
|
||||
#include "tunnel.h"
|
||||
|
||||
#define MODULE_NAME "vterm"
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
int fd;
|
||||
tunnel_msg_t msg;
|
||||
int status;
|
||||
char buff[MAX_CHANNEL_NAME+1];
|
||||
LOG_INIT(MODULE_NAME);
|
||||
if(argc != 2)
|
||||
{
|
||||
printf("Usage: %s path/to/hotline/socket\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
LOG(MODULE_NAME, "Hotline is: %s", argv[1]);
|
||||
// now try to request new channel from hotline
|
||||
fd = open_unix_socket(argv[1]);
|
||||
if(fd == -1)
|
||||
{
|
||||
ERROR(MODULE_NAME, "Unable to open the hotline: %s", argv[1]);
|
||||
return -1;
|
||||
}
|
||||
msg.header.type = CHANNEL_OPEN;
|
||||
msg.header.channel_id = 0;
|
||||
msg.header.client_id = 0;
|
||||
LOG(MODULE_NAME, "Request to open the channel %s", MODULE_NAME);
|
||||
(void)strncpy(buff, MODULE_NAME,MAX_CHANNEL_NAME);
|
||||
msg.header.size = strlen(buff);
|
||||
msg.data = (uint8_t*) buff;
|
||||
if(msg_write(fd, &msg) == -1)
|
||||
{
|
||||
ERROR(MODULE_NAME, "Unable to write message to hotline");
|
||||
(void) close(fd);
|
||||
return -1;
|
||||
}
|
||||
LOG(MODULE_NAME, "Wait for comfirm creation of %s", MODULE_NAME);
|
||||
// now wait for message
|
||||
if(msg_read(fd, &msg) == -1)
|
||||
{
|
||||
ERROR(MODULE_NAME, "Unable to read message from hotline");
|
||||
(void) close(fd);
|
||||
return -1;
|
||||
}
|
||||
if(msg.header.type == CHANNEL_OK)
|
||||
{
|
||||
LOG(MODULE_NAME, "Channel created: %s", MODULE_NAME);
|
||||
if(msg.data)
|
||||
free(msg.data);
|
||||
}
|
||||
// close the channel
|
||||
LOG(MODULE_NAME, "Close the channel %s (%d)", MODULE_NAME, fd);
|
||||
msg.header.type = CHANNEL_CLOSE;
|
||||
msg.header.size = 0;
|
||||
msg.data = NULL;
|
||||
sleep(5);
|
||||
if( msg_write(fd, &msg) == -1)
|
||||
{
|
||||
ERROR(MODULE_NAME, "Unable to request channel close");
|
||||
}
|
||||
(void)msg_read(fd, &msg);
|
||||
shutdown(fd, SHUT_WR);
|
||||
(void) close(fd);
|
||||
printf("Main application\n");
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user