Go to the documentation of this file.00001 #include <string.h>
00002
00003 #include "echo.h"
00004 #include "proxylib.h"
00005
00006 int ns_errno;
00007
00008 void str_cli(FILE *, int);
00009
00010 int main(int argc, char **argv)
00011 {
00012 int sockfd;
00013 PROXY_COMPONENTADDR servaddr;
00014
00015 if (argc != 3) {
00016 fprintf(stderr, "usage: tcpcli <server component ID> <port>\n");
00017 exit(EXIT_FAILURE);
00018 }
00019
00020 proxy_init("nse.cfg");
00021
00022 proxy_str_to_cid(servaddr.ID, argv[1]);
00023
00024 servaddr.port = htons(atoi(argv[2]));
00025 servaddr.IP = 0;
00026 servaddr.proxyIP = proxy_get_proxy_ip();
00027 servaddr.proxyPort = proxy_get_proxy_port();
00028
00029 sockfd = proxy_socket(AF_INET, SOCK_STREAM, 0);
00030
00031 if (proxy_connect(sockfd, &servaddr) < 0) {
00032 fprintf(stderr, "Error: could not connect.\n");
00033 exit(EXIT_FAILURE);
00034 }
00035
00036 str_cli(stdin, sockfd);
00037
00038 exit(EXIT_SUCCESS);
00039 }
00040
00041 void str_cli(FILE * fp, int sockfd)
00042 {
00043 char sendline[MAXLINE], recvline[MAXLINE];
00044
00045 while (fgets(sendline, MAXLINE, fp) != NULL) {
00046
00047 Writen(sockfd, sendline, strlen(sendline));
00048
00049 if (Readline(sockfd, recvline, MAXLINE) == 0) {
00050 fprintf(stderr, "str_cli: server terminated prematurely");
00051 return;
00052 }
00053
00054 fputs(recvline, stdout);
00055 }
00056 }