X-Git-Url: https://git.ozlabs.org/?p=ppp.git;a=blobdiff_plain;f=pppd%2Fsys-linux.c;h=df5cebb55951cfa8960ee3f8f2686d9f9a8caa99;hp=fc309ad267d02b6ac4e3f66b56ecdf1733bd610e;hb=9f842088e30f4a2d8ad31a14f16370f917bcb389;hpb=b1fcf16fa66159f380ee4abd7c9a76b59809dc7b diff --git a/pppd/sys-linux.c b/pppd/sys-linux.c index fc309ad..df5cebb 100644 --- a/pppd/sys-linux.c +++ b/pppd/sys-linux.c @@ -625,7 +625,7 @@ void generic_disestablish_ppp(int dev_fd) * make_ppp_unit - make a new ppp unit for ppp_dev_fd. * Assumes new_style_driver. */ -static int make_ppp_unit() +static int make_ppp_unit(void) { int x, flags; @@ -1377,9 +1377,7 @@ int set_filters(struct bpf_program *pass, struct bpf_program *active) * get_idle_time - return how long the link has been idle. */ int -get_idle_time(u, ip) - int u; - struct ppp_idle *ip; +get_idle_time(int u, struct ppp_idle *ip) { return ioctl(ppp_dev_fd, PPPIOCGIDLE, ip) >= 0; } @@ -1389,9 +1387,7 @@ get_idle_time(u, ip) * get_ppp_stats - return statistics for the link. */ int -get_ppp_stats(u, stats) - int u; - struct pppd_stats *stats; +get_ppp_stats(int u, struct pppd_stats *stats) { struct ifpppstatsreq req; @@ -2105,10 +2101,43 @@ get_if_hwaddr(u_char *addr, char *name) * get_first_ethernet - return the name of the first ethernet-style * interface on this system. */ +static char first_ether_name[IF_NAMESIZE]; char * -get_first_ethernet() +get_first_ethernet(void) { - return "eth0"; + struct if_nameindex *if_ni, *i; + struct ifreq ifreq; + int ret, sock_fd; + + sock_fd = socket(AF_INET, SOCK_DGRAM, 0); + if (sock_fd < 0) + return NULL; + + if_ni = if_nameindex(); + if (!if_ni) { + close(sock_fd); + return NULL; + } + + first_ether_name[0] = 0; + + for (i = if_ni; !(i->if_index == 0 && i->if_name == NULL); i++) { + memset(&ifreq.ifr_hwaddr, 0, sizeof(struct sockaddr)); + strlcpy(ifreq.ifr_name, i->if_name, sizeof(ifreq.ifr_name)); + ret = ioctl(sock_fd, SIOCGIFHWADDR, &ifreq); + if (ret >= 0 && ifreq.ifr_hwaddr.sa_family == ARPHRD_ETHER) { + strlcpy(first_ether_name, i->if_name, sizeof(first_ether_name)); + break; + } + } + + if_freenameindex(if_ni); + close(sock_fd); + + if (!first_ether_name[0]) + return NULL; + + return first_ether_name; } /******************************************************************** @@ -2757,7 +2786,7 @@ int sif6addr (int unit, eui64_t our_eui64, eui64_t his_eui64) memset(&ifr6, 0, sizeof(ifr6)); IN6_LLADDR_FROM_EUI64(ifr6.ifr6_addr, our_eui64); ifr6.ifr6_ifindex = ifr.ifr_ifindex; - ifr6.ifr6_prefixlen = 10; + ifr6.ifr6_prefixlen = 128; if (ioctl(sock6_fd, SIOCSIFADDR, &ifr6) < 0) { error("sif6addr: ioctl(SIOCSIFADDR): %m (line %d)", __LINE__); @@ -2768,7 +2797,7 @@ int sif6addr (int unit, eui64_t our_eui64, eui64_t his_eui64) memset(&rt6, 0, sizeof(rt6)); IN6_LLADDR_FROM_EUI64(rt6.rtmsg_dst, his_eui64); rt6.rtmsg_flags = RTF_UP; - rt6.rtmsg_dst_len = 10; + rt6.rtmsg_dst_len = 128; rt6.rtmsg_ifindex = ifr.ifr_ifindex; rt6.rtmsg_metric = 1; @@ -2805,7 +2834,7 @@ int cif6addr (int unit, eui64_t our_eui64, eui64_t his_eui64) memset(&ifr6, 0, sizeof(ifr6)); IN6_LLADDR_FROM_EUI64(ifr6.ifr6_addr, our_eui64); ifr6.ifr6_ifindex = ifr.ifr_ifindex; - ifr6.ifr6_prefixlen = 10; + ifr6.ifr6_prefixlen = 128; if (ioctl(sock6_fd, SIOCDIFADDR, &ifr6) < 0) { if (errno != EADDRNOTAVAIL) { @@ -2826,11 +2855,7 @@ int cif6addr (int unit, eui64_t our_eui64, eui64_t his_eui64) * to the uid given. Assumes slave_name points to >= 16 bytes of space. */ int -get_pty(master_fdp, slave_fdp, slave_name, uid) - int *master_fdp; - int *slave_fdp; - char *slave_name; - int uid; +get_pty(int *master_fdp, int *slave_fdp, char *slave_name, int uid) { int i, mfd, sfd = -1; char pty_name[16]; @@ -2956,10 +2981,7 @@ open_ppp_loopback(void) */ int -sifnpmode(u, proto, mode) - int u; - int proto; - enum NPmode mode; +sifnpmode(int u, int proto, enum NPmode mode) { struct npioctl npi; @@ -3070,7 +3092,7 @@ int cipxfaddr (int unit) * Use the hostname as part of the random number seed. */ int -get_host_seed() +get_host_seed(void) { int h; char *p = hostname;