X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=pppd%2Fsys-linux.c;h=df5cebb55951cfa8960ee3f8f2686d9f9a8caa99;hb=431469a02ce74e5fe4b9943e86b9bfc272882fcb;hp=f38210a4720556cf53784008850dcc4858e4fb67;hpb=505ec5cbd15ec23ed84282462ae9e451a1978133;p=ppp.git diff --git a/pppd/sys-linux.c b/pppd/sys-linux.c index f38210a..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; } /******************************************************************** @@ -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;