Problem using sendto(...) with packet sockets?

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 ...


Go Back   Usenet Forums > Linux Forums > Linux Networking

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-14-2008
jan.chludzinski@gmail.com
 
Posts: n/a
Default Problem using sendto(...) with packet sockets?

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 );
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 06:02 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0