else
imsg_compose(ibuf, IMSG_NETWORK_DONE, 0, 0, -1, NULL, 0); } else
main(int argc, char *argv[]){	struct sockaddr_un	 sun;	int			 fd, n, done, ch, nodescr = 0;	struct imsg		 imsg;	struct network_config	 net;	struct parse_result	*res;	struct ctl_neighbor	 neighbor;	while ((ch = getopt(argc, argv, "n")) != -1) {		switch (ch) {		case 'n':			if (++nodescr > 1)				usage();			break;		default:			usage();			/* NOTREACHED */		}	}	argc -= optind;	argv += optind;	if ((res = parse(argc, argv)) == NULL)		exit(1);	memcpy(&neighbor.addr, &res->addr, sizeof(neighbor.addr));	strlcpy(neighbor.descr, res->peerdesc, sizeof(neighbor.descr));	if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)		err(1, "control_init: socket");	bzero(&sun, sizeof(sun));	sun.sun_family = AF_UNIX;	strlcpy(sun.sun_path, SOCKET_NAME, sizeof(sun.sun_path));	if (connect(fd, (struct sockaddr *)&sun, sizeof(sun)) == -1)		err(1, "connect: %s", SOCKET_NAME);	if ((ibuf = malloc(sizeof(struct imsgbuf))) == NULL)		fatal(NULL);	imsg_init(ibuf, fd);	done = 0;	switch (res->action) {	case NONE:		usage();		/* not reached */	case SHOW:	case SHOW_SUMMARY:		imsg_compose(ibuf, IMSG_CTL_SHOW_NEIGHBOR, 0, 0, -1, NULL, 0);		show_summary_head();		break;	case SHOW_FIB:		if (!res->addr.af)			imsg_compose(ibuf, IMSG_CTL_KROUTE, 0, 0, -1,			    &res->flags, sizeof(res->flags));		else			imsg_compose(ibuf, IMSG_CTL_KROUTE_ADDR, 0, 0, -1,			    &res->addr, sizeof(res->addr));		show_fib_head();		break;	case SHOW_NEXTHOP:		imsg_compose(ibuf, IMSG_CTL_SHOW_NEXTHOP, 0, 0, -1, NULL, 0);		show_nexthop_head();		break;	case SHOW_INTERFACE:		imsg_compose(ibuf, IMSG_CTL_SHOW_INTERFACE, 0, 0, -1, NULL, 0);		show_interface_head();		break;	case SHOW_NEIGHBOR:	case SHOW_NEIGHBOR_TIMERS:		if (res->addr.af || res->peerdesc[0])			imsg_compose(ibuf, IMSG_CTL_SHOW_NEIGHBOR, 0, 0, -1,			    &neighbor, sizeof(neighbor));		else			imsg_compose(ibuf, IMSG_CTL_SHOW_NEIGHBOR, 0, 0, -1,			    NULL, 0);		break;	case SHOW_RIB:		if (res->as.type != AS_NONE)			imsg_compose(ibuf, IMSG_CTL_SHOW_RIB_AS, 0, 0, -1,			    &res->as, sizeof(res->as));		else if (res->addr.af) {			struct ctl_show_rib_prefix	msg;			bzero(&msg, sizeof(msg));			memcpy(&msg.prefix, &res->addr, sizeof(res->addr));			msg.prefixlen = res->prefixlen;			msg.flags = res->flags;			imsg_compose(ibuf, IMSG_CTL_SHOW_RIB_PREFIX, 0, 0, -1,			    &msg, sizeof(msg));		} else			imsg_compose(ibuf, IMSG_CTL_SHOW_RIB, 0, 0, -1,			    NULL, 0);		show_rib_summary_head();		break;	case RELOAD:		imsg_compose(ibuf, IMSG_CTL_RELOAD, 0, 0, -1, NULL, 0);		printf("reload request sent.\n");		done = 1;		break;	case FIB:		errx(1, "action==FIB");		break;	case FIB_COUPLE:		imsg_compose(ibuf, IMSG_CTL_FIB_COUPLE, 0, 0, -1, NULL, 0);		printf("couple request sent.\n");		done = 1;		break;	case FIB_DECOUPLE:		imsg_compose(ibuf, IMSG_CTL_FIB_DECOUPLE, 0, 0, -1, NULL, 0);		printf("decouple request sent.\n");		done = 1;		break;	case NEIGHBOR:		errx(1, "action==NEIGHBOR");		break;	case NEIGHBOR_UP:		imsg_compose(ibuf, IMSG_CTL_NEIGHBOR_UP, 0, 0, -1,		    &neighbor, sizeof(neighbor));		printf("request sent.\n");		done = 1;		break;	case NEIGHBOR_DOWN:		imsg_compose(ibuf, IMSG_CTL_NEIGHBOR_DOWN, 0, 0, -1,		    &neighbor, sizeof(neighbor));		printf("request sent.\n");		done = 1;		break;	case NEIGHBOR_CLEAR:		imsg_compose(ibuf, IMSG_CTL_NEIGHBOR_CLEAR, 0, 0, -1,		    &neighbor, sizeof(neighbor));		printf("request sent.\n");		done = 1;		break;	case NETWORK_ADD:	case NETWORK_REMOVE:		bzero(&net, sizeof(net));		memcpy(&net.prefix, &res->addr, sizeof(res->addr));		net.prefixlen = res->prefixlen;		/* attribute sets are not supported */		if (res->action == NETWORK_ADD)			imsg_compose(ibuf, IMSG_NETWORK_ADD, 0, 0, -1,			    &net, sizeof(net));		else			imsg_compose(ibuf, IMSG_NETWORK_REMOVE, 0, 0, -1,			    &net, sizeof(net));		printf("request sent.\n");		done = 1;		break;	case NETWORK_FLUSH:		imsg_compose(ibuf, IMSG_NETWORK_FLUSH, 0, 0, -1, NULL, 0);		printf("request sent.\n");		done = 1;		break;	case NETWORK_SHOW:		imsg_compose(ibuf, IMSG_CTL_SHOW_NETWORK, 0, 0, -1, NULL, 0);		show_network_head();		break;	}	while (ibuf->w.queued)		if (msgbuf_write(&ibuf->w) < 0)			err(1, "write error");	while (!done) {		if ((n = imsg_read(ibuf)) == -1)			errx(1, "imsg_read error");		if (n == 0)			errx(1, "pipe closed");		while (!done) {			if ((n = imsg_get(ibuf, &imsg)) == -1)				errx(1, "imsg_get error");			if (n == 0)				break;			switch (res->action) {			case SHOW:			case SHOW_SUMMARY:				done = show_summary_msg(&imsg, nodescr);				break;			case SHOW_FIB:				done = show_fib_msg(&imsg);				break;			case SHOW_NEXTHOP:				done = show_nexthop_msg(&imsg);				break;			case SHOW_INTERFACE:				done = show_interface_msg(&imsg);				break;			case SHOW_NEIGHBOR:				done = show_neighbor_msg(&imsg, NV_DEFAULT);				break;			case SHOW_NEIGHBOR_TIMERS:				done = show_neighbor_msg(&imsg, NV_TIMERS);				break;			case SHOW_RIB:				done = show_rib_summary_msg(&imsg);				break;			case NETWORK_SHOW:				done = show_fib_msg(&imsg);				break;			case NONE:			case RELOAD:			case FIB:			case FIB_COUPLE:			case FIB_DECOUPLE:			case NEIGHBOR:			case NEIGHBOR_UP:			case NEIGHBOR_DOWN:			case NEIGHBOR_CLEAR:			case NETWORK_ADD:			case NETWORK_REMOVE:			case NETWORK_FLUSH:				break;			}			imsg_free(&imsg);		}	}	close(fd);	free(ibuf);	exit(0);}