* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
#include <limits.h>
#include <stdio.h>
#include <stddef.h>
#include <sys/ethernet.h>
#endif
+#ifdef PPP_FILTER
+#include <pcap.h>
+#endif
+
#include "pppd.h"
#include "fsm.h"
#include "lcp.h"
#endif /* defined(INET6) && defined(SOL2) */
-#if defined(INET6) && defined(SOL2)
-static char first_ether_name[LIFNAMSIZ]; /* Solaris 8 and above */
-#else
-static char first_ether_name[IFNAMSIZ]; /* Before Solaris 8 */
+#if !defined(INET6) || !defined(SOL2)
#define MAXIFS 256 /* Max # of interfaces */
#endif /* defined(INET6) && defined(SOL2) */
static int get_hw_addr_dlpi(char *, struct sockaddr *);
static int dlpi_attach(int, int);
static int dlpi_info_req(int);
-static int dlpi_get_reply(int, union DL_primitives *, int, int);
+static int dlpi_get_reply(int, union DL_primitives *, int, size_t);
static int strioctl(int, int, void *, int, int);
#ifdef SOL2
#if defined(SOL2) && defined(INET6)
/*
- * get_first_ethernet - returns the first Ethernet interface name found in
- * the system, or NULL if none is found
+ * get_first_ether_hwaddr - get the hardware address for the first
+ * ethernet-style interface on this system.
*
* NOTE: This is the lifreq version (Solaris 8 and above)
*/
-char *
-get_first_ethernet(void)
+int
+get_first_ether_hwaddr(u_char *addr)
{
struct lifnum lifn;
struct lifconf lifc;
fd = socket(AF_INET, SOCK_DGRAM, 0);
if (fd < 0) {
- return 0;
+ return -1;
}
/*
if (ioctl(fd, SIOCGLIFNUM, &lifn) < 0) {
close(fd);
error("could not determine number of interfaces: %m");
- return 0;
+ return -1;
}
num_ifs = lifn.lifn_count;
if (req == NULL) {
close(fd);
error("out of memory");
- return 0;
+ return -1;
}
/*
close(fd);
free(req);
error("SIOCGLIFCONF: %m");
- return 0;
+ return -1;
}
/*
memset(&lifr, 0, sizeof(lifr));
strncpy(lifr.lifr_name, plifreq->lifr_name, sizeof(lifr.lifr_name));
if (ioctl(fd, SIOCGLIFFLAGS, &lifr) < 0) {
- close(fd);
- free(req);
error("SIOCGLIFFLAGS: %m");
- return 0;
+ break;
}
fl = lifr.lifr_flags;
!= (IFF_UP | IFF_BROADCAST))
continue;
+ if (get_if_hwaddr(addr, lifr.lifr_name) < 0)
+ continue;
+
found = 1;
break;
}
free(req);
close(fd);
- if (found) {
- strncpy(first_ether_name, lifr.lifr_name, sizeof(first_ether_name));
- return (char *)first_ether_name;
- } else
- return NULL;
+ if (found)
+ return 0;
+ else
+ return -1;
}
#else
/*
- * get_first_ethernet - returns the first Ethernet interface name found in
- * the system, or NULL if none is found
+ * get_first_ether_hwaddr - get the hardware address for the first
+ * ethernet-style interface on this system.
*
* NOTE: This is the ifreq version (before Solaris 8).
*/
-char *
-get_first_ethernet(void)
+int
+get_first_ether_hwaddr(u_char *addr)
{
struct ifconf ifc;
struct ifreq *pifreq;
fd = socket(AF_INET, SOCK_DGRAM, 0);
if (fd < 0) {
- return 0;
+ return -1;
}
/*
if (req == NULL) {
close(fd);
error("out of memory");
- return 0;
+ return -1;
}
/*
close(fd);
free(req);
error("SIOCGIFCONF: %m");
- return 0;
+ return -1;
}
/*
memset(&ifr, 0, sizeof(ifr));
strncpy(ifr.ifr_name, pifreq->ifr_name, sizeof(ifr.ifr_name));
if (ioctl(fd, SIOCGIFFLAGS, &ifr) < 0) {
- close(fd);
- free(req);
error("SIOCGIFFLAGS: %m");
- return 0;
+ break;
}
fl = ifr.ifr_flags;
!= (IFF_UP | IFF_BROADCAST))
continue;
+ if (get_if_hwaddr(addr, ifr.ifr_name) < 0)
+ continue;
+
found = 1;
break;
}
free(req);
close(fd);
- if (found) {
- strncpy(first_ether_name, ifr.ifr_name, sizeof(first_ether_name));
- return (char *)first_ether_name;
- } else
- return NULL;
+ if (found)
+ return 0;
+ else
+ return -1;
}
#endif /* defined(SOL2) && defined(INET6) */
error("ioctl(SIOCGIFMTU): %m (line %d)", __LINE__);
return 0;
}
- return ifr.ifr_mtu;
+ return ifr.ifr_metric;
}
/*
return 1;
}
-#if 0
-/*
- * set_filters - transfer the pass and active filters to the kernel.
- */
-int
-set_filters(struct bpf_program *pass, struct bpf_program *active)
-{
- int ret = 1;
-
- if (pass->bf_len > 0) {
- if (strioctl(pppfd, PPPIO_PASSFILT, pass,
- sizeof(struct bpf_program), 0) < 0) {
- error("Couldn't set pass-filter in kernel: %m");
- ret = 0;
- }
- }
- if (active->bf_len > 0) {
- if (strioctl(pppfd, PPPIO_ACTIVEFILT, active,
- sizeof(struct bpf_program), 0) < 0) {
- error("Couldn't set active-filter in kernel: %m");
- ret = 0;
- }
- }
- return ret;
-}
-#endif
-
/*
* ccp_fatal_error - returns 1 if decompression was disabled as a
* result of an error detected after decompression of a packet,
}
static int
-dlpi_get_reply(int fd, union DL_primitives *reply, int expected_prim, maxlen)
+dlpi_get_reply(int fd, union DL_primitives *reply, int expected_prim, size_t maxlen)
{
struct strbuf buf;
int flags, n;