xref: /onnv-gate/usr/src/lib/libsmbfs/smb/nb_net.c (revision 10023:71bf38dba3d6)
16007Sthurlow /*
26007Sthurlow  * Copyright (c) 2000, Boris Popov
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: nb_net.c,v 1.8 2004/03/19 01:49:47 lindak Exp $
336007Sthurlow  */
346007Sthurlow 
356007Sthurlow #include <sys/param.h>
366007Sthurlow #include <sys/socket.h>
376007Sthurlow #include <sys/ioctl.h>
386007Sthurlow #include <sys/sockio.h>
396007Sthurlow #include <net/if.h>
406007Sthurlow #include <ctype.h>
416007Sthurlow #include <errno.h>
426007Sthurlow #include <stdlib.h>
436007Sthurlow #include <string.h>
446007Sthurlow #include <strings.h>
456007Sthurlow #include <stdio.h>
466007Sthurlow #include <unistd.h>
47*10023SGordon.Ross@Sun.COM #include <netdb.h>
48*10023SGordon.Ross@Sun.COM #include <nss_dbdefs.h>
496007Sthurlow 
506007Sthurlow #include <err.h>
516007Sthurlow 
526007Sthurlow #include <netsmb/netbios.h>
536007Sthurlow #include <netsmb/smb_lib.h>
546007Sthurlow #include <netsmb/nb_lib.h>
558271SGordon.Ross@Sun.COM #include "private.h"
568271SGordon.Ross@Sun.COM 
578271SGordon.Ross@Sun.COM /*
588271SGordon.Ross@Sun.COM  * General networking stuff, in spite of the names
598271SGordon.Ross@Sun.COM  * that imply they're specific to NetBIOS.
608271SGordon.Ross@Sun.COM  */
616007Sthurlow 
626007Sthurlow int
nb_resolvehost_in(const char * name,struct in_addr * ia)63*10023SGordon.Ross@Sun.COM nb_resolvehost_in(const char *name, struct in_addr *ia)
646007Sthurlow {
65*10023SGordon.Ross@Sun.COM 	char  he_buf[NSS_BUFLEN_HOSTS];
66*10023SGordon.Ross@Sun.COM 	struct hostent he, *h;
67*10023SGordon.Ross@Sun.COM 	int err;
686007Sthurlow 
69*10023SGordon.Ross@Sun.COM 	h = gethostbyname_r(name, &he, he_buf, sizeof (he_buf), &err);
70*10023SGordon.Ross@Sun.COM 	if (h == NULL) {
716007Sthurlow #ifdef DEBUG
726007Sthurlow 		warnx("can't get server address `%s': ", name);
736007Sthurlow #endif
746007Sthurlow 		return (ENETDOWN);
756007Sthurlow 	}
766007Sthurlow 	if (h->h_addrtype != AF_INET) {
776007Sthurlow #ifdef DEBUG
786007Sthurlow 		warnx("address for `%s' is not in the AF_INET family", name);
796007Sthurlow #endif
806007Sthurlow 		return (EAFNOSUPPORT);
816007Sthurlow 	}
826007Sthurlow 	if (h->h_length != 4) {
836007Sthurlow #ifdef DEBUG
846007Sthurlow 		warnx("address for `%s' has invalid length", name);
856007Sthurlow #endif
866007Sthurlow 		return (EAFNOSUPPORT);
876007Sthurlow 	}
88*10023SGordon.Ross@Sun.COM 
89*10023SGordon.Ross@Sun.COM 	memcpy(ia, h->h_addr, sizeof (*ia));
906007Sthurlow 	return (0);
916007Sthurlow }
92