Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 08 Jan 2005 23:34:57 +0100
From:      Ivan Voras <ivoras@fer.hr>
To:        Robert Watson <rwatson@freebsd.org>, hackers@freebsd.org
Subject:   Re: Raw sockets problem?
Message-ID:  <41E06011.4050501@fer.hr>
In-Reply-To: <Pine.NEB.3.96L.1050108172415.43829E-100000@fledge.watson.org>
References:  <Pine.NEB.3.96L.1050108172415.43829E-100000@fledge.watson.org>

next in thread | previous in thread | raw e-mail | index | archive | help
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?




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?41E06011.4050501>