Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Raw socket
- SOCKET s = socket( AF_INET, SOCK_RAW, IPPROTO_IP );
- char name[ 256 ];
- hostent * pHE;
- sockaddr_in sa;
- gethostbyname( name ); // get the name of localhost
- pHE = gethostbyname( name ); // get info about localhost inc. the local IP
- ZeroMemory( &sa, sizeof( sockaddr_in ) );
- sa.sin_family = AF_INET;
- sa.sin_addr.s_addr = // fill the struct: the IP to bind to
- ( (in_addr *) // cast
- pHE->h_addr_list[ 0 ] // the first occurence
- ) -> s_addr; // it holds various info. We need the IP
- // then you bind() like this:
- bind( s, (SOCKADDR *) /* cast again */ &sa, sizeof( SOCKADDR ) )
- for(;; )
- {
- i /* how much received */ = recv( s, Buffer, sizeOfTheBuffer, 0 );
- if( i <= 0 )
- {
- // end of the game.
- }
- printf( "\n <<< A new packet has arrived >>>\n" );
- for( j = 0; j < i; j ++ )
- {
- if( (unsigned int) Buffer[ j ] >= 32 &&
- (unsigned int) Buffer[ j ] <= 126
- ) // if it's a writable char
- {
- putchar( Buffer[ j ] );
- }
- else
- {
- putchar( '?' );
- }
- }
- printf( "\n [End of Packet]\n" );
- }
Advertisement
Add Comment
Please, Sign In to add comment