Hello,
I am new to c and need help with a current program I am working on.
Currently, the program (code below) input is as follows:
program apple.test.com 51112
What I need is (essentially three arguments with a ':' space between the hostname and port number, and a third argument):
program apple.test.com:51112 usr/bin/test
where:
apple.test.com is argv[1]
51112 is argv[2]
usr/bing/test is argv[3]
Thanks guys.
Here is a bit of the current client file which needs to be modified.
________________________________________
int main(int argc, char *argv[])
{
int sockfd, portno, n;
struct sockaddr_in serv_addr;
struct hostent *server;
char buffer[256];
// get proper number of input arguments before proceeding
if (argc != 3) {
fprintf(stderr,"usage %s <hostname> <port>\n", argv[0]);
exit(0);
}
portno = atoi(argv[2]);
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd < 0)
error("ERROR opening socket");
server = gethostbyname(argv[1]);
if (server == NULL) {
fprintf(stderr,"ERROR, no such host\n");
exit(0);
}