14bff34e3Sthurlow /* 24bff34e3Sthurlow * Copyright (c) 2001, Apple Computer, Inc. 34bff34e3Sthurlow * All rights reserved. 44bff34e3Sthurlow * 54bff34e3Sthurlow * Redistribution and use in source and binary forms, with or without 64bff34e3Sthurlow * modification, are permitted provided that the following conditions 74bff34e3Sthurlow * are met: 84bff34e3Sthurlow * 1. Redistributions of source code must retain the above copyright 94bff34e3Sthurlow * notice, this list of conditions and the following disclaimer. 104bff34e3Sthurlow * 2. Redistributions in binary form must reproduce the above copyright 114bff34e3Sthurlow * notice, this list of conditions and the following disclaimer in the 124bff34e3Sthurlow * documentation and/or other materials provided with the distribution. 134bff34e3Sthurlow * 3. All advertising materials mentioning features or use of this software 144bff34e3Sthurlow * must display the following acknowledgement: 154bff34e3Sthurlow * This product includes software developed by Boris Popov. 164bff34e3Sthurlow * 4. Neither the name of the author nor the names of any co-contributors 174bff34e3Sthurlow * may be used to endorse or promote products derived from this software 184bff34e3Sthurlow * without specific prior written permission. 194bff34e3Sthurlow * 204bff34e3Sthurlow * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 214bff34e3Sthurlow * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 224bff34e3Sthurlow * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 234bff34e3Sthurlow * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 244bff34e3Sthurlow * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 254bff34e3Sthurlow * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 264bff34e3Sthurlow * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 274bff34e3Sthurlow * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 284bff34e3Sthurlow * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 294bff34e3Sthurlow * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 304bff34e3Sthurlow * SUCH DAMAGE. 314bff34e3Sthurlow * 324bff34e3Sthurlow * $Id: status.c,v 1.2 2001/08/18 05:44:50 conrad Exp $ 334bff34e3Sthurlow */ 344bff34e3Sthurlow 35*613a2f6bSGordon Ross /* 36*613a2f6bSGordon Ross * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 37*613a2f6bSGordon Ross * Use is subject to license terms. 38*613a2f6bSGordon Ross */ 394bff34e3Sthurlow 404bff34e3Sthurlow #include <sys/param.h> 414bff34e3Sthurlow #include <sys/errno.h> 424bff34e3Sthurlow #include <sys/stat.h> 434bff34e3Sthurlow #include <sys/socket.h> 444bff34e3Sthurlow #include <stdio.h> 454bff34e3Sthurlow #include <err.h> 464bff34e3Sthurlow #include <unistd.h> 474bff34e3Sthurlow #include <strings.h> 484bff34e3Sthurlow #include <stdlib.h> 494bff34e3Sthurlow #include <sysexits.h> 504bff34e3Sthurlow #include <libintl.h> 514bff34e3Sthurlow 524bff34e3Sthurlow #include <netinet/in.h> 534bff34e3Sthurlow #include <arpa/inet.h> 544bff34e3Sthurlow 554bff34e3Sthurlow #include <cflib.h> 564bff34e3Sthurlow 574bff34e3Sthurlow #include <netsmb/netbios.h> 584bff34e3Sthurlow #include <netsmb/smb_lib.h> 594bff34e3Sthurlow #include <netsmb/nb_lib.h> 604bff34e3Sthurlow 614bff34e3Sthurlow #include "common.h" 624bff34e3Sthurlow 634bff34e3Sthurlow 644bff34e3Sthurlow int 654bff34e3Sthurlow cmd_status(int argc, char *argv[]) 664bff34e3Sthurlow { 674bff34e3Sthurlow struct nb_ctx *ctx; 68*613a2f6bSGordon Ross struct in_addr ina; 694bff34e3Sthurlow char *hostname; 70*613a2f6bSGordon Ross char servername[NB_NAMELEN]; 71*613a2f6bSGordon Ross char workgroupname[NB_NAMELEN]; 724bff34e3Sthurlow int error, opt; 734bff34e3Sthurlow 744bff34e3Sthurlow if (argc < 2) 754bff34e3Sthurlow status_usage(); 764bff34e3Sthurlow error = nb_ctx_create(&ctx); 774bff34e3Sthurlow if (error) { 784bff34e3Sthurlow smb_error(gettext("unable to create nbcontext"), error); 794bff34e3Sthurlow exit(1); 804bff34e3Sthurlow } 814bff34e3Sthurlow if (smb_open_rcfile(NULL) == 0) { 82*613a2f6bSGordon Ross if (nb_ctx_readrcsection(NULL, ctx, "default", 0) != 0) 834bff34e3Sthurlow exit(1); 84*613a2f6bSGordon Ross smb_close_rcfile(); 854bff34e3Sthurlow } 864bff34e3Sthurlow while ((opt = getopt(argc, argv, "")) != EOF) { 874bff34e3Sthurlow switch (opt) { 884bff34e3Sthurlow default: 894bff34e3Sthurlow status_usage(); 904bff34e3Sthurlow /*NOTREACHED*/ 914bff34e3Sthurlow } 924bff34e3Sthurlow } 934bff34e3Sthurlow if (optind >= argc) 944bff34e3Sthurlow status_usage(); 954bff34e3Sthurlow 964bff34e3Sthurlow hostname = argv[argc - 1]; 97*613a2f6bSGordon Ross error = nb_resolvehost_in(hostname, &ina); 984bff34e3Sthurlow if (error) { 994bff34e3Sthurlow smb_error(gettext( 1004bff34e3Sthurlow "unable to resolve DNS hostname %s"), error, hostname); 1014bff34e3Sthurlow exit(1); 1024bff34e3Sthurlow } 1034bff34e3Sthurlow if ((ctx->nb_flags & NBCF_NS_ENABLE) == 0) { 1044bff34e3Sthurlow fprintf(stderr, 1054bff34e3Sthurlow gettext("nbns_enable=false, cannot get status\n")); 1064bff34e3Sthurlow exit(1); 1074bff34e3Sthurlow } 1084bff34e3Sthurlow servername[0] = (char)0; 1094bff34e3Sthurlow workgroupname[0] = (char)0; 110*613a2f6bSGordon Ross error = nbns_getnodestatus(ctx, &ina, servername, workgroupname); 1114bff34e3Sthurlow if (error) { 1124bff34e3Sthurlow smb_error( 1134bff34e3Sthurlow gettext("unable to get status from %s"), error, hostname); 1144bff34e3Sthurlow exit(1); 1154bff34e3Sthurlow } 1164bff34e3Sthurlow 1174bff34e3Sthurlow if (workgroupname[0]) { 1184bff34e3Sthurlow printf(gettext("Workgroup: %s\n"), workgroupname); 1194bff34e3Sthurlow } 1204bff34e3Sthurlow if (servername[0]) { 1214bff34e3Sthurlow printf(gettext("Server: %s\n"), servername); 1224bff34e3Sthurlow } 1234bff34e3Sthurlow 1244bff34e3Sthurlow return (0); 1254bff34e3Sthurlow } 1264bff34e3Sthurlow 1274bff34e3Sthurlow 1284bff34e3Sthurlow void 1294bff34e3Sthurlow status_usage(void) 1304bff34e3Sthurlow { 1314bff34e3Sthurlow printf(gettext("usage: smbutil status hostname\n")); 1324bff34e3Sthurlow exit(1); 1334bff34e3Sthurlow } 134