46 |
#define INADDR_NONE ((unsigned long) -1) |
#define INADDR_NONE ((unsigned long) -1) |
47 |
#endif |
#endif |
48 |
|
|
49 |
|
#ifdef WITH_SCARD |
50 |
|
#define STREAM_COUNT 8 |
51 |
|
#else |
52 |
|
#define STREAM_COUNT 1 |
53 |
|
#endif |
54 |
|
|
55 |
static int g_sock; |
static int g_sock; |
56 |
static struct stream g_in; |
static struct stream g_in; |
57 |
#ifndef WITH_SCARD |
static struct stream g_out[STREAM_COUNT]; |
|
static struct stream g_out; |
|
|
#endif |
|
58 |
int g_tcp_port_rdp = TCP_PORT_RDP; |
int g_tcp_port_rdp = TCP_PORT_RDP; |
59 |
|
|
60 |
/* wait till socket is ready to write or timeout */ |
/* wait till socket is ready to write or timeout */ |
81 |
STREAM |
STREAM |
82 |
tcp_init(uint32 maxlen) |
tcp_init(uint32 maxlen) |
83 |
{ |
{ |
84 |
|
static int cur_stream_id = 0; |
85 |
STREAM result = NULL; |
STREAM result = NULL; |
86 |
|
|
87 |
#ifdef WITH_SCARD |
#ifdef WITH_SCARD |
88 |
scard_lock(SCARD_LOCK_TCP); |
scard_lock(SCARD_LOCK_TCP); |
|
result = scard_tcp_init(); |
|
|
#else |
|
|
result = &g_out; |
|
89 |
#endif |
#endif |
90 |
|
result = &g_out[cur_stream_id]; |
91 |
|
cur_stream_id = (cur_stream_id + 1) % STREAM_COUNT; |
92 |
|
|
93 |
if (maxlen > result->size) |
if (maxlen > result->size) |
94 |
{ |
{ |
208 |
{ |
{ |
209 |
socklen_t option_len; |
socklen_t option_len; |
210 |
uint32 option_value; |
uint32 option_value; |
211 |
|
int i; |
212 |
|
|
213 |
#ifdef IPv6 |
#ifdef IPv6 |
214 |
|
|
301 |
g_in.size = 4096; |
g_in.size = 4096; |
302 |
g_in.data = (uint8 *) xmalloc(g_in.size); |
g_in.data = (uint8 *) xmalloc(g_in.size); |
303 |
|
|
304 |
#ifdef WITH_SCARD |
for (i = 0; i < STREAM_COUNT; i++) |
305 |
scard_tcp_connect(); |
{ |
306 |
#else |
g_out[i].size = 4096; |
307 |
g_out.size = 4096; |
g_out[i].data = (uint8 *) xmalloc(g_out[i].size); |
308 |
g_out.data = (uint8 *) xmalloc(g_out.size); |
} |
|
#endif |
|
309 |
|
|
310 |
return True; |
return True; |
311 |
} |
} |
338 |
void |
void |
339 |
tcp_reset_state(void) |
tcp_reset_state(void) |
340 |
{ |
{ |
341 |
|
int i; |
342 |
|
|
343 |
g_sock = -1; /* reset socket */ |
g_sock = -1; /* reset socket */ |
344 |
|
|
345 |
/* Clear the incoming stream */ |
/* Clear the incoming stream */ |
356 |
g_in.channel_hdr = NULL; |
g_in.channel_hdr = NULL; |
357 |
|
|
358 |
/* Clear the outgoing stream(s) */ |
/* Clear the outgoing stream(s) */ |
359 |
#ifdef WITH_SCARD |
for (i = 0; i < STREAM_COUNT; i++) |
360 |
scard_tcp_reset_state(); |
{ |
361 |
#else |
if (g_out[i].data != NULL) |
362 |
if (g_out.data != NULL) |
xfree(g_out[i].data); |
363 |
xfree(g_out.data); |
g_out[i].p = NULL; |
364 |
g_out.p = NULL; |
g_out[i].end = NULL; |
365 |
g_out.end = NULL; |
g_out[i].data = NULL; |
366 |
g_out.data = NULL; |
g_out[i].size = 0; |
367 |
g_out.size = 0; |
g_out[i].iso_hdr = NULL; |
368 |
g_out.iso_hdr = NULL; |
g_out[i].mcs_hdr = NULL; |
369 |
g_out.mcs_hdr = NULL; |
g_out[i].sec_hdr = NULL; |
370 |
g_out.sec_hdr = NULL; |
g_out[i].rdp_hdr = NULL; |
371 |
g_out.rdp_hdr = NULL; |
g_out[i].channel_hdr = NULL; |
372 |
g_out.channel_hdr = NULL; |
} |
|
#endif |
|
373 |
} |
} |