ICMP_ECHO request/ raw socket

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,

 i wrote a simple program to use raw sockets and catch all
icmp packets.

// -- code snipped

       buf = (char*) malloc(sizeof(struct ip)+sizeof(struct icmp));

        sockfd = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP);

        for (;;) {
                n = recv(sockfd, buf, sizeof(buf),0);
                ip = (struct ip *) buf;
                ip_len = ip->ip_hl << 2; // ip header length

                icmp = (struct icmp *) (buf + ip_len);

                printf("n= %d\n",n);
                if (icmp->icmp_type == ICMP_ECHO) {
                        printf("ping request arrived\n");
                }
        }


It seems that the kernel donot pass ICMP_ECHO (icmp echo request) to raw
socket, so i can't get into the if check. It can get ICMP_ECHOREPLY
though.

I beleive this was the restriction in BSD Kernels only that they don't
pass ICMP_ECHO request (0x08) to matching raw socket? in linux, it was
allowed ?


Any help in this regard is appreciated.

-- basit




-
: send the line "unsubscribe linux-net" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux 802.1Q VLAN]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Git]     [Bugtraq]     [Yosemite News and Information]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux PCI]     [Linux Admin]     [Samba]

  Powered by Linux