Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 5 Jan 2003 05:31:35 -0600 (CST)
From:      Abdul Basit <basit@basit.cc>
To:        net@freebsd.org
Subject:   raw socket/icmp-echo
Message-ID:  <20030105052449.K49935-100000@wireless.cs.twsu.edu>

next in thread | raw e-mail | index | archive | help

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 majordomo@FreeBSD.org
with "unsubscribe freebsd-net" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030105052449.K49935-100000>