This is a discussion on Problem using sendto(...) with packet sockets? within the Linux Networking forums, part of the Linux Forums category; I tried the code below and while sendto(...) sends the data contained in buf, the 'to' address seems to be ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
I tried the code below and while sendto(...) sends the data contained
in buf, the 'to' address seems to be ignored. As a consequence the source and destination addresses + the packet type are taken to be the first 14 bytes of buf, resulting in a gibberish message. What's up? ---jski struct sockaddr_ll to; int tolen; char buf[ 512 ]; if ( ( s = socket( PF_PACKET, SOCK_RAW, htons( ETH_P_ALL ) ) ) == -1 ) { fprintf( stderr, "Line: %i, socket error: %s\n", __LINE__, strerror( errno ) ); } memset( &to, 0, sizeof( to ) ); for ( i = 0; i < 6; i++ ) to.sll_addr[ i ] = 0xff; to.sll_family = AF_PACKET; to.sll_ifindex = ifr.ifr_ifindex; to.sll_protocol = GEOCAST; tolen = sizeof( to ); for ( i = 0; i < 512; i++ ) buf[ i ] = (unsigned char) i; size = sendto( s, buf, 512, 0, (const struct sockaddr *)&to, tolen ); |