static struct private_client_data *pcd;
+static void rc4_send(unsigned long len, const unsigned char *indata,
+ unsigned char *outdata)
+{
+ RC4(&pcd->rc4_send_key, len, indata, outdata);
+}
+
+static void rc4_recv(unsigned long len, const unsigned char *indata,
+ unsigned char *outdata)
+{
+ RC4(&pcd->rc4_recv_key, len, indata, outdata);
+}
+
+
/*
* client log function
*/
free(pcd);
}
+static void append_str(char **data, const char* append)
+{
+ if (*data) {
+ char *tmp = make_message("%s\n%s", *data, append);
+ free(*data);
+ *data = tmp;
+ } else
+ *data = para_strdup(append);
+}
+
static int client_parse_config(int argc, char *argv[],
struct private_client_data **pcd_ptr)
{
return ret;
}
-static void rc4_send(unsigned long len, const unsigned char *indata,
- unsigned char *outdata)
-{
- RC4(&pcd->rc4_send_key, len, indata, outdata);
-}
-
-static void rc4_recv(unsigned long len, const unsigned char *indata,
- unsigned char *outdata)
-{
- RC4(&pcd->rc4_recv_key, len, indata, outdata);
-}
-
-static void append_str(char **data, const char* append)
-{
- if (*data) {
- char *tmp = make_message("%s\n%s", *data, append);
- free(*data);
- *data = tmp;
- } else
- *data = para_strdup(append);
-}
-
-
static int send_stdin(int fd)
{
char buf[8192];
return 1;
}
+static int client_open(struct private_client_data *pcd)
+{
+ int ret;
+ struct hostent *he;
+ struct sockaddr_in their_addr;
+
+ /* get the host info */
+ PARA_NOTICE_LOG("getting host info of %s\n",
+ pcd->conf.hostname_arg);
+ ret = get_host_info(pcd->conf.hostname_arg, &he);
+ if (ret < 0)
+ goto out;
+ /* get new socket */
+ ret = get_socket();
+ if (ret < 0)
+ goto out;
+ pcd->fd = ret;
+ /* init their_addr */
+ init_sockaddr(&their_addr, pcd->conf.server_port_arg, he);
+ /* connect */
+ PARA_NOTICE_LOG("connecting to %s\n", pcd->conf.hostname_arg);
+ ret = para_connect(pcd->fd, &their_addr);
+ if (ret < 0)
+ goto out;
+ ret = 1;
+out:
+ return ret;
+}
+
+
/*
* MAIN
*/
pcd->conf.hostname_arg,
pcd->conf.server_port_arg
);
- /* concat args */
- for (i = 0; i < pcd->conf.inputs_num; i++)
- append_str(&command, pcd->conf.inputs[i]);
- /* get the host info */
- PARA_NOTICE_LOG("getting host info of %s\n",
- pcd->conf.hostname_arg);
- ret = get_host_info(pcd->conf.hostname_arg, &he);
- if (ret < 0)
- goto out;
- /* get new socket */
- ret = get_socket();
- if (ret < 0)
- goto out;
- pcd->fd = ret;
- /* init their_addr */
- init_sockaddr(&their_addr, pcd->conf.server_port_arg, he);
- /* connect */
- PARA_NOTICE_LOG("connecting to %s\n", pcd->conf.hostname_arg);
- ret = para_connect(pcd->fd, &their_addr);
+ ret = client_open(pcd);
if (ret < 0)
goto out;
/* receive welcome message */
rc4_buf[0], rc4_buf[1], rc4_buf[2], rc4_buf[3]);
enable_crypt(pcd->fd, rc4_recv, rc4_send);
}
+ /* concat args */
+ for (i = 0; i < pcd->conf.inputs_num; i++)
+ append_str(&command, pcd->conf.inputs[i]);
/* send command */
PARA_INFO_LOG("--> %s\n", command);
ret = send_buffer(pcd->fd, command);