From owner-freebsd-net@FreeBSD.ORG Tue Jun 17 20:40:05 2003 Return-Path: Delivered-To: freebsd-net@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 9D55837B401 for ; Tue, 17 Jun 2003 20:40:05 -0700 (PDT) Received: from fledge.watson.org (fledge.watson.org [204.156.12.50]) by mx1.FreeBSD.org (Postfix) with ESMTP id C231443F93 for ; Tue, 17 Jun 2003 20:40:04 -0700 (PDT) (envelope-from robert@fledge.watson.org) Received: from fledge.watson.org (localhost [127.0.0.1]) by fledge.watson.org (8.12.9/8.12.9) with ESMTP id h5I3e2KJ001245; Tue, 17 Jun 2003 23:40:02 -0400 (EDT) (envelope-from robert@fledge.watson.org) Received: from localhost (robert@localhost)h5I3e2kQ001242; Tue, 17 Jun 2003 23:40:02 -0400 (EDT) (envelope-from robert@fledge.watson.org) Date: Tue, 17 Jun 2003 23:40:02 -0400 (EDT) From: Robert Watson X-Sender: robert@fledge.watson.org To: "akanwar@digitarchy.com" In-Reply-To: <184670-22003631813445521@M2W098.mail2web.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII cc: wollman@lcs.mit.edu cc: freebsd-net@freebsd.org Subject: RE: replacement for SOCK_PACKET X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 18 Jun 2003 03:40:05 -0000 On Tue, 17 Jun 2003, akanwar@digitarchy.com wrote: > I am trying to write a small program to send out gratituous arps > (because the em driver does not work) for a redundancy (via IP address > take over) scheme. Hmm. If you're having if_em bugs and haven't already submitted a PR, please do so. Our if_em maintainer is Prafulle Deuskar at Intel. > I do NOT want to use libpcap or libnet as these will not be available on > prodution servers. I could probably statically link and make a huge > executable...but then I think there ought to be a simpler way. If pcap is not available on your production FreeBSD servers, it's because you've removed it. BPF is the supported "link layer transmission" mechanism in most BSD-derived platforms. libpcap provides a portable library interface to BPF; pcap ports are available (and shipped with) many other OS implementations, including Linux. If you have tcpdump installed, which is common for many production installations, you likely have pcap. If you just want to bypass libpcap, open /dev/bpf%d directly, issue the necessary ioctl() to bind the interface (BIOCSETIF), possibly change the "header completion mode" (BIOCSHDRCMPLT), and write the packet to the BPF device. Here's a code fragment: do { sprintf(device, "/dev/bpf%d", n++); fd = open(device, O_RDWR); } while (fd < 0 && errno == EBUSY && n < 1000); if (fd < 0) { perror("open"); return (-1); } strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); if (ioctl(fd, BIOCSETIF, &ifr)) { perror("ioctl"); close(fd); return (-1); } if (ioctl(fd, BIOCGDLT, &data)) { perror("ioctl"); close(fd); return (-1); } if (data != DLT_EN10MB) { fprintf(stderr, "ioctl: invalid data link type\n"); close(fd); return (-1); } data = 1; if (ioctl(fd, BIOCSHDRCMPLT, &data)) { perror("ioctl"); close(fd); return (-1); } ... if (write(fd, pbuf, pbuflen) != pbuflen) ... Robert N M Watson FreeBSD Core Team, TrustedBSD Projects robert@fledge.watson.org Network Associates Laboratories