/* * * ARPS 1.0 [ arp packets sender / shaping ] * * "THE BEER-WARE LICENSE" (by Poul-Henning Kamp, Revision 42) * emdel wrote this file. As long as you retain this notice * you can do whatever you want with this stuff. If we meet some day, and you * think this stuff is worth it, you can buy me a beer in return. * * emdel * */ #include #include #include #include #include #include #include #include #define INFO "Copyright (c) 2008 emdel " #define WHAT "ARPS 1.0 [ arp packets sender / shaping ]" void die( void ); int send_arp( libnet_t *handler, char *device, char *ip, u_short arptype ); int main( int argc, char **argv ) { int ret, i, v; int npacket; char *device; char *ip; libnet_t *handler; char err[LIBNET_ERRBUF_SIZE]; ret = getuid( ); if( ret != 0 ) { fprintf( stderr, "You must be root!\n" ); exit( 25 ); } if( argc != 4 ) { fprintf( stderr, "Usage %s < interface > < ip address > < number of packet > \n" , argv[0] ); exit( 25 ); } fprintf( stdout, "\n\t\t %s \n\n \t\t %s \n\n " , WHAT, INFO ); device = argv[1]; handler = libnet_init( LIBNET_LINK, device, err ); if( handler == NULL ) die( ); npacket = atoi( argv[3] ); ip = argv[2]; for( i = 0; i <= npacket; i++ ) { v = send_arp( handler, device, ip, ARPOP_REQUEST ); if( v < 0 ) printf("-1 -> error during the REQUEST sending\n"); else printf("0 -> success arp REQUEST!\n" ); /*v = send_arp( handler, device, ip, ARPOP_REPLY ); if( v < 0 ) printf("-1 -> error during the REPLY sending \n" ); else printf("0 -> success arp REPLY!\n" );*/ } libnet_destroy( handler ); return( v < 0 ? -1 : 0 ); } void die( void ) { fprintf( stderr, "An error occured\n" ); exit( 25 ); } int send_arp( libnet_t *handler, char *device, char *ip, u_short arptype ) { int r; in_addr_t ind; u_char src[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; u_char dst[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; ind = inet_addr( ip ); libnet_autobuild_arp( arptype, (u_int8_t *)ether_aton( ether_ntoa( ( struct ether_addr *)src ) ) , (u_int8_t *)&ind, (u_int8_t *)ether_aton( ether_ntoa( ( struct ether_addr *)dst ) ), (u_int8_t *)&ind, handler ); libnet_autobuild_ethernet( (u_int8_t *)ether_aton( ether_ntoa( ( struct ether_addr *)dst ) ), ETHERTYPE_ARP, handler ); r = libnet_write( handler ); fprintf( stdout, "ip_src: %s [ mac: %s ] --> ip_dst: %s [ mac: %s ]\n" , ip, ether_ntoa( ( struct ether_addr *)src ), ip, ether_ntoa( ( struct ether_addr *)src ) ); if( r == -1 ) printf( "fatal error %s\n" , strerror( errno ) ); return r; }