Hax4Us

Untitled

Sep 8th, 2018
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <sys/socket.h>
  3. #include <string.h>
  4. #include <arpa/inet.h>
  5. #include <netinet/in.h>
  6. #include <unistd.h>
  7. #include <netdb.h>
  8. #define MAX 1024
  9. #define PORT 19955
  10. int main(void){
  11.  
  12. int sockfd, status;
  13. char serverMsg[MAX]={0},clientMsg[MAX]={0};
  14. struct addrinfo hints,*res,*p;
  15. hints.ai_family=AF_UNSPEC;
  16. hints.ai_socktype=SOCK_STREAM;
  17.  
  18. if((status=getaddrinfo("0.tcp.ngrok.io","19955",&hints,&res))!=0){
  19. fprintf(stderr,"getaddrinfo : %s",gai_strerror(status)); return -1;}
  20.  
  21. for(p=res;p!=NULL;p=p->ai_next){
  22. if((sockfd=socket(p->ai_family,p->ai_socktype,p->ai_protocol))<0){
  23. printf("socket() failed");
  24. continue;}
  25.  
  26. if(connect(sockfd,p->ai_addr,p->ai_addrlen)<0){
  27. printf("Con() Failed");
  28. close(sockfd);
  29. sockfd=-1;
  30. continue;}
  31.  
  32. break; // we have correct IP now break the loop
  33. }
  34.  
  35. if(sockfd<0){
  36. printf("try again !");
  37. return -1;}
  38.  
  39. int pid=fork();
  40. if(pid==0){
  41. while(1){
  42. read(sockfd,serverMsg,MAX);
  43. if(strlen(serverMsg)>1){
  44. printf("Server : %s\n",serverMsg);
  45. puts("type something ...");
  46. }
  47. }
  48. }
  49. else{
  50. while(1){
  51. printf("type msg here ... ");
  52. fgets(clientMsg,MAX,stdin);
  53. send(sockfd,clientMsg,strlen(clientMsg)+1,0);
  54. }
  55. }
  56. }
Add Comment
Please, Sign In to add comment