2 * $Id: device-common.c,v 1.12 2011/02/06 03:41:38 reubenhwk Exp $
5 * Lars Fenneberg <lf@elemental.net>
7 * This software is Copyright 1996,1997 by the above mentioned author(s),
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>.
22 check_device(struct Interface
*iface
)
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
));
37 if (!(ifr
.ifr_flags
& IFF_UP
))
39 if (!iface
->IgnoreIfMissing
)
40 flog(LOG_ERR
, "interface %s is not UP", iface
->Name
);
43 if (!(ifr
.ifr_flags
& IFF_RUNNING
))
45 if (!iface
->IgnoreIfMissing
)
46 flog(LOG_ERR
, "interface %s is not RUNNING", iface
->Name
);
50 if (! iface
->UnicastOnly
&& !(ifr
.ifr_flags
& IFF_MULTICAST
))
52 flog(LOG_WARNING
, "interface %s does not support multicast",
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",
61 flog(LOG_WARNING
, " do you need to add the UnicastOnly flag?");
68 get_v4addr(const char *ifn
, unsigned int *dst
)
71 struct sockaddr_in
*addr
;
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
));
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
));
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
;