Qshell Interpreter (qsh) - FTP Directory Listing - IBM
Qshell Interpreter (qsh) - FTP Directory Listing - IBM
Qshell Interpreter (qsh) - FTP Directory Listing - IBM
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
} /* End of switch */<br />
} /* End of while */<br />
/* Convert a dotted decimal address to a 32-bit IP address. */<br />
hostname = argv[optind];<br />
ip_addr = inet_addr(hostname);<br />
/* When inet_addr() returns -1 we'll assume the user specified<br />
a host name. */<br />
if (ip_addr == -1) {<br />
/* Try to find the host by name. */<br />
host_p = gethostbyname(hostname);<br />
if (host_p) {<br />
memcpy(&ip_addr, host_p->h_addr, host_p->h_length);<br />
sysname = host_p->h_name;<br />
}<br />
else {<br />
fprintf(stderr, “<strong>qsh</strong>c: Could not find host %s\n”, hostname);<br />
exit(1);<br />
}<br />
} /* End of if */<br />
/* The user specified a IP address. */<br />
else {<br />
/* Try to find the host by address. */<br />
host_addr.s_addr = ip_addr;<br />
host_p = gethostbyaddr((char *)&host_addr.s_addr, sizeof(host_addr),<br />
AF_INET);<br />
if (host_p) {<br />
sysname = host_p->h_name;<br />
}<br />
else {<br />
fprintf(stderr, “<strong>qsh</strong>c: Could not find host %s\n”, hostname);<br />
exit(1);<br />
}<br />
} /* End of else */<br />
/********************************************************************/<br />
/* Connect to the <strong>qsh</strong> server on the specified system. */<br />
/********************************************************************/<br />
/* Create a socket. */<br />
if ((sd = socket(AF_INET, SOCK_STREAM, IPPROTO_IP)) < 0) {<br />
perror(“<strong>qsh</strong>c: socket() failed”);<br />
exit(1);<br />
}<br />
/* Connect to the <strong>qsh</strong> server on the specified AS/400. */<br />
memset(&svr_addr, '\0', sizeof(svr_addr));<br />
svr_addr.sin_family = AF_INET;<br />
svr_addr.sin_port = htons(port);<br />
svr_addr.sin_addr.s_addr = ip_addr;<br />
if (connect(sd, (struct sockaddr *)&svr_addr, sizeof(svr_addr)) != 0) {<br />
perror(“<strong>qsh</strong>c: connect() failed”);<br />
exit(1);<br />
}<br />
/********************************************************************/<br />
/* Send the user name and password to the server. */<br />
/********************************************************************/<br />
/* Allocate buffers for translating input and output. */<br />
ascii_buf = (char *)malloc(DEFAULT_BUF);<br />
memset(ascii_buf, '\0', DEFAULT_BUF);<br />
ebcdic_buf = (char *)malloc(DEFAULT_BUF);<br />
memset(ebcdic_buf, '\0', DEFAULT_BUF);<br />
ascii_user = ascii_buf;<br />
ascii_pwd = ascii_buf + 100;<br />
ebcdic_user = ebcdic_buf;<br />
ebcdic_pwd = ebcdic_buf + 100;<br />
/* Prompt the user for the user name and password. */<br />
if (nflag) {<br />
printf(“Enter user name: ”);<br />
gets(ascii_user);<br />
ascii_pwd = getpass(“Enter password: ”);<br />
Chapter 6. Remote client examples 129