16007Sthurlow /*
26007Sthurlow * Copyright (c) 2001, Apple Computer, Inc.
36007Sthurlow * All rights reserved.
46007Sthurlow *
56007Sthurlow * Redistribution and use in source and binary forms, with or without
66007Sthurlow * modification, are permitted provided that the following conditions
76007Sthurlow * are met:
86007Sthurlow * 1. Redistributions of source code must retain the above copyright
96007Sthurlow * notice, this list of conditions and the following disclaimer.
106007Sthurlow * 2. Redistributions in binary form must reproduce the above copyright
116007Sthurlow * notice, this list of conditions and the following disclaimer in the
126007Sthurlow * documentation and/or other materials provided with the distribution.
136007Sthurlow * 3. All advertising materials mentioning features or use of this software
146007Sthurlow * must display the following acknowledgement:
156007Sthurlow * This product includes software developed by Boris Popov.
166007Sthurlow * 4. Neither the name of the author nor the names of any co-contributors
176007Sthurlow * may be used to endorse or promote products derived from this software
186007Sthurlow * without specific prior written permission.
196007Sthurlow *
206007Sthurlow * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
216007Sthurlow * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
226007Sthurlow * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
236007Sthurlow * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
246007Sthurlow * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
256007Sthurlow * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
266007Sthurlow * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
276007Sthurlow * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
286007Sthurlow * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
296007Sthurlow * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
306007Sthurlow * SUCH DAMAGE.
316007Sthurlow *
326007Sthurlow * $Id: status.c,v 1.2 2001/08/18 05:44:50 conrad Exp $
336007Sthurlow */
346007Sthurlow
35*10023SGordon.Ross@Sun.COM /*
36*10023SGordon.Ross@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
37*10023SGordon.Ross@Sun.COM * Use is subject to license terms.
38*10023SGordon.Ross@Sun.COM */
396007Sthurlow
406007Sthurlow #include <sys/param.h>
416007Sthurlow #include <sys/errno.h>
426007Sthurlow #include <sys/stat.h>
436007Sthurlow #include <sys/socket.h>
446007Sthurlow #include <stdio.h>
456007Sthurlow #include <err.h>
466007Sthurlow #include <unistd.h>
476007Sthurlow #include <strings.h>
486007Sthurlow #include <stdlib.h>
496007Sthurlow #include <sysexits.h>
506007Sthurlow #include <libintl.h>
516007Sthurlow
526007Sthurlow #include <netinet/in.h>
536007Sthurlow #include <arpa/inet.h>
546007Sthurlow
556007Sthurlow #include <cflib.h>
566007Sthurlow
576007Sthurlow #include <netsmb/netbios.h>
586007Sthurlow #include <netsmb/smb_lib.h>
596007Sthurlow #include <netsmb/nb_lib.h>
606007Sthurlow
616007Sthurlow #include "common.h"
626007Sthurlow
636007Sthurlow
646007Sthurlow int
cmd_status(int argc,char * argv[])656007Sthurlow cmd_status(int argc, char *argv[])
666007Sthurlow {
676007Sthurlow struct nb_ctx *ctx;
68*10023SGordon.Ross@Sun.COM struct in_addr ina;
696007Sthurlow char *hostname;
70*10023SGordon.Ross@Sun.COM char servername[NB_NAMELEN];
71*10023SGordon.Ross@Sun.COM char workgroupname[NB_NAMELEN];
726007Sthurlow int error, opt;
736007Sthurlow
746007Sthurlow if (argc < 2)
756007Sthurlow status_usage();
766007Sthurlow error = nb_ctx_create(&ctx);
776007Sthurlow if (error) {
786007Sthurlow smb_error(gettext("unable to create nbcontext"), error);
796007Sthurlow exit(1);
806007Sthurlow }
816007Sthurlow if (smb_open_rcfile(NULL) == 0) {
82*10023SGordon.Ross@Sun.COM if (nb_ctx_readrcsection(NULL, ctx, "default", 0) != 0)
836007Sthurlow exit(1);
84*10023SGordon.Ross@Sun.COM smb_close_rcfile();
856007Sthurlow }
866007Sthurlow while ((opt = getopt(argc, argv, "")) != EOF) {
876007Sthurlow switch (opt) {
886007Sthurlow default:
896007Sthurlow status_usage();
906007Sthurlow /*NOTREACHED*/
916007Sthurlow }
926007Sthurlow }
936007Sthurlow if (optind >= argc)
946007Sthurlow status_usage();
956007Sthurlow
966007Sthurlow hostname = argv[argc - 1];
97*10023SGordon.Ross@Sun.COM error = nb_resolvehost_in(hostname, &ina);
986007Sthurlow if (error) {
996007Sthurlow smb_error(gettext(
1006007Sthurlow "unable to resolve DNS hostname %s"), error, hostname);
1016007Sthurlow exit(1);
1026007Sthurlow }
1036007Sthurlow if ((ctx->nb_flags & NBCF_NS_ENABLE) == 0) {
1046007Sthurlow fprintf(stderr,
1056007Sthurlow gettext("nbns_enable=false, cannot get status\n"));
1066007Sthurlow exit(1);
1076007Sthurlow }
1086007Sthurlow servername[0] = (char)0;
1096007Sthurlow workgroupname[0] = (char)0;
110*10023SGordon.Ross@Sun.COM error = nbns_getnodestatus(ctx, &ina, servername, workgroupname);
1116007Sthurlow if (error) {
1126007Sthurlow smb_error(
1136007Sthurlow gettext("unable to get status from %s"), error, hostname);
1146007Sthurlow exit(1);
1156007Sthurlow }
1166007Sthurlow
1176007Sthurlow if (workgroupname[0]) {
1186007Sthurlow printf(gettext("Workgroup: %s\n"), workgroupname);
1196007Sthurlow }
1206007Sthurlow if (servername[0]) {
1216007Sthurlow printf(gettext("Server: %s\n"), servername);
1226007Sthurlow }
1236007Sthurlow
1246007Sthurlow return (0);
1256007Sthurlow }
1266007Sthurlow
1276007Sthurlow
1286007Sthurlow void
status_usage(void)1296007Sthurlow status_usage(void)
1306007Sthurlow {
1316007Sthurlow printf(gettext("usage: smbutil status hostname\n"));
1326007Sthurlow exit(1);
1336007Sthurlow }
134