if (getsockopt(sck, SOL_SOCKET, SO_ERROR, (char *)(&opt), &opt_len) == 0)
{ if (opt == 0)
{ return1;
}
}
return0;
}
/*****************************************************************************/ staticint
copy_sck_to_sck(int from_sck, int to_sck, int hexdump, int local)
{ char buff[1024 * 32]; int rv = -1;
int count = g_tcp_recv(from_sck, buff, sizeof(buff), 0); if (count > 0 && count <= (int)sizeof(buff))
{
rv = count; // Assume we'll return the amount of data copied if (local)
{
g_loc_io_count += count; if (hexdump)
{
LOG_HEXDUMP(LOG_LEVEL_INFO, "from local:", buff, count);
}
} else
{
g_rem_io_count += count; if (hexdump)
{
LOG_HEXDUMP(LOG_LEVEL_INFO, "from remote:", buff, count);
}
}
constchar *p = buff; while ((count > 0) && (!g_terminated))
{ int error = g_tcp_send(to_sck, p, count, 0);
if (error > 0 && error <= count)
{ // We wrote some data
count -= error;
p += error;
} elseif ((error == -1) && g_tcp_last_error_would_block(to_sck))
{ if (g_tcp_can_send(to_sck, 1000))
{
g_tcp_socket_ok(to_sck);
}
} else
{
count = 0; // Terminate loop
rv = -1; // tell user
}
}
}
return rv;
}
/*****************************************************************************/ staticint
main_loop(char *local_port, char *remote_ip, char *remote_port, int hexdump)
{ int lis_sck = -1; int acc_sck = -1; int con_sck = -1; int sel; int count; int error; int i; int acc_to_con = 0; int con_to_acc = 0;
/* create the listening socket and setup options */
lis_sck = g_tcp_socket(); if (lis_sck < 0)
{
error = 1;
} else
{
g_tcp_set_non_blocking(lis_sck);
g_sck_set_reuseaddr(lis_sck);
error = g_tcp_bind(lis_sck, local_port);
}
if (error != 0)
{
LOG(LOG_LEVEL_WARNING, "bind failed");
}
/* listen for an incoming connection */ if (error == 0)
{
error = g_tcp_listen(lis_sck);
if (error == 0)
{
LOG(LOG_LEVEL_INFO, "listening for connection");
}
}
/* accept an incoming connection */ if (error == 0)
{ while ((!g_terminated) && (error == 0))
{
acc_sck = g_sck_accept(lis_sck);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.