Don't enable dnsmasq IPSET functionality on 2.4 kernel
[tomato.git] / release / src / router / radvd / device-common.c
blob4bcc9c98f4352aaa4b80d8db8cec384bb3c8a47f
1 /*
3 * Authors:
4 * Lars Fenneberg <lf@elemental.net>
6 * This software is Copyright 1996,1997 by the above mentioned author(s),
7 * All Rights Reserved.
9 * The license which is distributed with this software in the file COPYRIGHT
10 * applies to this software. If your distribution is missing this file, you
11 * may request it from <pekkas@netcore.fi>.
15 #include "config.h"
16 #include "includes.h"
17 #include "radvd.h"
18 #include "defaults.h"
20 int
21 check_device(struct Interface *iface)
23 struct ifreq ifr;
25 strncpy(ifr.ifr_name, iface->Name, IFNAMSIZ-1);
26 ifr.ifr_name[IFNAMSIZ-1] = '\0';
28 if (ioctl(sock, SIOCGIFFLAGS, &ifr) < 0)
30 if (!iface->IgnoreIfMissing)
31 flog(LOG_ERR, "ioctl(SIOCGIFFLAGS) failed for %s: %s",
32 iface->Name, strerror(errno));
33 return (-1);
36 if (!(ifr.ifr_flags & IFF_UP))
38 if (!iface->IgnoreIfMissing)
39 flog(LOG_ERR, "interface %s is not UP", iface->Name);
40 return (-1);
42 if (!(ifr.ifr_flags & IFF_RUNNING))
44 if (!iface->IgnoreIfMissing)
45 flog(LOG_ERR, "interface %s is not RUNNING", iface->Name);
46 return (-1);
49 if (! iface->UnicastOnly && !(ifr.ifr_flags & IFF_MULTICAST))
51 flog(LOG_WARNING, "interface %s does not support multicast",
52 iface->Name);
53 flog(LOG_WARNING, " do you need to add the UnicastOnly flag?");
56 if (! iface->UnicastOnly && !(ifr.ifr_flags & IFF_BROADCAST))
58 flog(LOG_WARNING, "interface %s does not support broadcast",
59 iface->Name);
60 flog(LOG_WARNING, " do you need to add the UnicastOnly flag?");
63 return 0;
66 int
67 get_v4addr(const char *ifn, unsigned int *dst)
69 struct ifreq ifr;
70 struct sockaddr_in *addr;
71 int fd;
73 if( ( fd = socket(AF_INET,SOCK_DGRAM,0) ) < 0 )
75 flog(LOG_ERR, "create socket for IPv4 ioctl failed for %s: %s",
76 ifn, strerror(errno));
77 return (-1);
80 memset(&ifr, 0, sizeof(ifr));
81 strncpy(ifr.ifr_name, ifn, IFNAMSIZ-1);
82 ifr.ifr_name[IFNAMSIZ-1] = '\0';
83 ifr.ifr_addr.sa_family = AF_INET;
85 if (ioctl(fd, SIOCGIFADDR, &ifr) < 0)
87 flog(LOG_ERR, "ioctl(SIOCGIFADDR) failed for %s: %s",
88 ifn, strerror(errno));
89 close( fd );
90 return (-1);
93 addr = (struct sockaddr_in *)(&ifr.ifr_addr);
95 dlog(LOG_DEBUG, 3, "IPv4 address for %s is %s", ifn,
96 inet_ntoa( addr->sin_addr ) );
98 *dst = addr->sin_addr.s_addr;
100 close( fd );
102 return 0;