/[cvs]/eggdrop1.9/testcode/sclient.c
ViewVC logotype

Contents of /eggdrop1.9/testcode/sclient.c

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.2 - (show annotations) (download) (as text)
Wed Jun 19 04:51:54 2002 UTC (16 years, 11 months ago) by stdarg
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +25 -36 lines
File MIME type: text/x-chdr
* I think the sockbuf api is almost done

1 #include <stdio.h>
2 #include <stdlib.h>
3
4 #include "my_socket.h"
5 #include "sockbuf.h"
6
7 int server_idx;
8
9 int server_read(void *client_data, int idx, char *data, int len)
10 {
11 printf("server: [%s]\n", data);
12 return(0);
13 }
14
15 int server_eof(void *client_data, int idx, int err, const char *errmsg)
16 {
17 if (err && errmsg) printf("Error: %s\n", errmsg);
18 printf("Server closed connection!\n");
19 exit(0);
20 }
21
22 int server_connect(void *client_data, int idx, const char *peer_ip, int peer_port)
23 {
24 printf("Connected to server (%s %d)!\n", peer_ip, peer_port);
25 //sslmode_on(idx, 0); /* 0 means client, 1 means server */
26 //zipmode_on(idx);
27 linemode_on(idx);
28 return(0);
29 }
30
31 static sockbuf_handler_t server_event = {
32 "server",
33 server_connect, server_eof, NULL,
34 server_read, NULL
35 };
36
37 int stdin_read(void *client_data, int idx, char *data, int len)
38 {
39 printf("you said: [%s]\n", data);
40 data[len] = '\n';
41 sockbuf_write(server_idx, data, len+1);
42 return(0);
43 }
44
45 int stdin_eof(void *client_data, int idx, int err, const char *errmsg)
46 {
47 sockbuf_delete(idx);
48 return(0);
49 }
50
51 static sockbuf_handler_t stdin_event = {
52 "stdin",
53 NULL, stdin_eof, NULL,
54 stdin_read, NULL
55 };
56
57 main (int argc, char *argv[])
58 {
59 int sock, port, proxy_port, stdin_idx, proxy, i;
60 char *user, *pass, *host, *proxy_host;
61
62 if (argc != 8) {
63 printf("usage: %s proxy-type proxy-host proxy-port user pass host port\n", argv[0]);
64 return(0);
65 }
66
67 srand(time(0));
68 proxy = atoi(argv[1]);
69 proxy_host = argv[2];
70 proxy_port = atoi(argv[3]);
71 user = argv[4];
72 pass = argv[5];
73 host = argv[6];
74 port = atoi(argv[7]);
75
76 printf("Connecting to %s %d by way of %s %d\n", host, port, proxy_host, proxy_port);
77
78 if (proxy == 1) server_idx = socks5_connect(-1, proxy_host, proxy_port, user, pass, host, port);
79 else if (proxy == 2) server_idx = socks4_connect(-1, proxy_host, proxy_port, user, host, port);
80 else if (proxy == 3) server_idx = http_connect(-1, proxy_host, proxy_port, user, pass, host, port);
81 else {
82 printf("invalid proxy type\n");
83 printf("1 - socks5, 2 - socks4, 3 - http\n");
84 return(0);
85 }
86
87 sockbuf_set_handler(server_idx, &server_event, NULL);
88 // sslmode_init();
89
90 stdin_idx = sockbuf_new();
91 sockbuf_set_sock(stdin_idx, 0, 0);
92 sockbuf_set_handler(stdin_idx, &stdin_event, NULL);
93 linemode_on(stdin_idx);
94 while (1) {
95 sockbuf_update_all(-1);
96 }
97 return(0);
98 }

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23