Annotation of libaitcli/example/tnet.c, revision 1.3.14.1
1.2 misho 1: #include <stdio.h>
1.3 misho 2: #include <unistd.h>
1.2 misho 3: #include <string.h>
4: #include <sys/socket.h>
5: #include <sys/select.h>
1.3.14.1! misho 6: #ifndef __linux__
1.2 misho 7: #include <sys/filio.h>
1.3.14.1! misho 8: #endif
1.2 misho 9: #include <netinet/in.h>
10: #include <arpa/inet.h>
11: #include <arpa/telnet.h>
1.3 misho 12: #include <elwix.h>
1.2 misho 13: #include <aitcli.h>
14:
15:
16: int main(int argc, char **argv)
17: {
18: int ret, s, c;
19: struct sockaddr_in sin = { sizeof sin, AF_INET, htons(2000), .sin_addr.s_addr = 0x100007f };
20: struct telnetAttrs *a, A[2];
21: char str[256], code;
22:
23: s = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
24: bind(s, (struct sockaddr*) &sin, sizeof sin);
25: listen(s, 1);
26: c = accept(s, (struct sockaddr*) &sin, (socklen_t*) &ret);
27:
28: cli_telnet_SetCmd(&A[0], DO, TELOPT_TTYPE);
29: if (argc > 1) {
30: cli_telnet_Set_SubOpt(&A[1], TELOPT_TTYPE, TELQUAL_SEND, NULL, 0);
1.3 misho 31: // cli_telnet_DumpAttrs(A, 2);
1.2 misho 32: printf("cli_telnetSend()=%d bytes\n", cli_telnetSend(c, &A[0], 1, NULL, 0, 1));
33: printf("errno=%d %s ret=%d telnetRecv()=%d attributes\n", cli_GetErrno(), cli_GetError(),
34: ret, cli_telnetRecv(c, &a, &ret, str, 255));
1.3 misho 35: // cli_telnet_DumpAttrs(a, ret);
36: e_free(a);
1.2 misho 37:
38: printf("str=%s\n", str);
39:
40: printf("telnetSend()=%d bytes\n", cli_telnetSend(c, &A[1], 1, "brym\n", 5, 0));
41: printf("errno=%d %s ret=%d telnetRecv()=%d attributes\n", cli_GetErrno(), cli_GetError(),
42: ret, cli_telnetRecv(c, &a, &ret, str, 255));
1.3 misho 43: // cli_telnet_DumpAttrs(a, ret);
1.2 misho 44: ret = 255;
1.3 misho 45: printf("term=%X str=%s get_subopt=%d\n", (u_char) code, str,
46: cli_telnet_Get_SubOpt(&a[0], (u_char*) &code, str, (u_char*) &ret));
47: e_free(a);
1.2 misho 48: } else {
49: cli_telnet_SetCmd(&A[1], GA, 0);
1.3 misho 50: // cli_telnet_DumpAttrs(A, 2);
1.2 misho 51:
52: char caps[] = { TELOPT_BINARY, TELOPT_TTYPE, TELOPT_STATUS };
1.3 misho 53: printf("a=%p ret=%d telnet_Answer()=%d\n", a, ret,
54: cli_telnet_Answer((u_char*) caps, sizeof caps, A, 2, &a, &ret));
55: // cli_telnet_DumpAttrs(a, ret);
56: e_free(a);
1.2 misho 57:
58: printf("telnetSend()=%d bytes\n", cli_telnetSend(c, A, 2, "piuk\n", 5, 0));
59: printf("errno=%d %s ret=%d telnetRecv()=%d bytes\n", cli_GetErrno(), cli_GetError(),
60: ret, cli_telnetRecv(c, &a, &ret, str, 255));
1.3 misho 61: // cli_telnet_DumpAttrs(a, ret);
62: e_free(a);
1.2 misho 63:
64: printf("str=%s\n", str);
65:
66: cli_telnet_Set_SubOpt(&A[1], TELOPT_TTYPE, TELQUAL_SEND, NULL, 0);
67: printf("telnetSend()=%d bytes\n", cli_telnetSend(c, &A[1], 1, NULL, 0, 1));
68: printf("errno=%d %s ret=%d telnetRecv()=%d bytes\n", cli_GetErrno(), cli_GetError(),
69: ret, cli_telnetRecv(c, &a, &ret, str, 255));
1.3 misho 70: // cli_telnet_DumpAttrs(a, ret);
1.2 misho 71: printf("str=%s\n", str);
72: ret = 255;
1.3 misho 73: printf("term=%X str=%s get_subopt=%d\n", code, str,
74: cli_telnet_Get_SubOpt(&a[0], (u_char*) &code, str, (u_char*) &ret));
75: e_free(a);
1.2 misho 76:
77: printf("errno=%d %s ret=%d telnetRecv()=%d bytes\n", cli_GetErrno(), cli_GetError(),
78: ret, cli_telnetRecv(c, &a, &ret, str, 255));
1.3 misho 79: // cli_telnet_DumpAttrs(a, ret);
80: e_free(a);
1.2 misho 81:
82: printf("str=%s\n", str);
83:
84: printf("telnetSend()=%d bytes\n", cli_telnetSend(c, NULL, 0, "ALA-BALA\n", 9, 0));
85: printf("errno=%d %s ret=%d telnetRecv()=%d bytes\n", cli_GetErrno(), cli_GetError(),
86: ret, cli_telnetRecv(c, NULL, NULL, str, 255));
1.3 misho 87: e_free(a);
1.2 misho 88: printf("str=%s\n", str);
89: printf("errno=%d %s ret=%d telnetRecv()=%d bytes\n", cli_GetErrno(), cli_GetError(),
90: ret, cli_telnetRecv(c, &a, &ret, str, 255));
1.3 misho 91: // cli_telnet_DumpAttrs(a, ret);
92: e_free(a);
1.2 misho 93:
94: printf("str=%s\n", str);
95: }
96:
97: close(c);
98: close(s);
99: return 0;
100: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>