本文整理汇总了C++中sk_write函数的典型用法代码示例。如果您正苦于以下问题:C++ sk_write函数的具体用法?C++ sk_write怎么用?C++ sk_write使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sk_write函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: proxy_http_negotiate
int proxy_http_negotiate (ProxySocket *p, int change)
{
if (p->state == PROXY_STATE_NEW) {
/* we are just beginning the proxy negotiate process,
* so we'll send off the initial bits of the request.
* for this proxy method, it's just a simple HTTP
* request
*/
char *buf, dest[512];
char *username, *password;
sk_getaddr(p->remote_addr, dest, lenof(dest));
buf = dupprintf("CONNECT %s:%i HTTP/1.1\r\nHost: %s:%i\r\n",
dest, p->remote_port, dest, p->remote_port);
sk_write(p->sub_socket, buf, strlen(buf));
sfree(buf);
username = conf_get_str(p->conf, CONF_proxy_username);
password = conf_get_str(p->conf, CONF_proxy_password);
if (username[0] || password[0]) {
char *buf, *buf2;
int i, j, len;
buf = dupprintf("%s:%s", username, password);
len = strlen(buf);
buf2 = snewn(len * 4 / 3 + 100, char);
sprintf(buf2, "Proxy-Authorization: Basic ");
for (i = 0, j = strlen(buf2); i < len; i += 3, j += 4)
base64_encode_atom((unsigned char *)(buf+i),
(len-i > 3 ? 3 : len-i), buf2+j);
strcpy(buf2+j, "\r\n");
sk_write(p->sub_socket, buf2, strlen(buf2));
sfree(buf);
sfree(buf2);
}
示例2: adb_receive
static int adb_receive(Plug plug, int urgent, char *data, int len)
{
Adb adb = (Adb) plug;
if (adb->state == STATE_SENT_HELLO) {
if (data[0]=='O') { // OKAY
sk_write(adb->s,"0006shell:",10);
adb->state = STATE_ASKED_FOR_SHELL; // wait for shell start response
} else {
if (data[0]=='F') {
handle_fail(adb, data, len);
} else {
connection_fatal(adb->frontend, "Bad response after initial send");
}
return 0;
}
} else if (adb->state == STATE_ASKED_FOR_SHELL) {
if (data[0]=='O') { //OKAY
adb->state = STATE_CONNECTED; // shell started, switch to terminal mode
} else {
if (data[0]=='F') {
handle_fail(adb, data, len);
} else {
connection_fatal(adb->frontend, "Bad response waiting for shell start");
}
return 0;
}
} else if (adb->state == STATE_WAITING_FOR_ERROR_MESSAGE) {
do_fatal(adb, data, len);
} else {
c_write(adb, data, len);
}
return 1;
}
示例3: rlogin_send
/*
* Called to send data down the rlogin connection.
*/
static int rlogin_send(void *handle, char *buf, int len)
{
Rlogin rlogin = (Rlogin) handle;
if (rlogin->s == NULL)
return 0;
if (rlogin->prompt) {
/*
* We're still prompting for a username, and aren't talking
* directly to the network connection yet.
*/
int ret = get_userpass_input(rlogin->prompt,
(unsigned char *)buf, len);
if (ret >= 0) {
rlogin_startup(rlogin, rlogin->prompt->prompts[0]->result);
/* that nulls out rlogin->prompt, so then we'll start sending
* data down the wire in the obvious way */
}
} else {
rlogin->bufsize = sk_write(rlogin->s, buf, len);
}
return rlogin->bufsize;
}
示例4: main
int main(int argc, char *argv[])
{
if (argc < 2) {
usage();
} else {
/* Version command */
if (argv[1][0] == 'v') {
printf("%s\n", programVersion);
return 1;
}
if (argc > 2) {
/* Cmd Read / Write / version */
switch (argv[2][0]) {
case 'r':
case 'R':
sk_read(argc, argv);
break;
case 'w':
case 'W':
sk_write(argc, argv);
break;
}
}
}
return 1;
}
示例5: proxy_socks5_selectchap
int proxy_socks5_selectchap(Proxy_Socket p)
{
if (p->cfg.proxy_username[0] || p->cfg.proxy_password[0]) {
char chapbuf[514];
int ulen;
chapbuf[0] = '\x01'; /* Version */
chapbuf[1] = '\x02'; /* Number of attributes sent */
chapbuf[2] = '\x11'; /* First attribute - algorithms list */
chapbuf[3] = '\x01'; /* Only one CHAP algorithm */
chapbuf[4] = '\x85'; /* ...and it's HMAC-MD5, the core one */
chapbuf[5] = '\x02'; /* Second attribute - username */
ulen = strlen(p->cfg.proxy_username);
if (ulen > 255) ulen = 255; if (ulen < 1) ulen = 1;
chapbuf[6] = ulen;
memcpy(chapbuf+7, p->cfg.proxy_username, ulen);
sk_write(p->sub_socket, chapbuf, ulen + 7);
p->chap_num_attributes = 0;
p->chap_num_attributes_processed = 0;
p->chap_current_attribute = -1;
p->chap_current_datalen = 0;
p->state = 8;
} else
plug_closing(p->plug, "Proxy error: Server chose "
"CHAP authentication but we didn't offer it!",
PROXY_ERROR_GENERAL, 0);
return 1;
}
示例6: process_subneg
static void process_subneg(Telnet telnet)
{
unsigned char *b, *p, *q;
int var, value, n, bsize;
char *e, *eval, *ekey, *user;
switch (telnet->sb_opt) {
case TELOPT_TSPEED:
if (telnet->sb_len == 1 && telnet->sb_buf[0] == TELQUAL_SEND) {
char *logbuf;
char *termspeed = conf_get_str(telnet->conf, CONF_termspeed);
b = snewn(20 + strlen(termspeed), unsigned char);
b[0] = IAC;
b[1] = SB;
b[2] = TELOPT_TSPEED;
b[3] = TELQUAL_IS;
strcpy((char *)(b + 4), termspeed);
n = 4 + strlen(termspeed);
b[n] = IAC;
b[n + 1] = SE;
telnet->bufsize = sk_write(telnet->s, (char *)b, n + 2);
logevent(telnet->frontend, "server:\tSB TSPEED SEND");
logbuf = dupprintf("client:\tSB TSPEED IS %s", termspeed);
logevent(telnet->frontend, logbuf);
sfree(logbuf);
sfree(b);
} else
示例7: raw_send
/*
* Called to send data down the raw connection.
*/
static int raw_send(char *buf, int len)
{
if (s == NULL)
return 0;
raw_bufsize = sk_write(s, buf, len);
return raw_bufsize;
}
示例8: sk_proxy_write
static int sk_proxy_write(Socket s, const char *data, int len) {
Proxy_Socket ps = (Proxy_Socket) s;
if (ps->state != PROXY_STATE_ACTIVE) {
bufchain_add(&ps->pending_output_data, data, len);
return bufchain_size(&ps->pending_output_data);
}
return sk_write(ps->sub_socket, data, len);
}
示例9: sk_proxy_write
static int sk_proxy_write (Socket s, const void *data, int len)
{
ProxySocket *ps = FROMFIELD(s, ProxySocket, sockvt);
if (ps->state != PROXY_STATE_ACTIVE) {
bufchain_add(&ps->pending_output_data, data, len);
return bufchain_size(&ps->pending_output_data);
}
return sk_write(ps->sub_socket, data, len);
}
示例10: send_opt
static void send_opt(Telnet telnet, int cmd, int option)
{
unsigned char b[3];
b[0] = IAC;
b[1] = cmd;
b[2] = option;
telnet->bufsize = sk_write(telnet->s, (char *)b, 3);
log_option(telnet, "client", cmd, option);
}
示例11: sk_proxy_write
static size_t sk_proxy_write (Socket *s, const void *data, size_t len)
{
ProxySocket *ps = container_of(s, ProxySocket, sock);
if (ps->state != PROXY_STATE_ACTIVE) {
bufchain_add(&ps->pending_output_data, data, len);
return bufchain_size(&ps->pending_output_data);
}
return sk_write(ps->sub_socket, data, len);
}
示例12: adb_send
/*
* Called to send data down the adb connection.
*/
static int adb_send(void *handle, char *buf, int len)
{
Adb adb = (Adb) handle;
if (adb->s == NULL)
return 0;
adb->bufsize = sk_write(adb->s, buf, len);
return adb->bufsize;
}
示例13: rlogin_send
/*
* Called to send data down the rlogin connection.
*/
static int rlogin_send(void *handle, char *buf, int len)
{
Rlogin rlogin = (Rlogin) handle;
if (rlogin->s == NULL)
return 0;
rlogin->bufsize = sk_write(rlogin->s, buf, len);
return rlogin->bufsize;
}
示例14: proxy_activate
/*
* Call this when proxy negotiation is complete, so that this
* socket can begin working normally.
*/
void proxy_activate(Proxy_Socket p)
{
void *data;
int len;
long output_before, output_after;
p->state = PROXY_STATE_ACTIVE;
/* we want to ignore new receive events until we have sent
* all of our buffered receive data.
*/
sk_set_frozen(p->sub_socket, 1);
/* how many bytes of output have we buffered? */
output_before = bufchain_size(&p->pending_oob_output_data) +
bufchain_size(&p->pending_output_data);
/* and keep track of how many bytes do not get sent. */
output_after = 0;
/* send buffered OOB writes */
while (bufchain_size(&p->pending_oob_output_data) > 0) {
bufchain_prefix(&p->pending_oob_output_data, &data, &len);
output_after += sk_write_oob(p->sub_socket, data, len);
bufchain_consume(&p->pending_oob_output_data, len);
}
/* send buffered normal writes */
while (bufchain_size(&p->pending_output_data) > 0) {
bufchain_prefix(&p->pending_output_data, &data, &len);
output_after += sk_write(p->sub_socket, data, len);
bufchain_consume(&p->pending_output_data, len);
}
/* if we managed to send any data, let the higher levels know. */
if (output_after < output_before)
plug_sent(p->plug, output_after);
/* if we were asked to flush the output during
* the proxy negotiation process, do so now.
*/
if (p->pending_flush)
sk_flush(p->sub_socket);
/* if we have a pending EOF to send, send it */
if (p->pending_eof)
sk_write_eof(p->sub_socket);
/* if the backend wanted the socket unfrozen, try to unfreeze.
* our set_frozen handler will flush buffered receive data before
* unfreezing the actual underlying socket.
*/
if (!p->freeze)
sk_set_frozen((Socket)p, 0);
}
示例15: raw_send
/*
* Called to send data down the raw connection.
*/
static int raw_send(void *handle, char *buf, int len)
{
Raw raw = (Raw) handle;
if (raw->s == NULL)
return 0;
raw->bufsize = sk_write(raw->s, buf, len);
return raw->bufsize;
}