int main(int argc, char **argv) { if(!check_permissions()) { exit(EXIT_FAILURE); } if((argc != 3) && (argc != 4)) { printf("usage: %s iface ttl\n", argv[0]); exit(EXIT_FAILURE); } char *iface = argv[1]; int ttl = atoi(argv[2]); int ipversion; // ipversion = 4 to IPv4; ipversion = 6 to IPv6; if(argc == 4){ ipversion = atoi(argv[3]); } else{ ipversion = 4; } demux_init(iface); struct confirm *conf = confirm_create(iface); struct confirm_query *q; struct sockaddr_storage dst; if (ipversion == 4){ struct sockaddr_in ipv4_dst; ipv4_dst.sin_family = AF_INET; inet_pton(AF_INET, "200.149.119.183", &(ipv4_dst.sin_addr)); dst = *((struct sockaddr_storage *) &ipv4_dst); dst.ss_family = AF_INET; q = confirm_query_create4(&dst, ttl, 1, 1, 1, 0, querycb); confirm_submit(conf, q); q = confirm_query_create4(&dst, ttl+1, 1, 1, 1, 0, querycb); confirm_submit(conf, q); } else if (ipversion == 6){ struct sockaddr_in6 sa; sa.sin6_family = AF_INET6; inet_pton(AF_INET6, "2800:3F0:4004:800:0:0:0:1012", &(sa.sin6_addr)); dst = *((struct sockaddr_storage *) &sa); dst.ss_family = AF_INET6; q = confirm_query_create6(&dst, ttl, 1, 1, 0, 0, querycb); confirm_submit(conf, q); q = confirm_query_create6(&dst, ttl+1, 1, 1, 0, 0, querycb); confirm_submit(conf, q); } sleep(10); confirm_destroy(conf); demux_destroy(); log_destroy(); exit(EXIT_SUCCESS); }
static int be_do_destroy(int argc, char **argv) { nvlist_t *be_attrs; boolean_t is_snap = B_FALSE; boolean_t suppress_prompt = B_FALSE; int err = 1; int c; int destroy_flags = 0; char *snap_name; char *be_name; while ((c = getopt(argc, argv, "fFsv")) != -1) { switch (c) { case 'f': destroy_flags |= BE_DESTROY_FLAG_FORCE_UNMOUNT; break; case 's': destroy_flags |= BE_DESTROY_FLAG_SNAPSHOTS; break; case 'v': libbe_print_errors(B_TRUE); break; case 'F': suppress_prompt = B_TRUE; break; default: usage(); return (1); } } argc -= optind; argv += optind; if (argc != 1) { usage(); return (1); } be_name = argv[0]; if (!suppress_prompt && !confirm_destroy(be_name)) { (void) printf(_("%s has not been destroyed.\n"), be_name); return (0); } if ((snap_name = strrchr(be_name, '@')) != NULL) { if (snap_name[1] == '\0') { usage(); return (1); } is_snap = B_TRUE; *snap_name = '\0'; snap_name++; } if (be_nvl_alloc(&be_attrs) != 0) return (1); if (be_nvl_add_string(be_attrs, BE_ATTR_ORIG_BE_NAME, be_name) != 0) goto out; if (is_snap) { if (be_nvl_add_string(be_attrs, BE_ATTR_SNAP_NAME, snap_name) != 0) goto out; err = be_destroy_snapshot(be_attrs); } else { if (be_nvl_add_uint16(be_attrs, BE_ATTR_DESTROY_FLAGS, destroy_flags) != 0) goto out; err = be_destroy(be_attrs); } switch (err) { case BE_SUCCESS: (void) printf(_("Destroyed successfully\n")); break; case BE_ERR_MOUNTED: (void) fprintf(stderr, _("Unable to destroy %s.\n"), be_name); (void) fprintf(stderr, _("It is currently mounted and must be " "unmounted before it can be destroyed.\n" "Use 'beadm " "unmount %s' to unmount the BE before destroying\nit or " "'beadm destroy -f %s'.\n"), be_name, be_name); break; case BE_ERR_DESTROY_CURR_BE: (void) fprintf(stderr, _("%s is the currently active BE and " "cannot be destroyed.\nYou must boot from another BE in " "order to destroy %s.\n"), be_name, be_name); break; case BE_ERR_ZONES_UNMOUNT: (void) fprintf(stderr, _("Unable to destroy one of " "%s's " "zone BE's.\nUse 'beadm destroy -f %s' or " "'zfs -f destroy <dataset>'.\n"), be_name, be_name); break; case BE_ERR_SS_NOENT: (void) fprintf(stderr, _("%s does not exist or appear " "to be a valid snapshot.\nPlease check that the name of " "the snapshot provided is correct.\n"), snap_name); break; case BE_ERR_PERM: case BE_ERR_ACCESS: (void) fprintf(stderr, _("Unable to destroy %s.\n"), be_name); (void) fprintf(stderr, _("You have insufficient privileges to " "execute this command.\n")); break; case BE_ERR_SS_EXISTS: (void) fprintf(stderr, _("Unable to destroy %s: " "BE has snapshots.\nUse 'beadm destroy -s %s' or " "'zfs -r destroy <dataset>'.\n"), be_name, be_name); break; default: (void) fprintf(stderr, _("Unable to destroy %s.\n"), be_name); (void) fprintf(stderr, "%s\n", be_err_to_str(err)); } out: nvlist_free(be_attrs); return (err); }