#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <strings.h>
#include <stdlib.h>
#include <unistd.h>
#include <netdb.h>
#include <libintl.h>
#include <xti.h>
#include <assert.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/byteorder.h>
#include <sys/socket.h>
#include <sys/fcntl.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
#include <netsmb/smb.h>
#include <netsmb/smb_lib.h>
#include <netsmb/netbios.h>
#include <netsmb/nb_lib.h>
#include <netsmb/smb_dev.h>
#include "charsets.h"
#include "private.h"
static int
findvc(struct smb_ctx *ctx, struct addrinfo *ai)
{
smbioc_ossn_t *ssn = &ctx->ct_ssn;
if (ai->ai_addrlen > sizeof (ssn->ssn_srvaddr))
return (EINVAL);
bzero(&ssn->ssn_srvaddr, sizeof (ssn->ssn_srvaddr));
bcopy(ai->ai_addr, &ssn->ssn_srvaddr, ai->ai_addrlen);
if (nsmb_ioctl(ctx->ct_dev_fd, SMBIOC_SSN_FIND, ssn) == -1)
return (errno);
return (0);
}
int
smb_ctx_findvc(struct smb_ctx *ctx)
{
struct addrinfo *ai;
int err;
if ((ctx->ct_flags & SMBCF_RESOLVED) == 0)
return (EINVAL);
if (ctx->ct_dev_fd < 0) {
if ((err = smb_ctx_gethandle(ctx)))
return (err);
}
for (ai = ctx->ct_addrinfo; ai; ai = ai->ai_next) {
switch (ai->ai_family) {
case AF_INET:
case AF_INET6:
case AF_NETBIOS:
err = findvc(ctx, ai);
break;
default:
DPRINT("skipped family %d", ai->ai_family);
err = EPROTONOSUPPORT;
break;
}
if (err == 0) {
return (0);
}
}
return (ENOENT);
}
int
smb_ctx_kill(struct smb_ctx *ctx)
{
if (nsmb_ioctl(ctx->ct_dev_fd, SMBIOC_SSN_KILL, NULL) == -1)
return (errno);
return (0);
}