Hello,

 I was trying to learn raw sockets, I wrote a simple program
to get all icmp packets and display ..

-- program

int
main(void)
{
        int             sockfd;
        int             ip_len;
        char            *buf;
        int             n;
        struct icmp    *icmp;
        struct ip      *ip;

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

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

-- end

The program compiles fine, but it can't recieve echo request , seems like
the BSD kernel is not passing icmp echo type requests to raw socket?

I beleive this is NOT the case in Linux, why this behaviour exists in BSD?
is there any way to circumvent this ?

Also, if anyone know any good tutorial on bpf , let me know the url (some
simple example for capturing will be good .. i read bpf manpage, it seems
little obscure to me).

-- basit
Graduate Stdudent
Dept. Of Computer science.
Wichita state university



To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-net" in the body of the message

Reply via email to