Skip to content

Commit

Permalink
half way there
Browse files Browse the repository at this point in the history
  • Loading branch information
gjedeer committed Apr 27, 2021
1 parent 972abf9 commit 0250be7
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 30 deletions.
13 changes: 9 additions & 4 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -383,20 +383,25 @@ int send_frame(protocol_frame *frame, uint8_t *data)
return rv;
}

int send_tunnel_ack_frame(tunnel *tun)
int send_tunnel_ack_frame(tunnel *tun, char *remote_hostname, int remote_port)
{
protocol_frame frame_st;
protocol_frame *frame;
uint8_t data[PROTOCOL_BUFFER_OFFSET];
uint8_t *data = NULL;

frame = &frame_st;
memset(frame, 0, sizeof(protocol_frame));

frame->packet_type = PACKET_TYPE_ACKTUNNEL;
frame->connid = tun->connid;
frame->data_length = 0;
frame->data_length = strlen(remote_hostname) + 3;
frame->friendnumber = tun->friendnumber;

data = calloc(PROTOCOL_BUFFER_OFFSET + frame->data_length, 1);
data[PROTOCOL_BUFFER_OFFSET + 0] = BYTE1(remote_port);
data[PROTOCOL_BUFFER_OFFSET + 1] = BYTE2(remote_port);
strncpy(data + PROTOCOL_BUFFER_OFFSET + 2, remote_hostname, frame->data_length-2);

return send_frame(frame, data);
}

Expand Down Expand Up @@ -485,7 +490,7 @@ int handle_request_tunnel_frame(protocol_frame *rcvd_frame)
FD_SET(sockfd, &master_server_fds);
update_select_nfds(sockfd);
log_printf(L_DEBUG, "Created tunnel, yay!\n");
send_tunnel_ack_frame(tun);
send_tunnel_ack_frame(tun, hostname, port);
}
else
{
Expand Down
52 changes: 26 additions & 26 deletions main.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@


typedef struct tunnel_t {
/* The forwarded socket fd */
int sockfd;
/* Connection ID, must be int because of uthash */
int connid;
/* Friend number of remote end */
uint32_t friendnumber;

UT_hash_handle hh;
/* The forwarded socket fd */
int sockfd;
/* Connection ID, must be int because of uthash */
int connid;
/* Friend number of remote end */
uint32_t friendnumber;

UT_hash_handle hh;
} tunnel;

typedef struct tunnel_list_t {
Expand All @@ -64,34 +64,34 @@ typedef struct tunnel_list_t {
} tunnel_list;

typedef struct allowed_toxid {
uint8_t toxid[TOX_ADDRESS_SIZE];
struct allowed_toxid *next;
uint8_t toxid[TOX_ADDRESS_SIZE];
struct allowed_toxid *next;
} allowed_toxid;

typedef struct protocol_frame_t {
uint32_t friendnumber;

/* Fields actually found in the protocol */
uint16_t magic;
uint16_t packet_type;
uint16_t connid;
uint16_t data_length;
uint8_t *data;
uint32_t friendnumber;

/* Fields actually found in the protocol */
uint16_t magic;
uint16_t packet_type;
uint16_t connid;
uint16_t data_length;
uint8_t *data;
} protocol_frame;

/* A list of local port forwards (listen locally, forward to server */
typedef struct local_port_forward_t {
int local_port;
char *remote_host;
int remote_port;
int local_port;
char *remote_host;
int remote_port;

/* Sock representing the local port - call accept() on it */
int bind_sockfd;
/* Sock representing the local port - call accept() on it */
int bind_sockfd;

/* Client mode tunnel object for this port forward */
tunnel *tun;
/* Client mode tunnel object for this port forward */
tunnel *tun;

struct local_port_forward_t *next;
struct local_port_forward_t *next;
} local_port_forward;

/* Rules policy */
Expand Down

0 comments on commit 0250be7

Please sign in to comment.