--- embedaddon/mpd/src/util.c 2016/11/01 09:56:12 1.1.1.3 +++ embedaddon/mpd/src/util.c 2021/03/17 00:39:23 1.1.1.4 @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -80,13 +81,13 @@ static const u_int16_t Crc16Table[256] = { */ static void Escape(char *line); - static char *ReadLine(FILE *fp, int *lineNum, char *result, int resultsize); + static char *ReadLine(FILE *fp, int *lineNum, char *result, size_t resultsize); static char HexVal(char c); static void IndexConfFile(FILE *fp, struct configfile **cf); - struct configfiles *ConfigFilesIndex=NULL; + static struct configfiles *ConfigFilesIndex=NULL; #undef isspace #define isspace(c) (((c)==' '||(c)=='\t'||(c)=='\n'||(c)=='\r')?1:0) @@ -118,8 +119,8 @@ int ExecCmd(int log, const char *label, const char *fmt, ...) { int rtn; - char cmd[BIG_LINE_SIZE]; - char cmdn[BIG_LINE_SIZE]; + char cmd[LINE_MAX]; + char cmdn[LINE_MAX]; va_list ap; va_start(ap, fmt); @@ -153,7 +154,7 @@ int ExecCmdNosh(int log, const char *label, const char *fmt, ...) { int rtn; - char cmd[BIG_LINE_SIZE]; + char cmd[LINE_MAX]; char *cmdp = &(cmd[0]); char *argv[256]; char **arg; @@ -378,7 +379,7 @@ Escape(char *line) int ReadFile(const char *filename, const char *target, - int (*func)(Context ctx, int ac, char *av[], const char *file, int line), Context ctx) + int (*func)(Context ctx, int ac, const char *const av[], const char *file, int line), Context ctx) { FILE *fp; int ac; @@ -409,7 +410,7 @@ ReadFile(const char *filename, const char *target, break; } ac = ParseLine(line, av, sizeof(av) / sizeof(*av), 0); - (*func)(ctx, ac, av, filename, lineNum); + (*func)(ctx, ac, (const char *const *)av, filename, lineNum); } /* Done */ @@ -558,7 +559,8 @@ OpenConfFile(const char *name, struct configfile **cf) char * ReadFullLine(FILE *fp, int *lineNum, char *result, int resultsize) { - int len, linelen, resultlinesize, continuation; + int len, resultlinesize, continuation; + unsigned linelen; char line[BIG_LINE_SIZE]; char real_line[BIG_LINE_SIZE]; char *resultline; @@ -626,7 +628,7 @@ ReadFullLine(FILE *fp, int *lineNum, char *result, int */ static char * -ReadLine(FILE *fp, int *lineNum, char *result, int resultsize) +ReadLine(FILE *fp, int *lineNum, char *result, size_t resultsize) { int empty; char *s; @@ -1050,7 +1052,7 @@ ShowMesg(int log, const char *pref, const char *buf, i if (len > 0) { - if (len > sizeof(mesg) - 1) + if (len > (int)(sizeof(mesg) - 1)) len = sizeof(mesg) - 1; memcpy(mesg, buf, len); mesg[len] = 0; @@ -1093,7 +1095,7 @@ Bin2Hex(const unsigned char *bin, size_t len) u_char * Hex2Bin(char *hexstr) { - int i; + unsigned i; u_char *binval; binval = Malloc(MB_UTIL, strlen(hexstr) / 2); @@ -1176,7 +1178,7 @@ GetAnyIpAddress(struct u_addr *ipaddr, const char *ifn close(s); return(-1); } - ipa = ((struct sockaddr_in *)&ifreq.ifr_ifru.ifru_addr)->sin_addr; + ipa = ((struct sockaddr_in *)(void *)&ifreq.ifr_ifru.ifru_addr)->sin_addr; if ((ntohl(ipa.s_addr)>>24) == 127) ipa.s_addr = 0; /* We don't like 127.0.0.1 */ } @@ -1196,7 +1198,7 @@ GetAnyIpAddress(struct u_addr *ipaddr, const char *ifn } /* if used size is too close to allocated size retry with a larger buffer */ - if (ifc.ifc_len + 128 < buffsize) + if ((unsigned)ifc.ifc_len + 128 < buffsize) break; Freee(ifs); @@ -1296,7 +1298,7 @@ GetEther(struct u_addr *addr, struct sockaddr_dl *hwad } /* if used size is too close to allocated size retry with a larger buffer */ - if (ifc.ifc_len + 128 < buffsize) + if ((unsigned)ifc.ifc_len + 128 < buffsize) break; Freee(ifs); @@ -1431,10 +1433,10 @@ GetPeerEther(struct u_addr *addr, struct sockaddr_dl * } lim = buf + needed; for (next = buf; next < lim; next += rtm->rtm_msglen) { - rtm = (struct rt_msghdr *)next; + rtm = (struct rt_msghdr *)(void *)next; sin2 = (struct sockaddr_inarp *)(rtm + 1); if (addr->u.ip4.s_addr == sin2->sin_addr.s_addr) { - sdl = (struct sockaddr_dl *)((char *)sin2 + SA_SIZE(sin2)); + sdl = (struct sockaddr_dl *)(void *)((char *)sin2 + SA_SIZE(sin2)); memcpy(hwaddr, sdl, sdl->sdl_len); found_entry = 1; break; @@ -1451,7 +1453,7 @@ void ppp_util_ascify(char *buf, size_t bsiz, const char *data, size_t len) { char *bp; - int i; + unsigned i; for (bp = buf, i = 0; i < len; i++) { const char ch = (char)data[i]; @@ -1505,3 +1507,42 @@ ether_ntoa_r(const struct ether_addr *n, char *a) return (a); } #endif + +int +IfaceSetFlag(const char *ifname, int value) +{ + struct ifreq my_ifr; + int s; + int flags; + + /* Get socket */ + if ((s = socket(PF_LOCAL, SOCK_DGRAM, 0)) < 0) { + Perror("Can't get socket to set flags"); + return(-1); + } + + memset(&my_ifr, 0, sizeof(my_ifr)); + (void) strlcpy(my_ifr.ifr_name, ifname, sizeof(my_ifr.ifr_name)); + + if (ioctl(s, SIOCGIFFLAGS, (caddr_t)&my_ifr) < 0) { + Perror("ioctl (SIOCGIFFLAGS)"); + close(s); + return (-1); + } + flags = (my_ifr.ifr_flags & 0xffff) | (my_ifr.ifr_flagshigh << 16); + + if (value < 0) { + value = -value; + flags &= ~value; + } else + flags |= value; + my_ifr.ifr_flags = flags & 0xffff; + my_ifr.ifr_flagshigh = flags >> 16; + if (ioctl(s, SIOCSIFFLAGS, (caddr_t)&my_ifr) < 0) { + Perror("ioctl (SIOCSIFFLAGS)"); + close(s); + return (-1); + } + close(s); + return (0); +}