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

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

Post by jan.chludzin.. » Fri, 16 May 2008 00:13:35



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 );

 
 
 

1. Sending Raw packet using PF_PACKET and sendto -

Greetings!

I am trying to send a a raw packet - using PF_PACKET - I have referred
to everything online - manp pages -

My sendto funtion returns successful but I never see the packet - My
network drivers hard_xmit function doesnt recieve it - This is the
problem.
I dont know whats wrong.

I first create a socket using

sockfd= socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));

Then I set the Interface, protocol etc in the destination sockaddr_ll
structure -
and use the normal sendto ()

CAn some one pleeeeeeeeeeaseeeeee point out whats wrong - before I go
insane and lose my Job :(

I have the deluxe red hat 7.1 with the 2.4.2 kernel.

Thanks a million in Advance !

Regards,

Sunny

2. NV6000 V4.2.1 & AIX 4.3.1

3. Sending Arp reply packets using packet-sockets on linux

4. Help! "/dev/lp" - problem with the new HP660 Deskjet

5. Bug in sendto() causes OOPS when using RAW sockets

6. IS L2 CACHE USED BY LINUX

7. problem with ethernet loopback test using loopback plug/stub: receiving socket not seeing packet.

8. Resample/Resize JPG

9. QUESTION: How can I sendto() a UDP packet with a diff FROM IP?

10. Why failing sendto/send transmit complete datagram/packet anyway??

11. How to receive UDP and ICMP packet using one UDP socket, (Path MTUD)

12. Reading outbound packets to datalink layer using C sockets API - how?

13. Packet socket losing packets