xref: /titanic_51/usr/src/lib/libsmbfs/smb/nb_net.c (revision 613a2f6ba31e891e3d947a356daf5e563d43c1ce)
14bff34e3Sthurlow /*
24bff34e3Sthurlow  * Copyright (c) 2000, Boris Popov
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: nb_net.c,v 1.8 2004/03/19 01:49:47 lindak Exp $
334bff34e3Sthurlow  */
344bff34e3Sthurlow 
354bff34e3Sthurlow #include <sys/param.h>
364bff34e3Sthurlow #include <sys/socket.h>
374bff34e3Sthurlow #include <sys/ioctl.h>
384bff34e3Sthurlow #include <sys/sockio.h>
394bff34e3Sthurlow #include <net/if.h>
404bff34e3Sthurlow #include <ctype.h>
414bff34e3Sthurlow #include <errno.h>
424bff34e3Sthurlow #include <stdlib.h>
434bff34e3Sthurlow #include <string.h>
444bff34e3Sthurlow #include <strings.h>
454bff34e3Sthurlow #include <stdio.h>
464bff34e3Sthurlow #include <unistd.h>
47*613a2f6bSGordon Ross #include <netdb.h>
48*613a2f6bSGordon Ross #include <nss_dbdefs.h>
494bff34e3Sthurlow 
504bff34e3Sthurlow #include <err.h>
514bff34e3Sthurlow 
524bff34e3Sthurlow #include <netsmb/netbios.h>
534bff34e3Sthurlow #include <netsmb/smb_lib.h>
544bff34e3Sthurlow #include <netsmb/nb_lib.h>
559c9af259SGordon Ross #include "private.h"
569c9af259SGordon Ross 
579c9af259SGordon Ross /*
589c9af259SGordon Ross  * General networking stuff, in spite of the names
599c9af259SGordon Ross  * that imply they're specific to NetBIOS.
609c9af259SGordon Ross  */
614bff34e3Sthurlow 
624bff34e3Sthurlow int
63*613a2f6bSGordon Ross nb_resolvehost_in(const char *name, struct in_addr *ia)
644bff34e3Sthurlow {
65*613a2f6bSGordon Ross 	char  he_buf[NSS_BUFLEN_HOSTS];
66*613a2f6bSGordon Ross 	struct hostent he, *h;
67*613a2f6bSGordon Ross 	int err;
684bff34e3Sthurlow 
69*613a2f6bSGordon Ross 	h = gethostbyname_r(name, &he, he_buf, sizeof (he_buf), &err);
70*613a2f6bSGordon Ross 	if (h == NULL) {
714bff34e3Sthurlow #ifdef DEBUG
724bff34e3Sthurlow 		warnx("can't get server address `%s': ", name);
734bff34e3Sthurlow #endif
744bff34e3Sthurlow 		return (ENETDOWN);
754bff34e3Sthurlow 	}
764bff34e3Sthurlow 	if (h->h_addrtype != AF_INET) {
774bff34e3Sthurlow #ifdef DEBUG
784bff34e3Sthurlow 		warnx("address for `%s' is not in the AF_INET family", name);
794bff34e3Sthurlow #endif
804bff34e3Sthurlow 		return (EAFNOSUPPORT);
814bff34e3Sthurlow 	}
824bff34e3Sthurlow 	if (h->h_length != 4) {
834bff34e3Sthurlow #ifdef DEBUG
844bff34e3Sthurlow 		warnx("address for `%s' has invalid length", name);
854bff34e3Sthurlow #endif
864bff34e3Sthurlow 		return (EAFNOSUPPORT);
874bff34e3Sthurlow 	}
88*613a2f6bSGordon Ross 
89*613a2f6bSGordon Ross 	memcpy(ia, h->h_addr, sizeof (*ia));
904bff34e3Sthurlow 	return (0);
914bff34e3Sthurlow }
92