X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=networking%2Fether-wake.c;h=e205ffc00073adca716ba4dad25eb78b8d22a7a1;hb=52933d47bd86d6d992f7290fad93d63b53f7a15f;hp=b4fb0c2d1c737205e4c3cf677899c51bd4dbbbd6;hpb=dac7ff15b7d32deeeef3d9665744fc5774c21d70;p=oweals%2Fbusybox.git diff --git a/networking/ether-wake.c b/networking/ether-wake.c index b4fb0c2d1..e205ffc00 100644 --- a/networking/ether-wake.c +++ b/networking/ether-wake.c @@ -65,25 +65,10 @@ */ -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include #include #include -#include #include - -#ifdef __linux__ #include -#endif #include "busybox.h" @@ -93,10 +78,10 @@ */ #ifdef PF_PACKET # define whereto_t sockaddr_ll -# define make_socket() bb_xsocket(PF_PACKET, SOCK_RAW, 0) +# define make_socket() xsocket(PF_PACKET, SOCK_RAW, 0) #else # define whereto_t sockaddr -# define make_socket() bb_xsocket(AF_INET, SOCK_PACKET, SOCK_PACKET) +# define make_socket() xsocket(AF_INET, SOCK_PACKET, SOCK_PACKET) #endif #ifdef DEBUG @@ -107,7 +92,7 @@ void bb_debug_dump_packet(unsigned char *outpack, int pktsize) printf("packet dump:\n"); for (i = 0; i < pktsize; ++i) { printf("%2.2x ", outpack[i]); - if (i % 20 == 19) printf("\n"); + if (i % 20 == 19) puts(""); } printf("\n\n"); } @@ -120,7 +105,7 @@ static inline void get_dest_addr(const char *arg, struct ether_addr *eaddr); static inline int get_fill(unsigned char *pkt, struct ether_addr *eaddr, int broadcast); static inline int get_wol_pw(const char *ethoptarg, unsigned char *wol_passwd); -int etherwake_main(int argc, char *argv[]) +int ether_wake_main(int argc, char *argv[]) { char *ifname = "eth0", *pass = NULL; unsigned long flags; @@ -135,7 +120,7 @@ int etherwake_main(int argc, char *argv[]) struct whereto_t whereto; /* who to wake up */ /* handle misc user options */ - flags = bb_getopt_ulflags(argc, argv, "bi:p:", &ifname, &pass); + flags = getopt32(argc, argv, "bi:p:", &ifname, &pass); if (optind == argc) bb_show_usage(); if (pass) @@ -145,7 +130,7 @@ int etherwake_main(int argc, char *argv[]) s = make_socket(); /* now that we have a raw socket we can drop root */ - setuid(getuid()); + xsetuid(getuid()); /* look up the dest mac address */ get_dest_addr(argv[optind], &eaddr); @@ -160,7 +145,7 @@ int etherwake_main(int argc, char *argv[]) { struct ifreq if_hwaddr; - strcpy(if_hwaddr.ifr_name, ifname); + strncpy(if_hwaddr.ifr_name, ifname, sizeof(if_hwaddr.ifr_name)); if (ioctl(s, SIOCGIFHWADDR, &if_hwaddr) < 0) bb_perror_msg_and_die("SIOCGIFHWADDR on %s failed", ifname); @@ -190,8 +175,7 @@ int etherwake_main(int argc, char *argv[]) /* This is necessary for broadcasts to work */ if (flags /*& 1 [OPT_BROADCAST]*/) { - int one = 1; - if (setsockopt(s, SOL_SOCKET, SO_BROADCAST, (void *)&one, sizeof(one)) < 0) + if (setsockopt_broadcast(s) < 0) bb_perror_msg("SO_BROADCAST"); } @@ -285,7 +269,7 @@ static inline int get_wol_pw(const char *ethoptarg, unsigned char *wol_passwd) byte_cnt = sscanf(ethoptarg, "%d.%d.%d.%d", &passwd[0], &passwd[1], &passwd[2], &passwd[3]); if (byte_cnt < 4) { - bb_error_msg("Unable to read the Wake-On-LAN pass"); + bb_error_msg("cannot read Wake-On-LAN pass"); return 0; }