IP header in Raw socket

IP header in Raw socket

Post by Sapan J Bhati » Thu, 12 Aug 1999 04:00:00



I had set up an ICMP ping server with an IPPROTO_ICMP raw
socket. After hours of frustation, I found that along with
an ICMP header (before it) I was getting an IP header too.

IS there any way of avoiding this? Also, if I set up a
RAW_SOCKET server with IPPROTO_IP, will it strip the IP
header before giving me the packet? Also, again, is there
any way of avoiding the IP header?

TIA
Sapan

* Sent from RemarQ http://www.remarq.com The Internet's Discussion Network *
The fastest and easiest way to search and participate in Usenet - Free!

 
 
 

IP header in Raw socket

Post by Andi Klee » Fri, 13 Aug 1999 04:00:00



Quote:> I had set up an ICMP ping server with an IPPROTO_ICMP raw
> socket. After hours of frustation, I found that along with
> an ICMP header (before it) I was getting an IP header too.

> IS there any way of avoiding this? Also, if I set up a
> RAW_SOCKET server with IPPROTO_IP, will it strip the IP
> header before giving me the packet? Also, again, is there
> any way of avoiding the IP header?

It is not clear what you use, but unless you enable IP_HDRINCL
or use IPPROTO_RAW as protocol, raw sockets don't give you an IP header.

rawsk = socket(PF_INET, SOCK_RAW, IPPROTO_ICMP);

-Andi
--
This is like TV. I don't like TV.

 
 
 

1. Incorrect IP header data in RAW Sockets

Hi,

I am using RAW sockets (Solaris 8) to send out a VRRP protocol packet
out to a multicast group. For some reason, I am not seeing the IP
header information that I am sending out. Instead I see TTL = 1,
Protocol=2 and etc. Can someone help me out in identifying the likely
problem in this code?

int vrrp_send_pkt( vrrp_rt *vsrv, char *buffer, int buflen )
{
        struct sockaddr_in from;
        int     len;
        int     fd = socket(AF_INET, SOCK_RAW, IPPROTO_RAW);

        if( fd < 0 ){
                perror( "socket" );
                return -1;
        }
        int on = 1;
        int geton = 1;
        int retSetSock = setsockopt(fd, IPPROTO_IP, IP_HDRINCL, &on,
sizeof(on));

        char lBuffer[72];
        struct ip ip;
        struct udphdr udphdr;

        ip.ip_hl                = 5;
        ip.ip_v = 4;
        ip.ip_tos               = 0;
        ip.ip_len       = ip.ip_hl*4 + vrrp_hd_len( vsrv );
        ip.ip_len       = htons(ip.ip_len);
        ip.ip_id                = ++ip_id;
        ip.ip_off       = 0;
        ip.ip_ttl               = VRRP_IP_TTL;
        ip.ip_p = IPPROTO_VRRP;
        ip.ip_src.s_addr = htonl(vsrv->vif.ipaddr);
        ip.ip_dst.s_addr        = htonl(INADDR_VRRP_GROUP);
        /* checksum must be done last */
        ip.ip_sum       = in_csum( (u_short*)(&ip), ip.ip_hl*4, 0 );

        memcpy(lBuffer+sizeof(ip), &udphdr, sizeof(udphdr));
        /* build the address */
        memset( &from, 0 , sizeof(from));
        //strcpy( from.sa_data, vsrv->vif.ifname );
        /* send the data */
        from.sin_family = AF_INET;
        from.sin_addr.s_addr=inet_addr("224.0.0.18");
        from.sin_port=htonl(5000);
        len = sendto( fd, &ip, 40, 0, (struct sockaddr *) &from,
sizeof(from) );
printf("len=%d\n",len);
        close( fd );
        return len;

Thanks,
Devender

2. NFS Problems

3. raw sockets, IP header

4. HELP: Cyclades board (Cyclom 8Yo) and Modems

5. Calling conventions/register use?

6. raw IP and raw ICMP socket???

7. lspv is not showing all hdisks in rootvg!

8. IP Checksum in Raw Sockets

9. Linux Raw Socket for IP Multicast

10. IP_HDRINCL Option for raw IP sockets

11. PATCH for Multicast bug in RAW IP sockets 2.4.0

12. Raw IP socket on Digital Unix