Advertisement
Guest User

Client

a guest
Dec 11th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.03 KB | None | 0 0
  1. #define _GNU_SOURCE
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <signal.h>
  6. #include <unistd.h>
  7. #include <sys/types.h>
  8. #include <sys/socket.h>
  9. #include <netdb.h>
  10. #include <netinet/in.h>
  11. #include <arpa/inet.h>
  12.  
  13. char sendbuff[1024];
  14. char getbuff[1024];
  15. int newsocket = 0;
  16. uint16_t prt       = 9345;
  17.  
  18. int main( void )
  19. {
  20.     struct sockaddr_in serv_addr;
  21.     struct hostent *hp;
  22.     if( ( newsocket=socket(AF_INET, SOCK_STREAM,0 ) ) < 0 )
  23.     {
  24.         printf( "ERROR: can't create socket" );
  25.     }
  26.  
  27.     hp = gethostbyname( "192.168.0.103" );
  28.     memcpy( &serv_addr.sin_addr, hp->h_addr_list[0], (size_t)hp->h_length );
  29.     serv_addr.sin_family = AF_INET;
  30.     serv_addr.sin_port   = htons( prt) ;
  31.  
  32.     while( connect( newsocket,( struct sockaddr*  )&serv_addr, sizeof( serv_addr ) ) < 0 )
  33.     {
  34.         perror( "ERROR%" );
  35.         sleep( 3 );
  36.     }
  37.     memset( getbuff,'\0',sizeof ( getbuff ) );
  38.     recv( newsocket, getbuff, sizeof( getbuff ), 0 );
  39.     printf( "test%s\n",getbuff );
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement