#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 "smb/charsets.h"
#include "smb/private.h"
static int
fknewvc(struct smb_ctx *ctx, struct addrinfo *ai)
{
char host[256];
char svc[32];
smbioc_ossn_t *ssn = &ctx->ct_ssn;
int err;
if (smb_debug) {
err = getnameinfo(ai->ai_addr, ai->ai_addrlen,
host, sizeof (host), svc, sizeof (svc),
AI_NUMERICHOST);
if (err != 0) {
strlcpy(host, "(?)", sizeof (host));
strlcpy(svc, "?", sizeof (host));
}
printf("fknewvc: Try AF=%d %s:%s\n",
ai->ai_family, host, svc);
}
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);
err = smb_iod_cl_newvc(ctx);
if (smb_debug) {
printf("fknewvc: iod_cl_newvc err=%d\n", err);
}
return (err);
}
int
smb_ctx_newvc(struct smb_ctx *ctx)
{
struct addrinfo *ai;
int err;
if ((ctx->ct_flags & SMBCF_RESOLVED) == 0)
return (EINVAL);
err = EPROTONOSUPPORT;
for (ai = ctx->ct_addrinfo; ai; ai = ai->ai_next) {
switch (ai->ai_family) {
case AF_INET:
case AF_INET6:
case AF_NETBIOS:
err = fknewvc(ctx, ai);
if (err == 0)
return (0);
break;
default:
break;
}
}
return (err);
}