int vconfig_main(int argc, char **argv) { struct vlan_ioctl_args ifr; const char *p; int fd; if (argc < 3) { bb_show_usage(); } /* Don't bother closing the filedes. It will be closed on cleanup. */ if (open(conf_file_name, O_RDONLY) < 0) { /* Is 802.1q is present? */ bb_perror_msg_and_die("open %s", conf_file_name); } memset(&ifr, 0, sizeof(struct vlan_ioctl_args)); ++argv; p = xfind_str(cmds+2, *argv); ifr.cmd = *p; if (argc != p[-1]) { bb_show_usage(); } if (ifr.cmd == SET_VLAN_NAME_TYPE_CMD) { /* set_name_type */ ifr.u.name_type = *xfind_str(name_types+1, argv[1]); } else { if (strlen(argv[1]) >= IF_NAMESIZE) { bb_error_msg_and_die("if_name >= %d chars\n", IF_NAMESIZE); } strcpy(ifr.device1, argv[1]); p = argv[2]; /* I suppose one could try to combine some of the function calls below, * since ifr.u.flag, ifr.u.VID, and ifr.u.skb_priority are all same-sized * (unsigned) int members of a unions. But because of the range checking, * doing so wouldn't save that much space and would also make maintainence * more of a pain. */ if (ifr.cmd == SET_VLAN_FLAG_CMD) { /* set_flag */ ifr.u.flag = bb_xgetularg10_bnd(p, 0, 1); } else if (ifr.cmd == ADD_VLAN_CMD) { /* add */ ifr.u.VID = bb_xgetularg10_bnd(p, 0, VLAN_GROUP_ARRAY_LEN-1); } else if (ifr.cmd != DEL_VLAN_CMD) { /* set_{egress|ingress}_map */ ifr.u.skb_priority = bb_xgetularg10_bnd(p, 0, ULONG_MAX); ifr.vlan_qos = bb_xgetularg10_bnd(argv[3], 0, 7); } } if (((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) || (ioctl(fd, SIOCSIFVLAN, &ifr) < 0) ) { bb_perror_msg_and_die("socket or ioctl error for %s", *argv); } return 0; }
int vconfig_main(int argc, char **argv) { struct vlan_ioctl_args ifr; const char *p; int fd; if (argc < 3) { bb_show_usage(); } /* Don't bother closing the filedes. It will be closed on cleanup. */ /* Will die if 802.1q is not present */ xopen(conf_file_name, O_RDONLY); memset(&ifr, 0, sizeof(ifr)); ++argv; p = xfind_str(cmds+2, *argv); ifr.cmd = *p; if (argc != p[-1]) { bb_show_usage(); } if (ifr.cmd == SET_VLAN_NAME_TYPE_CMD) { /* set_name_type */ ifr.u.name_type = *xfind_str(name_types+1, argv[1]); } else { strncpy_IFNAMSIZ(ifr.device1, argv[1]); p = argv[2]; /* I suppose one could try to combine some of the function calls below, * since ifr.u.flag, ifr.u.VID, and ifr.u.skb_priority are all same-sized * (unsigned) int members of a unions. But because of the range checking, * doing so wouldn't save that much space and would also make maintainence * more of a pain. */ if (ifr.cmd == SET_VLAN_FLAG_CMD) { /* set_flag */ ifr.u.flag = xatoul_range(p, 0, 1); /* DM: in order to set reorder header, qos must be set */ ifr.vlan_qos = xatoul_range(argv[3], 0, 7); } else if (ifr.cmd == ADD_VLAN_CMD) { /* add */ ifr.u.VID = xatoul_range(p, 0, VLAN_GROUP_ARRAY_LEN-1); } else if (ifr.cmd != DEL_VLAN_CMD) { /* set_{egress|ingress}_map */ ifr.u.skb_priority = xatou(p); ifr.vlan_qos = xatoul_range(argv[3], 0, 7); } } fd = xsocket(AF_INET, SOCK_STREAM, 0); ioctl_or_perror_and_die(fd, SIOCSIFVLAN, &ifr, "ioctl error for %s", *argv); return 0; }
int smuxctl_main(int argc, char **argv) { struct smux_ioctl_args ifr; const char *p; int fd; if (argc < 3) { bb_show_usage(); } memset(&ifr, 0, sizeof(struct smux_ioctl_args)); ++argv; p = xfind_str(cmds+2, *argv); ifr.cmd = *p; if (argc != p[-1]) { bb_show_usage(); } if(ifr.cmd == ADD_SMUX_CMD) { ++argv; p = xfind_str(smux_protos+1, *argv); ifr.proto = *p; strcpy(ifr.ifname, argv[1]); strcpy(ifr.u.ifname, argv[2]); } else if(ifr.cmd == REM_SMUX_CMD) { strcpy(ifr.u.ifname, argv[1]); } if (((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) || (ioctl(fd, SIOCSIFSMUX, &ifr) < 0)) { bb_perror_msg_and_die("socket or ioctl error for %s", *argv); } return 0; }