fix outgoing QOS prios
[tomato.git] / release / src / router / radvd / device-common.c
blob1a52200cae2f2ffb519f4058a27ebd14bbd73e5d
1 /*
2 * $Id: device-common.c,v 1.12 2011/02/06 03:41:38 reubenhwk Exp $
4 * Authors:
5 * Lars Fenneberg <lf@elemental.net>
7 * This software is Copyright 1996,1997 by the above mentioned author(s),
8 * All Rights Reserved.
10 * The license which is distributed with this software in the file COPYRIGHT
11 * applies to this software. If your distribution is missing this file, you
12 * may request it from <pekkas@netcore.fi>.
16 #include "config.h"
17 #include "includes.h"
18 #include "radvd.h"
19 #include "defaults.h"
21 int
22 check_device(struct Interface *iface)
24 struct ifreq ifr;
26 strncpy(ifr.ifr_name, iface->Name, IFNAMSIZ-1);
27 ifr.ifr_name[IFNAMSIZ-1] = '\0';
29 if (ioctl(sock, SIOCGIFFLAGS, &ifr) < 0)
31 if (!iface->IgnoreIfMissing)
32 flog(LOG_ERR, "ioctl(SIOCGIFFLAGS) failed for %s: %s",
33 iface->Name, strerror(errno));
34 return (-1);
37 if (!(ifr.ifr_flags & IFF_UP))
39 if (!iface->IgnoreIfMissing)
40 flog(LOG_ERR, "interface %s is not UP", iface->Name);
41 return (-1);
43 if (!(ifr.ifr_flags & IFF_RUNNING))
45 if (!iface->IgnoreIfMissing)
46 flog(LOG_ERR, "interface %s is not RUNNING", iface->Name);
47 return (-1);
50 if (! iface->UnicastOnly && !(ifr.ifr_flags & IFF_MULTICAST))
52 flog(LOG_WARNING, "interface %s does not support multicast",
53 iface->Name);
54 flog(LOG_WARNING, " do you need to add the UnicastOnly flag?");
57 if (! iface->UnicastOnly && !(ifr.ifr_flags & IFF_BROADCAST))
59 flog(LOG_WARNING, "interface %s does not support broadcast",
60 iface->Name);
61 flog(LOG_WARNING, " do you need to add the UnicastOnly flag?");
64 return 0;
67 int
68 get_v4addr(const char *ifn, unsigned int *dst)
70 struct ifreq ifr;
71 struct sockaddr_in *addr;
72 int fd;
74 if( ( fd = socket(AF_INET,SOCK_DGRAM,0) ) < 0 )
76 flog(LOG_ERR, "create socket for IPv4 ioctl failed for %s: %s",
77 ifn, strerror(errno));
78 return (-1);
81 memset(&ifr, 0, sizeof(ifr));
82 strncpy(ifr.ifr_name, ifn, IFNAMSIZ-1);
83 ifr.ifr_name[IFNAMSIZ-1] = '\0';
84 ifr.ifr_addr.sa_family = AF_INET;
86 if (ioctl(fd, SIOCGIFADDR, &ifr) < 0)
88 flog(LOG_ERR, "ioctl(SIOCGIFADDR) failed for %s: %s",
89 ifn, strerror(errno));
90 close( fd );
91 return (-1);
94 addr = (struct sockaddr_in *)(&ifr.ifr_addr);
96 dlog(LOG_DEBUG, 3, "IPv4 address for %s is %s", ifn,
97 inet_ntoa( addr->sin_addr ) );
99 *dst = addr->sin_addr.s_addr;
101 close( fd );
103 return 0;