From owner-freebsd-hackers@FreeBSD.ORG Sat Jan 8 22:35:39 2005 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id E5A2316A4CE; Sat, 8 Jan 2005 22:35:39 +0000 (GMT) Received: from lara.cc.fer.hr (lara.cc.fer.hr [161.53.72.113]) by mx1.FreeBSD.org (Postfix) with ESMTP id 36E1B43D2D; Sat, 8 Jan 2005 22:35:39 +0000 (GMT) (envelope-from ivoras@fer.hr) Received: from [127.0.0.1] (localhost.cc.fer.hr [127.0.0.1]) by lara.cc.fer.hr (8.13.1/8.13.1) with ESMTP id j08MYv2i076352; Sat, 8 Jan 2005 23:34:58 +0100 (CET) (envelope-from ivoras@fer.hr) Message-ID: <41E06011.4050501@fer.hr> Date: Sat, 08 Jan 2005 23:34:57 +0100 From: Ivan Voras User-Agent: Mozilla Thunderbird 1.0 (X11/20041213) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Robert Watson , hackers@freebsd.org References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: Raw sockets problem? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 08 Jan 2005 22:35:40 -0000 Robert Watson wrote: > On Sat, 8 Jan 2005, Ivan Voras wrote: > > >> I've just noticed I can't create a raw socket on 5.3-RELEASE, while the >> same code works on 5.2. I get 'Protocol not supported' error on code >> like this: > > > > I've not got a 5.2 box on hand, but this appears not to work on 4.x. There isn't a domain handler for AF_LINK, so you shouldn't be able to > create a socket of that type, so if it was possible in 5.2, it was likely > a bug. I use it in this code: /* get interface name by index */ int cardif_get_int(int index, char *retInterface) { struct ifreq ifr; struct ifaddrs *ifa_master, *ifa; int sock, retval; char msg[100]; sock = socket(AF_LINK, SOCK_RAW, 0); if (sock < 0) { sprintf(msg, "cardif_get_int: cannot create raw socket: %s\n", strerror(errno)); debug_printf(DEBUG_NORMAL, msg); return XESOCKOP; } getifaddrs(&ifa_master); for (ifa = ifa_master; ifa != NULL; ifa = ifa->ifa_next) { strncpy(ifr.ifr_name, ifa->ifa_name, IFNAMSIZ); retval = ioctl(sock, SIOCGIFINDEX, &ifr); if (retval < 0) { debug_printf(DEBUG_NORMAL, "Error getting interface index value for interface %s\n", ifa->ifa_name); freeifaddrs(ifa_master); close(sock); return XESOCKOP; } if (ifr.ifr_index == index) break; } if (ifa == NULL) { debug_printf(DEBUG_NORMAL, "Cannot find interface name by its index: %d\n", index); freeifaddrs(ifa_master); close(sock); return XENOTINT; } strncpy(retInterface, ifa->ifa_name, IFNAMSIZ); freeifaddrs(ifa_master); close(sock); return XENONE; } --- i.e. I need it for the ioctl() call. Is there another way?