commancli.c 605 B

1234567891011121314151617181920212223242526272829
  1. #include<stdio.h>
  2. #include<unistd.h>
  3. #include<sys/socket.h>
  4. #include<sys/types.h>
  5. #include<netinet/in.h>
  6. #include<string.h>
  7. #include<stdlib.h>
  8. int main()
  9. {
  10. int sd,port;
  11. char msg[80];
  12. struct sockaddr_in cli;
  13. sd=socket(AF_INET,SOCK_STREAM,0);
  14. bzero(&cli,sizeof(cli));
  15. printf("enter the port no");
  16. scanf("%d",&port);
  17. cli.sin_port=port;
  18. cli.sin_addr.s_addr=inet_addr("127.0.0.1");
  19. cli.sin_family=AF_INET;
  20. connect(sd,(struct sockaddr*)&cli,sizeof(cli));
  21. printf("\nenter the command\n");
  22. scanf("%s",msg);
  23. write(sd,msg,strlen(msg));
  24. system(msg);
  25. read(sd,msg,10);
  26. printf("%s",msg);
  27. return 0;
  28. }