Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _GNU_SOURCE
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <signal.h>
- #include <unistd.h>
- #include <sys/types.h>
- #include <sys/socket.h>
- #include <netdb.h>
- #include <netinet/in.h>
- #include <arpa/inet.h>
- char sendbuff[1024];
- char getbuff[1024];
- int newsocket = 0;
- uint16_t prt = 9345;
- int main( void )
- {
- struct sockaddr_in serv_addr;
- struct hostent *hp;
- if( ( newsocket=socket(AF_INET, SOCK_STREAM,0 ) ) < 0 )
- {
- printf( "ERROR: can't create socket" );
- }
- hp = gethostbyname( "192.168.0.103" );
- memcpy( &serv_addr.sin_addr, hp->h_addr_list[0], (size_t)hp->h_length );
- serv_addr.sin_family = AF_INET;
- serv_addr.sin_port = htons( prt) ;
- while( connect( newsocket,( struct sockaddr* )&serv_addr, sizeof( serv_addr ) ) < 0 )
- {
- perror( "ERROR%" );
- sleep( 3 );
- }
- memset( getbuff,'\0',sizeof ( getbuff ) );
- recv( newsocket, getbuff, sizeof( getbuff ), 0 );
- printf( "test%s\n",getbuff );
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement