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