2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License, Version 1.0 only
2N/A * (the "License"). You may not use this file except in compliance
2N/A * with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A/*
2N/A * Copyright (c) 2000 by Sun Microsystems, Inc.
2N/A * All rights reserved.
2N/A */
2N/A
2N/A#pragma ident "%Z%%M% %I% %E% SMI"
2N/A
2N/A/*
2N/A * Print SUNWbinfiles DHCP network containers.
2N/A */
2N/A
2N/A#include <stdlib.h>
2N/A#include <unistd.h>
2N/A#include <sys/types.h>
2N/A#include <netinet/in.h>
2N/A#include <arpa/inet.h>
2N/A#include <stdio.h>
2N/A#include <fcntl.h>
2N/A#include <errno.h>
2N/A#include <string.h>
2N/A#include <stddef.h>
2N/A#include <sys/socket.h>
2N/A#include "../dhcp_network.h"
2N/A
2N/Astatic void print_hashes(int, dn_header_t);
2N/A
2N/Aint
2N/Amain(int argc, char **argv)
2N/A{
2N/A int confd;
2N/A dn_header_t header;
2N/A char netmask[INET_ADDRSTRLEN], network[INET_ADDRSTRLEN];
2N/A struct in_addr in_addr;
2N/A unsigned int i;
2N/A
2N/A if (argc < 2) {
2N/A (void) fprintf(stderr, "usage: %s container [container ...]\n",
2N/A argv[0]);
2N/A return (EXIT_FAILURE);
2N/A }
2N/A
2N/A for (i = 1; argv[i] != NULL; i++) {
2N/A confd = open(argv[i], O_RDONLY);
2N/A if (confd == -1) {
2N/A (void) fprintf(stderr, "%s: cannot open container "
2N/A "`%s': %s\n", argv[0], argv[i], strerror(errno));
2N/A continue;
2N/A }
2N/A
2N/A if (read(confd, &header, sizeof (header)) != sizeof (header) ||
2N/A header.dnh_magic != DN_MAGIC) {
2N/A (void) fprintf(stderr, "%s: container `%s' is not a "
2N/A "binfiles network container\n", argv[0], argv[i]);
2N/A continue;
2N/A }
2N/A
2N/A (void) printf("binfiles network container `%s':\n", argv[i]);
2N/A
2N/A in_addr.s_addr = header.dnh_network;
2N/A (void) inet_ntop(AF_INET, &in_addr, network, INET_ADDRSTRLEN);
2N/A in_addr.s_addr = header.dnh_netmask;
2N/A (void) inet_ntop(AF_INET, &in_addr, netmask, INET_ADDRSTRLEN);
2N/A
2N/A (void) printf("%12s: %s\n", "network", network);
2N/A (void) printf("%12s: %s\n", "netmask", netmask);
2N/A (void) printf("%12s: %d\n", "dirtybit", header.dnh_dirty);
2N/A (void) printf("%12s: %d\n", "version", header.dnh_version);
2N/A (void) printf("%12s: %d\n", "active image", header.dnh_image);
2N/A (void) printf("%12s: %d\n", "temp image", header.dnh_tempimage);
2N/A (void) printf("%12s: %d\n", "checks", header.dnh_checks);
2N/A (void) printf("%12s: %d\n", "errors", header.dnh_errors);
2N/A print_hashes(confd, header);
2N/A (void) close(confd);
2N/A }
2N/A
2N/A return (EXIT_SUCCESS);
2N/A}
2N/A
2N/Astatic void
2N/Aprint_hashes(int confd, dn_header_t header)
2N/A{
2N/A dn_filerec_t rec;
2N/A dn_recid_t recid;
2N/A unsigned int image, hash;
2N/A
2N/A for (hash = 0; hash < DN_CIDHASHSZ; hash++) {
2N/A for (image = 0; image < 2; image++) {
2N/A if (header.dnh_cidhash[hash][image] == DN_NOREC)
2N/A continue;
2N/A
2N/A (void) printf(" hash %4d/%d: ", hash, image);
2N/A recid = header.dnh_cidhash[hash][image];
2N/A for (; recid != DN_NOREC; recid = rec.rec_next[image]) {
2N/A if (pread(confd, &rec, sizeof (dn_rec_t),
2N/A RECID2OFFSET(recid)) != sizeof (dn_rec_t)) {
2N/A (void) fprintf(stderr, "cannot read "
2N/A "recid %d: %s", recid,
2N/A strerror(errno));
2N/A break;
2N/A }
2N/A (void) printf("%d<-[%d]->%d ",
2N/A rec.rec_prev[image], recid,
2N/A rec.rec_next[image]);
2N/A }
2N/A (void) printf("\n");
2N/A }
2N/A }
2N/A}