1 diff -ur samba-2.2.8a/source/acconfig.h samba-2.2.8a+IPv6-20030712/source/acconfig.h
2 --- samba-2.2.8a/source/acconfig.h 2003-02-28 10:56:06.000000000 -0500
3 +++ samba-2.2.8a+IPv6-20030712/source/acconfig.h 2003-07-12 22:28:29.000000000 -0400
12 diff -ur samba-2.2.8a/source/client/client.c samba-2.2.8a+IPv6-20030712/source/client/client.c
13 --- samba-2.2.8a/source/client/client.c 2003-03-14 16:34:47.000000000 -0500
14 +++ samba-2.2.8a+IPv6-20030712/source/client/client.c 2003-07-12 22:28:29.000000000 -0400
16 struct cli_state *cli;
17 extern BOOL in_client;
18 extern BOOL AllowDebugChange;
19 -static int port = SMB_PORT;
21 pstring cur_dir = "\\";
23 static pstring service;
25 static BOOL recurse = False;
26 BOOL lowercase = False;
28 -struct in_addr dest_ip;
31 #define SEPARATORS " \t\n\r"
35 struct nmb_name called, calling;
39 + struct sockaddr_list *salist;
42 /* make a copy so we don't modify the global string 'service' */
43 @@ -2170,21 +2170,18 @@
49 make_nmb_name(&calling, global_myname, 0x0);
50 make_nmb_name(&called , server, name_type);
54 - if (have_ip) ip = dest_ip;
56 - /* have to open a new connection */
57 - if (!(c=cli_initialise(NULL)) || (cli_set_port(c, port) == 0) ||
58 - !cli_connect(c, server_n, &ip)) {
59 - DEBUG(0,("Connection to %s failed\n", server_n));
62 + salist = resolve_name_smb(have_ip ? dest_ip : server_n, port);
64 + /* have to open a new connection */
65 + if (!(c=cli_initialise(NULL)) || !cli_connect(c, server_n, salist)) {
66 + DEBUG(0,("Connection to %s failed\n", server_n));
67 + free_sockaddr_list(salist);
71 c->protocol = max_protocol;
73 @@ -2429,29 +2426,19 @@
75 static int do_message_op(void)
78 struct nmb_name called, calling;
81 + struct sockaddr_list *salist;
83 make_nmb_name(&calling, global_myname, 0x0);
84 make_nmb_name(&called , desthost, name_type);
89 - else if (name_type != 0x20) {
90 - /* We must do our own resolve name here as the nametype is #0x3, not #0x20. */
91 - if (!resolve_name(desthost, &ip, name_type)) {
92 - DEBUG(0,("Cannot resolve name %s#0x%x\n", desthost, name_type));
97 - if (!(cli=cli_initialise(NULL)) || (cli_set_port(cli, port) == 0) || !cli_connect(cli, desthost, &ip)) {
98 - DEBUG(0,("Connection to %s failed\n", desthost));
101 + salist = resolve_name_smb(have_ip ? dest_ip : desthost, port);
103 + if (!(cli=cli_initialise(NULL)) || !cli_connect(cli, desthost, salist)) {
104 + DEBUG(0,("Connection to %s failed\n", desthost));
105 + free_sockaddr_list(salist);
109 if (!cli_session_request(cli, &calling, &called)) {
110 DEBUG(0,("session request failed\n"));
111 @@ -2682,9 +2669,7 @@
115 - dest_ip = *interpret_addr2(optarg);
116 - if (is_zero_ip(dest_ip))
118 + strncpy(dest_ip, optarg, sizeof(dest_ip));
122 diff -ur samba-2.2.8a/source/client/smbmount.c samba-2.2.8a+IPv6-20030712/source/client/smbmount.c
123 --- samba-2.2.8a/source/client/smbmount.c 2002-04-30 09:26:19.000000000 -0400
124 +++ samba-2.2.8a+IPv6-20030712/source/client/smbmount.c 2003-07-12 22:28:29.000000000 -0400
126 static pstring service;
127 static pstring options;
129 -static struct in_addr dest_ip;
130 +static char dest_ip[512];
132 -static int smb_port = 139;
133 +static int smb_port = 0;
134 static BOOL got_pass;
135 static uid_t mount_uid;
136 static gid_t mount_gid;
140 struct nmb_name called, calling;
141 + struct sockaddr_list *salist;
147 @@ -141,16 +141,15 @@
148 make_nmb_name(&called , server, 0x20);
152 - if (have_ip) ip = dest_ip;
153 + salist = resolve_name_smb(have_ip ? dest_ip : server_n, smb_port);
155 /* have to open a new connection */
156 - if (!(c=cli_initialise(NULL)) || (cli_set_port(c, smb_port) == 0) ||
157 - !cli_connect(c, server_n, &ip)) {
158 - DEBUG(0,("%d: Connection to %s failed\n", getpid(), server_n));
162 + if (!(c=cli_initialise(NULL)) || !cli_connect(c, server_n, salist)) {
163 + DEBUG(0,("%d: Connection to %s failed\n", getpid(), server_n));
164 + free_sockaddr_list(salist);
172 } else if(!strcmp(opts, "debug")) {
174 } else if(!strcmp(opts, "ip")) {
175 - dest_ip = *interpret_addr2(opteq+1);
176 - if (is_zero_ip(dest_ip)) {
177 - fprintf(stderr,"Can't resolve address %s\n", opteq+1);
180 + strncpy(dest_ip, optarg, sizeof(dest_ip));
182 } else if(!strcmp(opts, "workgroup")) {
183 pstrcpy(workgroup,opteq+1);
184 diff -ur samba-2.2.8a/source/client/smbspool.c samba-2.2.8a+IPv6-20030712/source/client/smbspool.c
185 --- samba-2.2.8a/source/client/smbspool.c 2003-02-28 10:56:18.000000000 -0500
186 +++ samba-2.2.8a+IPv6-20030712/source/client/smbspool.c 2003-07-12 22:28:29.000000000 -0400
188 struct cli_state *c; /* New connection */
189 struct nmb_name called, /* NMB name of server */
190 calling; /* NMB name of client */
191 - struct in_addr ip; /* IP address of server */
192 pstring myname; /* Client name */
201 make_nmb_name(&calling, myname, 0x0);
202 make_nmb_name(&called, server, 0x20);
208 - if (!cli_set_port(c, SMB_PORT))
210 - fputs("ERROR: cli_set_port() failed...\n", stderr);
215 - if (!cli_connect(c, server, &ip))
216 + if (!cli_connect(c, server, NULL))
218 fputs("ERROR: cli_connect() failed...\n", stderr);
220 diff -ur samba-2.2.8a/source/configure.in samba-2.2.8a+IPv6-20030712/source/configure.in
221 --- samba-2.2.8a/source/configure.in 2003-02-28 10:56:18.000000000 -0500
222 +++ samba-2.2.8a+IPv6-20030712/source/configure.in 2003-07-12 22:28:29.000000000 -0400
223 @@ -2282,6 +2282,53 @@
226 #################################################
227 +# check for IPv6 support
228 +AC_MSG_CHECKING(whether to use IPv6)
230 +[ --with-ipv6 Include IPv6 support (default=no)],
231 +[ case "$withval" in
234 + AC_DEFINE(HAVE_INET6)
236 + AC_CACHE_CHECK(for struct sockaddr_in6,samba_cv_struct_sockaddr_in6,
238 + [#include <sys/types.h>
239 + #include <sys/socket.h>
240 + #include <netinet/in.h>],
241 + [struct sockaddr_in6 sin6;
242 + sin6.sin6_port = 0;],
243 + [samba_cv_struct_sockaddr_in6=yes],
244 + [samba_cv_struct_sockaddr_in6=no]))
245 + if test "$samba_cv_struct_sockaddr_in6" != yes ; then
246 + AC_MSG_ERROR([This system does not have IPv6 support. Reconfigure without the --with-ipv6 flag.])
249 + AC_CHECK_FUNC(getaddrinfo,,
250 + AC_MSG_ERROR([IPv6 functionality requires getaddrinfo. Reconfigure without the --with-ipv6 flag.]))
252 + dnl This can't check for member names because we're not sure what they
253 + dnl might be. Doesn't matter - we only need it defined for sizeof.
254 + AC_CACHE_CHECK(for struct sockaddr_storage,samba_cv_struct_sockaddr_storage,
256 + [#include <sys/types.h>
257 + #include <sys/socket.h>
258 + #include <netinet/in.h>],
259 + [struct sockaddr_storage ss;],
260 + [samba_cv_struct_sockaddr_storage=yes],
261 + [samba_cv_struct_sockaddr_storage=no]))
262 + if test "$samba_cv_struct_sockaddr_storage" != yes ; then
263 + AC_MSG_ERROR([IPv6 functionality requires the sockaddr_storage structure. Reconfigure without the --with-ipv6 flag.])
273 +#################################################
274 # check for syslog logging
275 AC_MSG_CHECKING(whether to use syslog logging)
277 diff -ur samba-2.2.8a/source/include/client.h samba-2.2.8a+IPv6-20030712/source/include/client.h
278 --- samba-2.2.8a/source/include/client.h 2003-03-14 16:34:47.000000000 -0500
279 +++ samba-2.2.8a+IPv6-20030712/source/include/client.h 2003-07-12 22:28:29.000000000 -0400
287 int smb_rw_error; /* Copy of last read or write error. */
290 struct nmb_name called;
291 struct nmb_name calling;
292 fstring full_dest_host_name;
293 - struct in_addr dest_ip;
294 + struct sockaddr_list *dest_addrs;
295 + struct sockaddr_list *connected_addr;
298 unsigned char cryptkey[8];
299 diff -ur samba-2.2.8a/source/include/config.h.in samba-2.2.8a+IPv6-20030712/source/include/config.h.in
300 --- samba-2.2.8a/source/include/config.h.in 2003-02-28 10:56:18.000000000 -0500
301 +++ samba-2.2.8a+IPv6-20030712/source/include/config.h.in 2003-07-12 22:28:29.000000000 -0400
310 diff -ur samba-2.2.8a/source/include/nameserv.h samba-2.2.8a+IPv6-20030712/source/include/nameserv.h
311 --- samba-2.2.8a/source/include/nameserv.h 2002-05-18 09:40:11.000000000 -0400
312 +++ samba-2.2.8a+IPv6-20030712/source/include/nameserv.h 2003-07-12 22:28:29.000000000 -0400
314 #define FIND_SELF_NAME 1
317 + * Linked-list structure for storing resolved IP addresses.
320 +struct sockaddr_list {
321 + struct sockaddr_list *next;
324 + struct sockaddr *addr;
328 * The different name types that can be in namelists.
330 * SELF_NAME should only be on the broadcast and unicast subnets.
331 diff -ur samba-2.2.8a/source/include/proto.h samba-2.2.8a+IPv6-20030712/source/include/proto.h
332 --- samba-2.2.8a/source/include/proto.h 2003-03-14 16:34:47.000000000 -0500
333 +++ samba-2.2.8a+IPv6-20030712/source/include/proto.h 2003-07-12 22:28:29.000000000 -0400
335 BOOL cli_negprot(struct cli_state *cli);
336 BOOL cli_session_request(struct cli_state *cli,
337 struct nmb_name *calling, struct nmb_name *called);
338 -BOOL cli_connect(struct cli_state *cli, const char *host, struct in_addr *ip);
339 +BOOL cli_connect(struct cli_state *cli, const char *host,
340 + struct sockaddr_list *salist);
341 BOOL cli_establish_connection(struct cli_state *cli,
342 - const char *dest_host, struct in_addr *dest_ip,
343 + char *dest_host, struct sockaddr_list *salist,
344 struct nmb_name *calling, struct nmb_name *called,
345 const char *service, const char *service_type,
346 BOOL do_shutdown, BOOL do_tcon);
348 const char *service, const char *service_type,
349 const char *user, const char *domain,
350 const char *password, int pass_len) ;
351 -BOOL attempt_netbios_session_request(struct cli_state *cli, const char *srchost, const char *desthost,
352 - struct in_addr *pdest_ip);
353 +BOOL attempt_netbios_session_request(struct cli_state *cli, char *srchost,
356 /* The following definitions come from libsmb/cli_dfs.c */
358 @@ -723,12 +724,12 @@
359 BOOL getlmhostsent( FILE *fp, pstring name, int *name_type, struct in_addr *ipaddr);
360 void endlmhosts(FILE *fp);
361 BOOL name_register_wins(const char *name, int name_type);
362 -BOOL name_resolve_bcast(const char *name, int name_type,
363 - struct in_addr **return_ip_list, int *return_count);
364 -BOOL resolve_name(const char *name, struct in_addr *return_ip, int name_type);
365 -BOOL resolve_name_2(const char *name, struct in_addr **return_ip, int *count, int name_type);
366 -BOOL resolve_srv_name(const char* srv_name, fstring dest_host,
367 - struct in_addr *ip);
368 +struct sockaddr_list *name_resolve_bcast(const char *name, int name_type);
369 +BOOL resolve_name_netbios(const char *name, struct in_addr *return_ip,
371 +struct sockaddr_list *resolve_name_smb(const char *name, int port);
372 +struct sockaddr_list *resolve_srv_name(const char* srv_name,
373 + fstring dest_host, int port);
374 BOOL find_master_ip(char *group, struct in_addr *master_ip);
375 BOOL lookup_dc_name(const char *srcname, const char *domain,
376 struct in_addr *dc_ip, char *ret_name);
377 @@ -1155,8 +1156,21 @@
378 void safe_free(void *p);
379 BOOL get_myname(char *my_name);
380 int interpret_protocol(char *str,int def);
381 +BOOL is_ipv4address(const char *str);
382 BOOL is_ipaddress(const char *str);
383 uint32 interpret_addr(const char *str);
384 +struct sockaddr *get_numeric_addr(const char *str);
385 +BOOL sa_host_equal(struct sockaddr *a, struct sockaddr *b);
386 +int get_sockaddr_port(struct sockaddr *sa);
387 +void set_sockaddr_port(struct sockaddr *sa, int port);
388 +struct sockaddr_list *set_default_ports(struct sockaddr_list *salist);
389 +BOOL is_directsmb(struct sockaddr *sa);
390 +char *print_sockaddr(struct sockaddr *sa);
391 +void make_sockaddr_in(struct sockaddr *sa, struct in_addr *addr);
392 +void free_sockaddr_list(struct sockaddr_list *salist);
393 +struct sockaddr_list *make_sin_list(struct in_addr *addr, int count);
394 +struct sockaddr_list *make_singlet_list(struct in_addr *addr, int port);
395 +struct sockaddr_list *make_sa_list(struct addrinfo *ai);
396 struct in_addr *interpret_addr2(const char *str);
397 BOOL is_zero_ip(struct in_addr ip);
398 void zero_ip(struct in_addr *ip);
399 @@ -1311,7 +1325,8 @@
400 BOOL send_smb(int fd,char *buffer);
401 BOOL send_one_packet(char *buf,int len,struct in_addr ip,int port,int type);
402 int open_socket_in( int type, int port, int dlevel, uint32 socket_addr, BOOL rebind );
403 -int open_socket_out(int type, struct in_addr *addr, int port ,int timeout);
404 +int open_socket_out(struct sockaddr_list *addrs,
405 + struct sockaddr_list **connected_addr, int timeout);
406 void client_setfd(int fd);
407 char *client_name(void);
408 char *client_addr(void);
409 @@ -4507,10 +4522,6 @@
410 char *inbuf,char *outbuf, int dum_size,
413 -/* The following definitions come from smbd/noquotas.c */
415 -BOOL disk_quotas(const char *path,SMB_BIG_UINT *bsize,SMB_BIG_UINT *dfree,SMB_BIG_UINT *dsize);
417 /* The following definitions come from smbd/notify.c */
419 void remove_pending_change_notify_requests_by_fid(files_struct *fsp);
420 @@ -4643,6 +4654,16 @@
421 void check_reload(int t);
422 void smbd_process(void);
424 +/* The following definitions come from smbd/quotas.c */
426 +BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize);
427 +BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize);
428 +BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize);
429 +BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize);
430 +BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize);
431 +BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize);
432 +BOOL disk_quotas_vxfs(const pstring name, char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize);
434 /* The following definitions come from smbd/reply.c */
436 int reply_special(char *inbuf,char *outbuf);
437 diff -ur samba-2.2.8a/source/include/smb.h samba-2.2.8a+IPv6-20030712/source/include/smb.h
438 --- samba-2.2.8a/source/include/smb.h 2003-03-14 16:34:47.000000000 -0500
439 +++ samba-2.2.8a+IPv6-20030712/source/include/smb.h 2003-07-12 22:28:29.000000000 -0400
441 char *user; /* name of user who *opened* this connection */
442 uid_t uid; /* uid of user who *opened* this connection */
443 gid_t gid; /* gid of user who *opened* this connection */
444 - char client_address[18]; /* String version of client IP address. */
445 + char client_address[50]; /* String version of client IP address.
446 + * Nice and long for IPv6 addresses... */
448 uint16 vuid; /* vuid of user who *opened* this connection, or UID_FIELD_INVALID */
450 diff -ur samba-2.2.8a/source/lib/access.c samba-2.2.8a+IPv6-20030712/source/lib/access.c
451 --- samba-2.2.8a/source/lib/access.c 2003-03-14 16:34:47.000000000 -0500
452 +++ samba-2.2.8a+IPv6-20030712/source/lib/access.c 2003-07-12 22:28:29.000000000 -0400
454 #define ALLONES ((uint32)0xFFFFFFFF)
456 /* masked_match - match address against netnumber/netmask */
457 -static int masked_match(char *tok, char *slash, char *s)
458 +static BOOL masked_match_ipv4(char *tok, char *slash, char *s)
463 return ((addr & mask) == net);
467 +static BOOL masked_match_ipv6(char *tok, char *slash, char *s)
469 + struct in6_addr net, addr;
470 + unsigned char *n = (unsigned char *)&net;
471 + unsigned char *a = (unsigned char *)&addr;
472 + int ret, len, i, mask;
474 + if(inet_pton(AF_INET6, s, &addr) <= 0)
476 + DEBUG(0,("access: unable to parse remote address: %s\n", s));
480 + ret = inet_pton(AF_INET6, tok, &net);
482 + len = atoi(slash + 1);
483 + if(ret <= 0 || len < 0 || len > 128
484 + || (len == 0 && strcmp(slash + 1, "0")))
486 + DEBUG(0,("access: bad net/mask access control: %s\n", tok));
489 + for(i = 0; i < len; i += 8)
493 + mask = ~((1 << (8 - (len - i))) - 1);
496 + DEBUG(3,("len=%d i=%d mask=%02x *n=%02x *a=%02x *a&mask=%02x\n",
497 + len, i, mask, *n, *a, *a & mask));
498 + if(*(n++) != (*(a++) & mask)) return False;
504 +static BOOL masked_match(char *tok, char *slash, char *s)
506 + if(is_ipv4address(s)) return masked_match_ipv4(tok, slash, s);
508 + return masked_match_ipv6(tok, slash, s);
514 /* string_match - match string against token */
515 static int string_match(char *tok,char *s, char *invalid_char)
518 } else if (tok[(tok_len = strlen(tok)) - 1] == '.') { /* network */
519 if (strncmp(tok, s, tok_len) == 0)
522 + } else if (tok[(tok_len = strlen(tok)) - 1] == ':') { /* IPv6 network */
523 + if (strncasecmp(tok, s, tok_len) == 0)
526 } else if ((cut = strchr(tok, '/')) != 0) { /* netnumber/netmask */
527 - if (isdigit((int)s[0]) && masked_match(tok, cut, s))
528 + if (isxdigit((int)s[0]) && masked_match(tok, cut, s))
530 } else if (strchr(tok, '*') != 0) {
535 /* if it is loopback then always allow unless specifically denied */
537 + if (strcmp(caddr, "127.0.0.1") == 0 || strcmp(caddr, "::1") == 0) {
539 if (strcmp(caddr, "127.0.0.1") == 0) {
542 - * If 127.0.0.1 matches both allow and deny then allow.
543 + * If 127.0.0.1 or ::1 matches both allow and deny then allow.
544 * Patch from Steve Langasek vorlon@netexpress.net.
547 diff -ur samba-2.2.8a/source/lib/util.c samba-2.2.8a+IPv6-20030712/source/lib/util.c
548 --- samba-2.2.8a/source/lib/util.c 2003-03-14 16:34:47.000000000 -0500
549 +++ samba-2.2.8a+IPv6-20030712/source/lib/util.c 2003-07-12 22:28:29.000000000 -0400
550 @@ -745,11 +745,11 @@
551 Return true if a string could be a pure IP address.
552 ****************************************************************************/
554 -BOOL is_ipaddress(const char *str)
555 +BOOL is_ipv4address(const char *str)
557 BOOL pure_address = True;
561 for (i=0; pure_address && str[i]; i++)
562 if (!(isdigit((int)str[i]) || str[i] == '.'))
563 pure_address = False;
568 +BOOL is_ipaddress(const char *str)
571 + /* First we see if the address is an IPv6 address */
572 + if (strchr(str, ':'))
576 + /* It contains a colon; it probably is */
577 + for (i=0; str[i]; i++)
578 + if (!(isxdigit((int)str[i]) || str[i] == '.' || str[i] == ':'))
585 + return is_ipv4address(str);
588 /****************************************************************************
589 interpret an internet address or name into an IP address in 4 byte form
590 ****************************************************************************/
591 @@ -794,6 +814,204 @@
595 +struct sockaddr *get_numeric_addr(const char *str)
598 + struct sockaddr *sa;
599 + struct addrinfo *ai, hints;
601 + memset(&hints, 0, sizeof(hints));
602 + hints.ai_socktype = SOCK_STREAM;
603 + hints.ai_flags = AI_NUMERICHOST;
604 + if(getaddrinfo(str, NULL, &hints, &ai) || ! ai) return NULL;
605 + sa = (struct sockaddr *)malloc(ai->ai_addrlen);
606 + memcpy(sa, ai->ai_addr, ai->ai_addrlen);
610 + struct sockaddr *sa;
611 + struct in_addr addr;
613 + if(inet_aton(str, &addr))
615 + sa = (struct sockaddr *)malloc(sizeof(struct sockaddr_in));
616 + make_sockaddr_in(sa, &addr);
623 +BOOL sa_host_equal(struct sockaddr *a, struct sockaddr *b)
626 + if(a->sa_family == AF_INET6 && b->sa_family == AF_INET6)
628 + return IN6_ARE_ADDR_EQUAL(
629 + &((struct sockaddr_in6 *)a)->sin6_addr,
630 + &((struct sockaddr_in6 *)b)->sin6_addr);
633 + if(a->sa_family == AF_INET && b->sa_family == AF_INET)
635 + return ((struct sockaddr_in *)a)->sin_addr.s_addr
636 + == ((struct sockaddr_in *)b)->sin_addr.s_addr;
641 +int get_sockaddr_port(struct sockaddr *sa)
644 + if(sa->sa_family==AF_INET6)
645 + return ntohs(((struct sockaddr_in6 *)sa)->sin6_port);
648 + if(sa->sa_family==AF_INET)
649 + return ntohs(((struct sockaddr_in *)sa)->sin_port);
654 +void set_sockaddr_port(struct sockaddr *sa, int port)
657 + if(sa->sa_family==AF_INET6)
658 + ((struct sockaddr_in6 *)sa)->sin6_port = htons(port);
661 + if(sa->sa_family==AF_INET)
662 + ((struct sockaddr_in *)sa)->sin_port = htons(port);
665 +struct sockaddr_list *set_default_ports(struct sockaddr_list *salist)
667 + struct sockaddr_list *cur;
669 + for(cur = salist; cur; cur = cur->next)
671 + set_sockaddr_port(cur->addr, 445);
672 + if(cur->addr->sa_family == AF_INET)
674 + struct sockaddr_list *sc;
676 + sc = (struct sockaddr_list *)
677 + malloc(sizeof(struct sockaddr_list));
678 + sc->next = cur->next;
680 + sc->pfamily = cur->pfamily;
681 + sc->len = cur->len;
682 + sc->addr = (struct sockaddr *)malloc(sc->len);
683 + memcpy(sc->addr, cur->addr, cur->len);
684 + set_sockaddr_port(sc->addr, 139);
692 +BOOL is_directsmb(struct sockaddr *sa)
694 + BOOL ret = sa->sa_family != AF_INET
695 + || ((struct sockaddr_in *)sa)->sin_port == htons(445);
696 + DEBUG(4,("connection is%s direct SMB\n", ret ? "" : " not"));
700 +char *print_sockaddr(struct sockaddr *sa)
703 + static char addr[64];
705 + if(sa->sa_family == AF_INET6)
707 + inet_ntop(AF_INET6, &((struct sockaddr_in6 *)sa)->sin6_addr,
708 + addr, sizeof(addr));
712 + if(sa->sa_family == AF_INET)
713 + return inet_ntoa(((struct sockaddr_in *)sa)->sin_addr);
717 +void make_sockaddr_in(struct sockaddr *sa, struct in_addr *addr)
719 + memset(sa, 0, sizeof(struct sockaddr_in));
720 + ((struct sockaddr_in *)sa)->sin_family = AF_INET;
721 + ((struct sockaddr_in *)sa)->sin_port = 0;
722 + memcpy(&((struct sockaddr_in *)sa)->sin_addr, addr,
723 + sizeof(struct in_addr));
726 +void free_sockaddr_list(struct sockaddr_list *salist)
728 + struct sockaddr_list *next;
732 + next = salist->next;
733 + SAFE_FREE(salist->addr);
739 +struct sockaddr_list *make_sin_list(struct in_addr *addr, int count)
742 + struct sockaddr_list *top = NULL, *last = NULL, *sc;
744 + for(i = 0; i<count; ++i)
746 + sc = (struct sockaddr_list *)
747 + malloc(sizeof(struct sockaddr_list));
749 + else last->next = sc;
752 + sc->pfamily = PF_INET;
753 + sc->len = sizeof(struct sockaddr_in);
754 + sc->addr = (struct sockaddr *)
755 + malloc(sizeof(struct sockaddr_in));
756 + make_sockaddr_in(sc->addr, &addr[i]);
761 +struct sockaddr_list *make_singlet_list(struct in_addr *addr, int port)
763 + struct sockaddr_list *salist;
765 + salist = make_sin_list(addr, 1);
766 + if(port) set_sockaddr_port(salist->addr, port);
767 + else salist = set_default_ports(salist);
772 +struct sockaddr_list *make_sa_list(struct addrinfo *ai)
774 + struct sockaddr_list *top = NULL, *last = NULL, *sc;
776 + for(; ai; ai = ai->ai_next)
778 + sc = (struct sockaddr_list *)
779 + malloc(sizeof(struct sockaddr_list));
780 + if(top==NULL) top = sc;
781 + else last->next = sc;
784 + sc->pfamily = ai->ai_family;
785 + sc->len = ai->ai_addrlen;
786 + sc->addr = (struct sockaddr *)malloc(ai->ai_addrlen);
787 + memcpy(sc->addr, ai->ai_addr, ai->ai_addrlen);
793 /*******************************************************************
794 a convenient addition to interpret_addr()
795 ******************************************************************/
796 @@ -1394,7 +1612,7 @@
799 /* maybe its an IP address? */
800 - if (is_ipaddress(s))
801 + if (is_ipv4address(s))
803 struct iface_struct nics[MAX_INTERFACES];
805 diff -ur samba-2.2.8a/source/lib/util_sock.c samba-2.2.8a+IPv6-20030712/source/lib/util_sock.c
806 --- samba-2.2.8a/source/lib/util_sock.c 2003-03-14 16:34:47.000000000 -0500
807 +++ samba-2.2.8a+IPv6-20030712/source/lib/util_sock.c 2003-07-12 22:28:29.000000000 -0400
808 @@ -819,67 +819,94 @@
809 create an outgoing socket. timeout is in milliseconds.
810 **************************************************************************/
812 -int open_socket_out(int type, struct in_addr *addr, int port ,int timeout)
813 +int open_socket_out(struct sockaddr_list *addrs,
814 + struct sockaddr_list **connected_addr, int timeout)
816 - struct sockaddr_in sock_out;
818 - int connect_loop = 250; /* 250 milliseconds */
819 - int loops = (timeout) / connect_loop;
821 - /* create a socket to write to */
822 - res = socket(PF_INET, type, 0);
824 - { DEBUG(0,("socket error\n")); return -1; }
826 - if (type != SOCK_STREAM) return(res);
828 - memset((char *)&sock_out,'\0',sizeof(sock_out));
829 - putip((char *)&sock_out.sin_addr,(char *)addr);
831 - sock_out.sin_port = htons( port );
832 - sock_out.sin_family = PF_INET;
834 - /* set it non-blocking */
835 - set_blocking(res,False);
837 - DEBUG(3,("Connecting to %s at port %d\n",inet_ntoa(*addr),port));
839 - /* and connect it to the destination */
841 - ret = connect(res,(struct sockaddr *)&sock_out,sizeof(sock_out));
843 - /* Some systems return EAGAIN when they mean EINPROGRESS */
844 - if (ret < 0 && (errno == EINPROGRESS || errno == EALREADY ||
845 - errno == EAGAIN) && loops--) {
846 - msleep(connect_loop);
847 - goto connect_again;
850 - if (ret < 0 && (errno == EINPROGRESS || errno == EALREADY ||
851 - errno == EAGAIN)) {
852 - DEBUG(1,("timeout connecting to %s:%d\n",inet_ntoa(*addr),port));
856 + struct sockaddr_list *sl;
858 + int connect_loop = 250; /* 250 milliseconds */
859 + int loops = (timeout) / connect_loop;
861 + if(connected_addr) *connected_addr = NULL;
863 + for(sl = addrs; sl; sl = sl->next)
865 + /* create a socket to write to */
866 + res = socket(sl->pfamily, SOCK_STREAM, 0);
869 + /* If there are more addresses available, then we
870 + * are probably running on a platform without IPv6
871 + * support in the kernel, and we just tried
872 + * connecting to an IPv6 address. Don't complain
873 + * until we're out of addresses. */
875 + if(!sl->next) DEBUG(0,("socket error\n"));
879 + /* set it non-blocking */
880 + set_blocking(res,False);
882 + DEBUG(3,("Connecting to %s at port %d\n",
883 + print_sockaddr(sl->addr), get_sockaddr_port(sl->addr)));
885 + /* and connect it to the destination */
887 + ret = connect(res,sl->addr,sl->len);
889 + /* Some systems return EAGAIN when they mean EINPROGRESS */
890 + if (ret < 0 && (errno == EINPROGRESS || errno == EALREADY ||
891 + errno == EAGAIN) && loops--) {
892 + msleep(connect_loop);
893 + goto connect_again;
896 + if (ret < 0 && (errno == EINPROGRESS || errno == EALREADY ||
897 + errno == EAGAIN)) {
898 + DEBUG(1,("timeout connecting to [%s]:%d\n",
899 + print_sockaddr(sl->addr),
900 + get_sockaddr_port(sl->addr)));
903 + DEBUG(1,("attempting next address...\n"));
909 - if (ret < 0 && errno == EISCONN) {
913 + if (ret < 0 && errno == EISCONN) {
920 - DEBUG(2,("error connecting to %s:%d (%s)\n",
921 - inet_ntoa(*addr),port,strerror(errno)));
926 + /* If we got connection refused or host unreachable,
927 + * we may be trying to connect to an IPv6 host but
928 + * this system isn't configured for IPv6. If we have
929 + * more addresses, don't complain about this one --
930 + * just try the next ones. */
932 + BOOL can_ignore = sl->next &&
933 + (errno == ECONNREFUSED || errno == ENETUNREACH);
934 + DEBUG(can_ignore ? 3 : 2,
935 + ("error connecting to [%s]:%d (%s)\n",
936 + print_sockaddr(sl->addr),
937 + get_sockaddr_port(sl->addr),
943 - /* set it blocking again */
944 - set_blocking(res,True);
945 + /* set it blocking again */
946 + set_blocking(res,True);
949 + if(connected_addr) *connected_addr = sl;
956 /* the following 3 client_*() functions are nasty ways of allowing
958 matchname - determine if host name matches IP address. Used to
959 confirm a hostname lookup to prevent spoof attacks
960 ******************************************************************/
961 -static BOOL matchname(char *remotehost,struct in_addr addr)
963 +static BOOL addr_equal(struct sockaddr *a, struct sockaddr *b)
965 + if(a->sa_family == AF_INET6 && b->sa_family == AF_INET6)
967 + struct sockaddr_in6 *a6 = (struct sockaddr_in6 *)a;
968 + struct sockaddr_in6 *b6 = (struct sockaddr_in6 *)b;
970 + return !memcmp(&a6->sin6_addr, &b6->sin6_addr, 16);
972 + if(a->sa_family == AF_INET && b->sa_family == AF_INET)
974 + struct sockaddr_in *a4 = (struct sockaddr_in *)a;
975 + struct sockaddr_in *b4 = (struct sockaddr_in *)b;
977 + return a4->sin_addr.s_addr == b4->sin_addr.s_addr;
983 +/*******************************************************************
984 + matchname - determine if host name matches IP address. Used to
985 + confirm a hostname lookup to prevent spoof attacks
986 + ******************************************************************/
987 +static BOOL matchname(char *remotehost, struct sockaddr *can)
990 + struct addrinfo *ai, hints, *cur;
992 + memset(&hints, 0, sizeof(hints));
993 + hints.ai_socktype = SOCK_STREAM;
994 + if(getaddrinfo(remotehost, NULL, &hints, &ai)){
995 + DEBUG(0,("getaddrinfo(%s): lookup failure.\n", remotehost));
998 + for( cur = ai; cur; cur = cur->ai_next )
999 + if(addr_equal(cur->ai_addr, can))
1006 + * The host name does not map to the original host address. Perhaps
1007 + * someone has compromised a name server. More likely someone botched
1008 + * it, but that could be dangerous, too.
1011 + DEBUG(0,("host name/address mismatch: %s != %s\n",
1012 + print_sockaddr(can), remotehost));
1018 + struct in_addr addr = ((struct sockaddr_in *)can)->sin_addr;
1021 if ((hp = sys_gethostbyname(remotehost)) == 0) {
1022 @@ -946,6 +1027,56 @@
1023 DEBUG(0,("host name/address mismatch: %s != %s\n",
1024 inet_ntoa(addr), hp->h_name));
1029 +/*******************************************************************
1030 + return a sockaddr describing the remote endpoint
1031 + ******************************************************************/
1032 +static BOOL get_socket_sa(int fd, struct sockaddr **sa, int *len)
1039 + *len = sizeof(struct sockaddr_storage);
1041 + *len = sizeof(struct sockaddr);
1044 + *sa = (struct sockaddr *)malloc(*len);
1046 + if (getpeername(fd, *sa, len) < 0) {
1047 + DEBUG(0,("getpeername failed. Error was %s\n", strerror(errno) ));
1054 + if((*sa)->sa_family == AF_INET6 && IN6_IS_ADDR_V4MAPPED(
1055 + &((struct sockaddr_in6 *)(*sa))->sin6_addr))
1057 + struct sockaddr_in *newsin;
1058 + struct in_addr addr;
1059 + int port = ((struct sockaddr_in6 *)(*sa))->sin6_port;
1061 + DEBUG(5,("converting IPv6-mapped address %s\n",
1062 + print_sockaddr(*sa)));
1063 + memcpy(&addr, &((struct sockaddr_in6 *)
1064 + (*sa))->sin6_addr + 12, 4);
1066 + *len = sizeof(struct sockaddr_in);
1067 + *sa = (struct sockaddr *)malloc(*len);
1068 + newsin = (struct sockaddr_in *)(*sa);
1069 + newsin->sin_family = AF_INET;
1070 + newsin->sin_port = port;
1071 + newsin->sin_addr = addr;
1079 @@ -955,34 +1086,60 @@
1080 char *get_socket_name(int fd)
1082 static pstring name_buf;
1083 - static fstring addr_buf;
1084 - struct hostent *hp;
1085 - struct in_addr addr;
1086 + struct sockaddr *sa;
1090 - p = get_socket_addr(fd);
1092 - /* it might be the same as the last one - save some DNS work */
1093 - if (strcmp(p, addr_buf) == 0) return name_buf;
1095 pstrcpy(name_buf,"UNKNOWN");
1096 if (fd == -1) return name_buf;
1098 - fstrcpy(addr_buf, p);
1099 + if(!get_socket_sa(fd, &sa, &len)) return name_buf;
1100 + p = print_sockaddr(sa);
1102 - addr = *interpret_addr2(p);
1104 - /* Look up the remote host name. */
1105 - if ((hp = gethostbyaddr((char *)&addr.s_addr, sizeof(addr.s_addr), AF_INET)) == 0) {
1106 - DEBUG(1,("Gethostbyaddr failed for %s\n",p));
1107 - pstrcpy(name_buf, p);
1109 - pstrcpy(name_buf,(char *)hp->h_name);
1110 - if (!matchname(name_buf, addr)) {
1111 - DEBUG(0,("Matchname failed on %s %s\n",name_buf,p));
1112 - pstrcpy(name_buf,"UNKNOWN");
1115 + char hostbuf[NI_MAXHOST];
1117 + if(getnameinfo(sa, len, hostbuf, NI_MAXHOST, NULL, 0, 0)) {
1118 + DEBUG(1,("Getnameinfo failed for %s\n",p));
1119 + pstrcpy(name_buf, p);
1121 + if (matchname(hostbuf, sa))
1122 + pstrcpy(name_buf, hostbuf);
1124 + DEBUG(0,("Matchname failed on %s %s\n",
1126 + pstrcpy(name_buf,p);
1132 + struct hostent *hp;
1133 + struct sockaddr_in *nsin = (struct sockaddr_in *)sa;
1135 + if(sa->sa_family != AF_INET)
1141 + /* Look up the remote host name. */
1142 + if ((hp = gethostbyaddr((char *)&nsin->sin_addr.s_addr,
1143 + sizeof(nsin->sin_addr.s_addr), AF_INET)) == 0) {
1144 + DEBUG(1,("Gethostbyaddr failed for %s\n",p));
1145 + pstrcpy(name_buf, p);
1147 + pstrcpy(name_buf,(char *)hp->h_name);
1148 + if (!matchname(name_buf, sa)) {
1149 + DEBUG(0,("Matchname failed on %s %s\n",
1151 + pstrcpy(name_buf,p);
1158 alpha_strcpy(name_buf, name_buf, "_-.", sizeof(name_buf));
1159 if (strstr(name_buf,"..")) {
1160 @@ -997,24 +1154,18 @@
1161 ******************************************************************/
1162 char *get_socket_addr(int fd)
1164 - struct sockaddr sa;
1165 - struct sockaddr_in *sockin = (struct sockaddr_in *) (&sa);
1166 - socklen_t length = sizeof(sa);
1167 static fstring addr_buf;
1168 + struct sockaddr *sa;
1171 fstrcpy(addr_buf,"0.0.0.0");
1175 + if(get_socket_sa(fd, &sa, &len))
1177 + fstrcpy(addr_buf,print_sockaddr(sa));
1181 - if (getpeername(fd, &sa, &length) < 0) {
1182 - DEBUG(0,("getpeername failed. Error was %s\n", strerror(errno) ));
1186 - fstrcpy(addr_buf,(char *)inet_ntoa(sockin->sin_addr));
1191 diff -ur samba-2.2.8a/source/lib/wins_srv.c samba-2.2.8a+IPv6-20030712/source/lib/wins_srv.c
1192 --- samba-2.2.8a/source/lib/wins_srv.c 2003-03-14 16:34:47.000000000 -0500
1193 +++ samba-2.2.8a+IPv6-20030712/source/lib/wins_srv.c 2003-07-12 22:28:29.000000000 -0400
1197 /* Add server to list. */
1198 - if( is_ipaddress( wins_id_bufr ) )
1199 + if( is_ipv4address( wins_id_bufr ) )
1200 entry->ip_addr = *interpret_addr2( wins_id_bufr );
1202 entry->ip_addr = *interpret_addr2( "0.0.0.0" );
1203 diff -ur samba-2.2.8a/source/libsmb/cliconnect.c samba-2.2.8a+IPv6-20030712/source/libsmb/cliconnect.c
1204 --- samba-2.2.8a/source/libsmb/cliconnect.c 2003-03-14 16:34:48.000000000 -0500
1205 +++ samba-2.2.8a+IPv6-20030712/source/libsmb/cliconnect.c 2003-07-12 22:28:29.000000000 -0400
1208 extern pstring user_socket_options;
1210 - /* 445 doesn't have session request */
1211 - if (cli->port == 445) return True;
1212 + /* Direct SMB doesn't have session request */
1213 + if (is_directsmb(cli->connected_addr->addr)) return True;
1215 /* send a session request (RFC 1002) */
1216 memcpy(&(cli->calling), calling, sizeof(*calling));
1217 @@ -690,9 +690,12 @@
1219 int port = (CVAL(cli->inbuf,8)<<8)+CVAL(cli->inbuf,9);
1220 /* SESSION RETARGET */
1221 - putip((char *)&cli->dest_ip,cli->inbuf+4);
1223 - cli->fd = open_socket_out(SOCK_STREAM, &cli->dest_ip, port, LONG_CONNECT_TIMEOUT);
1224 + struct in_addr addr;
1225 + putip((char *)&addr,cli->inbuf+4);
1226 + if(cli->dest_addrs) free_sockaddr_list(cli->dest_addrs);
1227 + cli->dest_addrs = make_singlet_list(&addr, port);
1228 + cli->fd = open_socket_out(cli->dest_addrs,
1229 + &cli->connected_addr, LONG_CONNECT_TIMEOUT);
1233 @@ -736,10 +739,11 @@
1234 Open the client sockets.
1235 ****************************************************************************/
1237 -BOOL cli_connect(struct cli_state *cli, const char *host, struct in_addr *ip)
1238 +BOOL cli_connect(struct cli_state *cli, const char *host,
1239 + struct sockaddr_list *salist)
1241 extern pstring user_socket_options;
1242 - int name_type = 0x20;
1243 + BOOL free_on_error = False;
1246 /* reasonable default hostname */
1247 @@ -747,45 +751,44 @@
1248 host = "*SMBSERVER";
1250 fstrcpy(cli->desthost, host);
1252 - /* allow hostnames of the form NAME#xx and do a netbios lookup */
1253 - if ((p = strchr(cli->desthost, '#'))) {
1254 - name_type = strtol(p+1, NULL, 16);
1258 - if (!ip || is_zero_ip(*ip)) {
1259 - if (!resolve_name(cli->desthost, &cli->dest_ip, name_type)) {
1262 + /* At this point, cli->dest_addrs should be empty */
1263 + if(cli->dest_addrs) free_sockaddr_list(cli->dest_addrs);
1266 + free_on_error = True;
1267 + if ((p = strchr(cli->desthost, '#'))) {
1268 + struct in_addr ip;
1269 + int name_type = strtol(p+1, NULL, 16);
1272 + if(!resolve_name_netbios(cli->desthost, &ip, name_type))
1274 + salist = make_singlet_list(&ip, 139);
1276 + if(!(salist = resolve_name_smb(cli->desthost,
1277 + cli->default_port)))
1281 - *ip = cli->dest_ip;
1283 - cli->dest_ip = *ip;
1287 if (getenv("LIBSMB_PROG")) {
1288 cli->fd = sock_exec(getenv("LIBSMB_PROG"));
1290 - /* try 445 first, then 139 */
1291 - int port = cli->port?cli->port:445;
1292 - cli->fd = open_socket_out(SOCK_STREAM, &cli->dest_ip,
1293 - port, cli->timeout);
1294 - if (cli->fd == -1 && cli->port == 0) {
1296 - cli->fd = open_socket_out(SOCK_STREAM, &cli->dest_ip,
1297 - port, cli->timeout);
1299 - if (cli->fd != -1) cli->port = port;
1300 + cli->fd = open_socket_out(salist, &cli->connected_addr,
1303 if (cli->fd == -1) {
1304 DEBUG(1,("Error connecting to %s (%s)\n",
1305 - inet_ntoa(*ip),strerror(errno)));
1306 + print_sockaddr(salist->addr),strerror(errno)));
1307 + if(free_on_error) free_sockaddr_list(salist);
1311 set_socket_options(cli->fd,user_socket_options);
1313 + cli->dest_addrs = salist;
1318 @@ -794,13 +797,14 @@
1319 ****************************************************************************/
1321 BOOL cli_establish_connection(struct cli_state *cli,
1322 - const char *dest_host, struct in_addr *dest_ip,
1323 + char *dest_host, struct sockaddr_list *salist,
1324 struct nmb_name *calling, struct nmb_name *called,
1325 const char *service, const char *service_type,
1326 BOOL do_shutdown, BOOL do_tcon)
1328 DEBUG(5,("cli_establish_connection: %s connecting to %s (%s) - %s [%s]\n",
1329 - nmb_namestr(calling), nmb_namestr(called), inet_ntoa(*dest_ip),
1330 + nmb_namestr(calling), nmb_namestr(called),
1331 + salist ? print_sockaddr(salist->addr) : "unspecified",
1332 cli->user_name, cli->domain));
1334 /* establish connection */
1335 @@ -809,9 +813,12 @@
1338 if (cli->fd == -1) {
1339 - if (!cli_connect(cli, dest_host, dest_ip)) {
1340 + if (!cli_connect(cli, dest_host, salist))
1342 DEBUG(1,("cli_establish_connection: failed to connect to %s (%s)\n",
1343 - nmb_namestr(called), inet_ntoa(*dest_ip)));
1344 + nmb_namestr(called),
1345 + salist ? print_sockaddr(salist->addr)
1351 struct nmb_name calling;
1352 struct nmb_name called;
1353 struct cli_state *cli;
1354 - struct in_addr ip;
1355 + struct sockaddr_list *salist;
1358 DEBUG(0, ("output_cli is NULL!?!"));
1359 @@ -964,14 +971,14 @@
1360 return NT_STATUS_UNSUCCESSFUL;
1364 + salist = make_singlet_list(dest_ip, port);
1366 DEBUG(3,("Connecting to host=%s share=%s\n", dest_host, service));
1368 - if (!cli_connect(cli, dest_host, &ip)) {
1369 + if (!cli_connect(cli, dest_host, salist)) {
1370 DEBUG(1,("cli_establish_connection: failed to connect to %s (%s)\n",
1371 nmb_namestr(&called), inet_ntoa(*dest_ip)));
1372 - cli_shutdown(cli);
1373 + free_sockaddr_list(salist);
1374 return NT_STATUS_UNSUCCESSFUL;
1377 @@ -1031,9 +1038,10 @@
1378 Attempt a NetBIOS session request, falling back to *SMBSERVER if needed.
1379 ****************************************************************************/
1381 -BOOL attempt_netbios_session_request(struct cli_state *cli, const char *srchost, const char *desthost,
1382 - struct in_addr *pdest_ip)
1383 +BOOL attempt_netbios_session_request(struct cli_state *cli, char *srchost,
1386 + struct sockaddr_list *dest_addrs_cache = cli->dest_addrs;
1387 struct nmb_name calling, called;
1389 make_nmb_name(&calling, srchost, 0x0);
1390 @@ -1076,9 +1084,11 @@
1391 * for this purpose. JRA. Based on work by "Kim R. Pedersen" <krp@filanet.dk>.
1394 + cli->dest_addrs = NULL; /* we cached it, so it shouldn't free */
1395 cli_close_connection(cli);
1397 - if (!cli_initialise(cli) || !cli_connect(cli, desthost, pdest_ip) ||
1398 + if (!cli_initialise(cli) ||
1399 + !cli_connect(cli, desthost, dest_addrs_cache) ||
1400 !cli_session_request(cli, &calling, &smbservername)) {
1401 DEBUG(0,("attempt_netbios_session_request: %s rejected the session for name *SMBSERVER with error %s\n",
1402 desthost, cli_errstr(cli) ));
1403 diff -ur samba-2.2.8a/source/libsmb/clidgram.c samba-2.2.8a+IPv6-20030712/source/libsmb/clidgram.c
1404 --- samba-2.2.8a/source/libsmb/clidgram.c 2003-03-14 16:34:48.000000000 -0500
1405 +++ samba-2.2.8a+IPv6-20030712/source/libsmb/clidgram.c 2003-07-12 22:28:29.000000000 -0400
1407 struct sockaddr_in sock_out;
1408 socklen_t name_size;
1410 - if (!resolve_name(send_to_name, &sendto_ip, 0x1d)) {
1411 + if (!resolve_name_netbios(send_to_name, &sendto_ip, 0x1d)) {
1413 DEBUG(0, ("Could not resolve name: %s<1D>\n", send_to_name));
1415 @@ -156,17 +156,15 @@
1417 my_ip.s_addr = inet_addr("0.0.0.0");
1419 - if (!resolve_name(myname, &my_ip, 0x00)) { /* FIXME: Call others here */
1420 + if (!resolve_name_netbios(myname, &my_ip, 0x00)) { /* FIXME: Call others here */
1422 DEBUG(0, ("Could not resolve name: %s<00>\n", myname));
1426 - if ((dgram_sock = open_socket_out(SOCK_DGRAM, &sendto_ip, 138, LONG_CONNECT_TIMEOUT)) < 0) {
1428 - DEBUG(4, ("open_sock_out failed ..."));
1429 + if ((dgram_sock = socket(PF_INET, SOCK_DGRAM, 0)) < 0) {
1430 + DEBUG(0, ("socket failed (%s)", strerror(errno)));
1435 /* Make it a broadcast socket ... */
1436 diff -ur samba-2.2.8a/source/libsmb/clientgen.c samba-2.2.8a+IPv6-20030712/source/libsmb/clientgen.c
1437 --- samba-2.2.8a/source/libsmb/clientgen.c 2002-12-10 09:58:15.000000000 -0500
1438 +++ samba-2.2.8a+IPv6-20030712/source/libsmb/clientgen.c 2003-07-12 22:28:29.000000000 -0400
1440 #include "includes.h"
1442 /****************************************************************************
1443 - Change the port number used to call on.
1444 + Change the default port number used to call on.
1446 + This should only truly be used if we're operating on a non-standard
1447 + port. The default behavior is to first try port 445, then 139.
1448 ****************************************************************************/
1450 int cli_set_port(struct cli_state *cli, int port)
1453 + cli->default_port = port;
1462 + cli->default_port = 0;
1463 + cli->dest_addrs = NULL;
1464 + cli->connected_addr = NULL;
1467 cli->pid = (uint16)sys_getpid();
1469 SAFE_FREE(cli->outbuf);
1470 SAFE_FREE(cli->inbuf);
1472 + if (cli->dest_addrs)
1473 + free_sockaddr_list(cli->dest_addrs);
1476 talloc_destroy(cli->mem_ctx);
1477 cli->mem_ctx = NULL;
1478 diff -ur samba-2.2.8a/source/libsmb/cli_lsarpc.c samba-2.2.8a+IPv6-20030712/source/libsmb/cli_lsarpc.c
1479 --- samba-2.2.8a/source/libsmb/cli_lsarpc.c 2002-06-06 17:31:33.000000000 -0400
1480 +++ samba-2.2.8a+IPv6-20030712/source/libsmb/cli_lsarpc.c 2003-07-12 22:28:29.000000000 -0400
1481 @@ -1064,6 +1064,7 @@
1483 extern pstring global_myname;
1484 struct cli_state cli;
1485 + struct sockaddr_list *dest_addrs;
1489 @@ -1074,20 +1075,22 @@
1493 - if(!resolve_name( remote_machine, &cli.dest_ip, 0x20)) {
1494 + if(!(dest_addrs = resolve_name_smb(remote_machine, 0))) {
1495 DEBUG(0,("fetch_domain_sid: Can't resolve address for %s\n", remote_machine));
1499 - if (!cli_connect(&cli, remote_machine, &cli.dest_ip)) {
1500 + if (!cli_connect(&cli, remote_machine, dest_addrs)) {
1501 DEBUG(0,("fetch_domain_sid: unable to connect to SMB server on \
1502 machine %s. Error was : %s.\n", remote_machine, cli_errstr(&cli) ));
1506 - if (!attempt_netbios_session_request(&cli, global_myname, remote_machine, &cli.dest_ip)) {
1507 + if (!attempt_netbios_session_request(&cli, global_myname,
1508 + remote_machine)) {
1509 DEBUG(0,("fetch_domain_sid: machine %s rejected the NetBIOS session request.\n",
1511 + free_sockaddr_list(dest_addrs);
1515 diff -ur samba-2.2.8a/source/libsmb/cli_pipe_util.c samba-2.2.8a+IPv6-20030712/source/libsmb/cli_pipe_util.c
1516 --- samba-2.2.8a/source/libsmb/cli_pipe_util.c 2003-03-14 16:34:47.000000000 -0500
1517 +++ samba-2.2.8a+IPv6-20030712/source/libsmb/cli_pipe_util.c 2003-07-12 22:28:29.000000000 -0400
1519 const char *pipe_name,
1520 struct ntuser_creds *creds)
1522 - struct in_addr dest_ip;
1523 + struct sockaddr_list *dest_addrs;
1524 struct nmb_name calling, called;
1526 extern pstring global_myname;
1529 /* Establish a SMB connection */
1531 - if (!resolve_srv_name(system_name, dest_host, &dest_ip)) {
1532 + if (!(dest_addrs = resolve_srv_name(system_name, dest_host,
1533 + cli->default_port))) {
1537 make_nmb_name(&called, dns_to_netbios_name(dest_host), 0x20);
1538 make_nmb_name(&calling, dns_to_netbios_name(global_myname), 0);
1540 - if (!cli_establish_connection(cli, dest_host, &dest_ip, &calling,
1541 + if (!cli_establish_connection(cli, dest_host, dest_addrs, &calling,
1542 &called, "IPC$", "IPC", False, True)) {
1543 + cli_shutdown(cli);
1544 + free_sockaddr_list(dest_addrs);
1548 diff -ur samba-2.2.8a/source/libsmb/libsmbclient.c samba-2.2.8a+IPv6-20030712/source/libsmb/libsmbclient.c
1549 --- samba-2.2.8a/source/libsmb/libsmbclient.c 2003-02-28 10:56:19.000000000 -0500
1550 +++ samba-2.2.8a+IPv6-20030712/source/libsmb/libsmbclient.c 2003-07-12 22:28:30.000000000 -0400
1551 @@ -244,10 +244,8 @@
1552 char *p, *server_n = server;
1555 - struct in_addr ip;
1556 int tried_reverse = 0;
1561 /* try to use an existing connection */
1562 @@ -305,10 +303,8 @@
1564 slprintf(ipenv,sizeof(ipenv)-1,"HOST_%s", server_n);
1568 /* have to open a new connection */
1569 - if (!cli_initialise(&c) || !cli_connect(&c, server_n, &ip)) {
1570 + if (!cli_initialise(&c) || !cli_connect(&c, server_n, NULL)) {
1571 if (c.initialised) cli_shutdown(&c);
1576 /* Only try this if server is an IP address ... */
1578 - if (is_ipaddress(server) && !tried_reverse) {
1579 + if (is_ipv4address(server) && !tried_reverse) {
1580 fstring remote_name;
1581 struct in_addr rem_ip;
1583 @@ -1617,8 +1613,8 @@
1584 /* first try to get the LMB for our workgroup, and if that fails, */
1587 - if (!(resolve_name(lp_workgroup(), &rem_ip, 0x1d) ||
1588 - resolve_name(lp_workgroup(), &rem_ip, 0x1b))) {
1589 + if (!(resolve_name_netbios(lp_workgroup(), &rem_ip, 0x1d) ||
1590 + resolve_name_netbios(lp_workgroup(), &rem_ip, 0x1b))) {
1592 errno = EINVAL; /* Something wrong with smb.conf? */
1594 @@ -1689,9 +1685,9 @@
1595 /* Check to see if <server><1D>, <server><1B>, or <server><20> translates */
1596 /* However, we check to see if <server> is an IP address first */
1598 - if (!is_ipaddress(server) && /* Not an IP addr so check next */
1599 - (resolve_name(server, &rem_ip, 0x1d) || /* Found LMB */
1600 - resolve_name(server, &rem_ip, 0x1b) )) { /* Found DMB */
1601 + if (!is_ipv4address(server) && /* Not an IP addr so check next */
1602 + (resolve_name_netbios(server, &rem_ip, 0x1d) || /* Found LMB */
1603 + resolve_name_netbios(server, &rem_ip, 0x1b) )) { /* Found DMB */
1606 smbc_file_table[slot]->dir_type = SMBC_SERVER;
1607 @@ -1743,8 +1739,7 @@
1612 - if (resolve_name(server, &rem_ip, 0x20)) {
1613 + if (resolve_name_netbios(server, &rem_ip, 0x20)) {
1615 /* Now, list the shares ... */
1617 diff -ur samba-2.2.8a/source/libsmb/namequery.c samba-2.2.8a+IPv6-20030712/source/libsmb/namequery.c
1618 --- samba-2.2.8a/source/libsmb/namequery.c 2003-03-14 16:34:48.000000000 -0500
1619 +++ samba-2.2.8a+IPv6-20030712/source/libsmb/namequery.c 2003-07-12 22:28:30.000000000 -0400
1620 @@ -643,15 +643,11 @@
1621 Resolve via "bcast" method.
1622 *********************************************************/
1624 -BOOL name_resolve_bcast(const char *name, int name_type,
1625 - struct in_addr **return_ip_list, int *return_count)
1626 +struct sockaddr_list *name_resolve_bcast(const char *name, int name_type)
1629 int num_interfaces = iface_count();
1631 - *return_ip_list = NULL;
1632 - *return_count = 0;
1635 * "bcast" means do a broadcast lookup on all the local interfaces.
1638 sock = open_socket_in( SOCK_DGRAM, 0, 3,
1639 interpret_addr(lp_socket_address()), True );
1641 - if (sock == -1) return False;
1642 + if (sock == -1) return NULL;
1644 set_socket_options(sock,"SO_BROADCAST");
1646 @@ -670,35 +666,37 @@
1648 for( i = num_interfaces-1; i >= 0; i--) {
1649 struct in_addr sendto_ip;
1651 + struct in_addr *addr;
1652 + int return_count, flags;
1654 /* Done this way to fix compiler error on IRIX 5.x */
1655 sendto_ip = *iface_bcast(*iface_n_ip(i));
1656 - *return_ip_list = name_query(sock, name, name_type, True,
1657 - True, sendto_ip, return_count, &flags);
1658 - if(*return_ip_list != NULL) {
1666 + addr = name_query(sock, name, name_type, True,
1667 + True, sendto_ip, &return_count, &flags);
1668 + if(addr != NULL) {
1669 + struct sockaddr_list *salist;
1672 + salist = make_sin_list(addr, return_count);
1682 /********************************************************
1683 Resolve via "wins" method.
1684 *********************************************************/
1686 -static BOOL resolve_wins(const char *name, int name_type,
1687 - struct in_addr **return_iplist, int *return_count)
1688 +static struct sockaddr_list *resolve_wins(const char *name, int name_type)
1691 struct in_addr wins_ip;
1694 - *return_iplist = NULL;
1695 - *return_count = 0;
1698 * "wins" means do a unicast lookup to the WINS server.
1699 * Ignore if there is no WINS server specified or if the
1702 } else if( wins_srv_count() < 1 ) {
1703 DEBUG(3,("resolve_wins: WINS server resolution selected and no WINS servers listed.\n"));
1707 wins_ip = wins_srv_ip();
1708 wins_ismyip = ismyip(wins_ip);
1709 @@ -731,28 +729,32 @@
1710 interpret_addr(lp_socket_address()),
1714 - *return_iplist = name_query( sock, name,
1717 - return_count, &flags);
1718 - if(*return_iplist != NULL) {
1722 + struct in_addr *addr;
1723 + int return_count, flags;
1725 + addr = name_query(sock, name,
1728 + &return_count, &flags);
1730 + if(addr != NULL) {
1731 + struct sockaddr_list *salist;
1733 + salist = make_sin_list(addr, return_count);
1744 /********************************************************
1745 Resolve via "lmhosts" method.
1746 *********************************************************/
1748 -static BOOL resolve_lmhosts(const char *name, int name_type,
1749 - struct in_addr **return_iplist, int *return_count)
1750 +static struct sockaddr_list *resolve_lmhosts(const char *name, int name_type)
1753 * "lmhosts" means parse the local lmhosts file.
1756 struct in_addr return_ip;
1758 - *return_iplist = NULL;
1759 - *return_count = 0;
1761 DEBUG(3,("resolve_lmhosts: Attempting lmhosts lookup for name %s<0x%x>\n", name, name_type));
1763 fp = startlmhosts( LMHOSTSFILE );
1764 @@ -775,19 +774,12 @@
1765 ((name_type2 == -1) || (name_type == name_type2))
1768 - *return_iplist = (struct in_addr *)malloc(sizeof(struct in_addr));
1769 - if(*return_iplist == NULL) {
1770 - DEBUG(3,("resolve_lmhosts: malloc fail !\n"));
1773 - **return_iplist = return_ip;
1774 - *return_count = 1;
1776 + return make_sin_list(&return_ip, 1);
1786 @@ -795,34 +787,45 @@
1787 Resolve via "hosts" method.
1788 *********************************************************/
1790 -static BOOL resolve_hosts(const char *name,
1791 - struct in_addr **return_iplist, int *return_count)
1792 +static struct sockaddr_list *resolve_hosts(const char *name)
1795 * "host" means do a localhost, or dns lookup.
1798 + struct addrinfo *ai, hints;
1799 + struct sockaddr_list *ret;
1801 + DEBUG(3,("resolve_hosts: Attempting getaddrinfo for name %s<0x20>\n", name));
1802 + memset(&hints, 0, sizeof(hints));
1803 + hints.ai_socktype = SOCK_STREAM;
1804 + if(getaddrinfo(name, NULL, &hints, &ai)) return NULL;
1805 + ret = make_sa_list(ai);
1811 - *return_iplist = NULL;
1812 - *return_count = 0;
1814 DEBUG(3,("resolve_hosts: Attempting host lookup for name %s<0x20>\n", name));
1817 if (((hp = sys_gethostbyname(name)) != NULL) && (hp->h_addr != NULL)) {
1819 + struct in_addr addr;
1820 + struct sockaddr_list *top = NULL, **cur = ⊤
1822 while (hp->h_addr_list[i]) i++;
1823 DEBUG(10, ("%d addresses returned\n", i));
1824 - *return_iplist = (struct in_addr *)malloc(i*sizeof(struct in_addr));
1825 - if(*return_iplist == NULL) {
1826 - DEBUG(3,("resolve_hosts: malloc fail !\n"));
1829 for (j = 0; j < i; j++)
1830 - putip(&(*return_iplist)[j], (char *)hp->h_addr_list[j]);
1831 - *return_count = i;
1834 + memcpy(&addr.s_addr, hp->h_addr_list[j],
1835 + sizeof(addr.s_addr));
1836 + *cur = make_sin_list(&addr, 1);
1837 + cur = &(*cur)->next;
1846 /********************************************************
1847 @@ -830,49 +833,54 @@
1848 Use this function if the string is either an IP address, DNS
1849 or host name or NetBIOS name. This uses the name switch in the
1850 smb.conf to determine the order of name resolution.
1852 + WARNING: This function returns sockaddrs without the port set!
1853 + Don't try to connect to these without first setting
1855 *********************************************************/
1857 -static BOOL internal_resolve_name(const char *name, int name_type,
1858 - struct in_addr **return_iplist, int *return_count)
1859 +static struct sockaddr_list *internal_resolve_name(const char *name,
1862 pstring name_resolve_list;
1865 - BOOL allones = (strcmp(name,"255.255.255.255") == 0);
1866 - BOOL allzeros = (strcmp(name,"0.0.0.0") == 0);
1867 - BOOL is_address = is_ipaddress(name);
1868 - BOOL result = False;
1869 - struct in_addr *nodupes_iplist;
1872 - *return_iplist = NULL;
1873 - *return_count = 0;
1875 - if (allzeros || allones || is_address) {
1876 - *return_iplist = (struct in_addr *)malloc(sizeof(struct in_addr));
1877 - if(*return_iplist == NULL) {
1878 - DEBUG(3,("internal_resolve_name: malloc fail !\n"));
1882 - /* if it's in the form of an IP address then get the lib to interpret it */
1883 - if (((*return_iplist)->s_addr = inet_addr(name)) == 0xFFFFFFFF ){
1884 - DEBUG(1,("internal_resolve_name: inet_addr failed on %s\n", name));
1888 - (*return_iplist)->s_addr = allones ? 0xFFFFFFFF : 0;
1889 - *return_count = 1;
1894 + struct sockaddr_list *salist = NULL, *cur;
1896 + if (is_ipaddress(name)) {
1897 + /* if it's in the form of an IP address then get
1898 + * the lib to interpret it */
1899 + struct sockaddr *sa;
1901 + if(!(sa = get_numeric_addr(name))) return NULL;
1902 + salist = (struct sockaddr_list *)malloc(sizeof(struct sockaddr_list));
1903 + salist->next = NULL;
1904 + salist->addr = sa;
1906 + /* This isn't kosher, but it would take a lot to make Samba
1907 + * be truly AF-independent. */
1909 + if( sa->sa_family == AF_INET6 )
1911 + salist->pfamily = PF_INET6;
1912 + salist->len = sizeof(struct sockaddr_in6);
1916 + salist->pfamily = PF_INET;
1917 + salist->len = sizeof(struct sockaddr_in);
1923 /* Check netbios name cache */
1925 if (namecache_fetch(name, name_type, return_iplist, return_count)) {
1926 /* This could be a negative response */
1927 return (*return_count > 0);
1931 pstrcpy(name_resolve_list, lp_name_resolve_order());
1932 ptr = name_resolve_list;
1933 @@ -881,147 +889,177 @@
1935 while (next_token(&ptr, tok, LIST_SEP, sizeof(tok))) {
1936 if((strequal(tok, "host") || strequal(tok, "hosts"))) {
1937 - if (name_type == 0x20 && resolve_hosts(name, return_iplist, return_count)) {
1940 + if (name_type == 0x20 && (salist = resolve_hosts(name)))
1944 } else if(strequal( tok, "lmhosts")) {
1945 - if (resolve_lmhosts(name, name_type, return_iplist, return_count)) {
1948 + if ((salist=resolve_lmhosts(name, name_type))) {
1951 } else if(strequal( tok, "wins")) {
1952 /* don't resolve 1D via WINS */
1953 if (name_type != 0x1D &&
1954 - resolve_wins(name, name_type, return_iplist, return_count)) {
1957 + (salist=resolve_wins(name, name_type))) {
1960 } else if(strequal( tok, "bcast")) {
1961 - if (name_resolve_bcast(name, name_type, return_iplist, return_count)) {
1964 + if ((salist=name_resolve_bcast(name, name_type))) {
1968 DEBUG(0,("resolve_name: unknown name switch type %s\n", tok));
1972 - /* All of the resolve_* functions above have returned false. */
1974 - SAFE_FREE(*return_iplist);
1979 /* Remove duplicate entries. Some queries, notably #1c (domain
1980 - controllers) return the PDC in iplist[0] and then all domain
1981 - controllers including the PDC in iplist[1..n]. Iterating over
1982 - the iplist when the PDC is down will cause two sets of timeouts. */
1984 - if (*return_count && (nodupes_iplist =
1985 - (struct in_addr *)malloc(sizeof(struct in_addr) * (*return_count)))) {
1986 - int nodupes_count = 0;
1988 - /* Iterate over return_iplist looking for duplicates */
1990 - for (i = 0; i < *return_count; i++) {
1991 - BOOL is_dupe = False;
1994 - for (j = i + 1; j < *return_count; j++) {
1995 - if (ip_equal((*return_iplist)[i],
1996 - (*return_iplist)[j])) {
2004 - /* This one not a duplicate */
2006 - nodupes_iplist[nodupes_count] = (*return_iplist)[i];
2011 - /* Switcheroo with original list */
2013 - free(*return_iplist);
2015 - *return_iplist = nodupes_iplist;
2016 - *return_count = nodupes_count;
2017 + controllers) return the PDC in the first node and then all domain
2018 + controllers including the PDC in the remainder of the list.
2019 + Iterating over the list when the PDC is down will cause two
2020 + sets of timeouts. */
2022 + for (cur = salist; cur; cur = cur->next)
2024 + struct sockaddr_list *i;
2026 + for(i = cur; i->next; i = i->next)
2028 + if(sa_host_equal(cur->addr,i->next->addr))
2030 + struct sockaddr_list *del = i->next;
2032 + i->next = del->next;
2034 + free_sockaddr_list(del);
2039 - /* Display some debugging info */
2041 - DEBUG(10, ("internal_resolve_name: returning %d addresses: ",
2044 - for (i = 0; i < *return_count; i++)
2045 - DEBUGADD(10, ("%s ", inet_ntoa((*return_iplist)[i])));
2047 - DEBUG(10, ("\n"));
2054 +static BOOL internal_resolve_name_netbios(const char *name, int name_type,
2055 + struct in_addr **return_iplist, int *return_count)
2057 + struct sockaddr_list *salist, *sl;
2060 + *return_iplist = NULL;
2061 + *return_count = 0;
2063 + salist = internal_resolve_name(name, name_type);
2064 + if(!salist) return False;
2066 + for(sl = salist; sl; sl = sl->next)
2067 + if(sl->addr->sa_family == AF_INET) ++*return_count;
2069 + *return_iplist = (struct in_addr *)
2070 + malloc(*return_count * sizeof(struct in_addr));
2072 + for(i = 0, sl = salist; i < *return_count; ++i)
2073 + if(sl->addr->sa_family == AF_INET)
2074 + *return_iplist[i] =
2075 + ((struct sockaddr_in *)(sl->addr))->sin_addr;
2077 + free_sockaddr_list(salist);
2083 /********************************************************
2084 - Internal interface to resolve a name into one IP address.
2085 + Internal interface to resolve a name into one IP address for NetBIOS.
2086 Use this function if the string is either an IP address, DNS
2087 or host name or NetBIOS name. This uses the name switch in the
2088 smb.conf to determine the order of name resolution.
2089 *********************************************************/
2091 -BOOL resolve_name(const char *name, struct in_addr *return_ip, int name_type)
2092 +BOOL resolve_name_netbios(const char *name, struct in_addr *return_ip,
2095 - struct in_addr *ip_list = NULL;
2097 + struct sockaddr_list *salist;
2099 if (is_ipaddress(name)) {
2100 *return_ip = *interpret_addr2(name);
2104 - if(internal_resolve_name(name, name_type, &ip_list, &count)) {
2106 + if((salist = internal_resolve_name(name, name_type))) {
2107 + struct sockaddr_list *sl;
2110 /* only return valid addresses for TCP connections */
2111 - for (i=0; i<count; i++) {
2112 - char *ip_str = inet_ntoa(ip_list[i]);
2114 + for(sl = salist; sl; sl = sl->next) {
2115 + if ( sl->addr->sa_family == AF_INET &&
2116 + (ip_str = inet_ntoa(((struct sockaddr_in *)
2117 + (sl->addr))->sin_addr)) &&
2118 strcmp(ip_str, "255.255.255.255") != 0 &&
2119 strcmp(ip_str, "0.0.0.0") != 0) {
2120 - *return_ip = ip_list[i];
2121 - SAFE_FREE(ip_list);
2122 + *return_ip = ((struct sockaddr_in *)
2123 + (sl->addr))->sin_addr;
2124 + free_sockaddr_list(salist);
2128 + free_sockaddr_list(salist);
2130 - SAFE_FREE(ip_list);
2134 -/**************************************************************************
2135 - Resolve a name to a list of addresses
2136 -**************************************************************************/
2137 -BOOL resolve_name_2(const char *name, struct in_addr **return_ip, int *count, int name_type)
2138 +/********************************************************
2139 + Function to resolve a name into a list of addresses for
2140 + use with SMB. This uses the name switch in the smb.conf
2141 + to determine the order of name resolution.
2142 +*********************************************************/
2144 +struct sockaddr_list *resolve_name_smb(const char *name, int port)
2146 + struct sockaddr_list *salist;
2148 - return internal_resolve_name(name, name_type, return_ip, count);
2149 + if((salist=internal_resolve_name(name, 0x20))) {
2150 + struct sockaddr_list *sl = salist, *old = NULL;
2154 + /* only return valid addresses for TCP connections */
2157 + if ( sl->addr->sa_family == AF_INET &&
2158 + (ip_str = inet_ntoa(((struct sockaddr_in *)
2159 + (sl->addr))->sin_addr)) &&
2160 + ( strcmp(ip_str, "255.255.255.255") == 0 ||
2161 + strcmp(ip_str, "0.0.0.0") == 0 ) )
2163 + struct sockaddr_list *next = sl->next;
2165 + SAFE_FREE(sl->addr);
2167 + if(old == NULL) salist = next;
2168 + else old->next = next;
2171 + if(port) set_sockaddr_port(sl->addr, port);
2177 + return port ? salist : set_default_ports(salist);
2181 /********************************************************
2182 resolve a name of format \\server_name or \\ipaddress
2183 into a name. also, cut the \\ from the front for us.
2184 *********************************************************/
2186 -BOOL resolve_srv_name(const char* srv_name, fstring dest_host,
2187 - struct in_addr *ip)
2188 +struct sockaddr_list *resolve_srv_name(const char* srv_name,
2189 + fstring dest_host, int port)
2192 const char *sv_name = srv_name;
2193 + struct in_addr ip;
2194 + struct sockaddr_list *salist;
2196 DEBUG(10,("resolve_srv_name: %s\n", srv_name));
2198 @@ -1029,8 +1067,11 @@
2200 extern pstring global_myname;
2201 fstrcpy(dest_host, global_myname);
2202 - ip = interpret_addr2("127.0.0.1");
2204 + inet_aton("127.0.0.1", &ip);
2205 + salist = make_sin_list(&ip, 1);
2206 + if(port) set_sockaddr_port(salist->addr, port);
2207 + else salist = set_default_ports(salist);
2211 if (strnequal("\\\\", srv_name, 2))
2212 @@ -1042,18 +1083,24 @@
2213 /* treat the '*' name specially - it is a magic name for the PDC */
2214 if (strcmp(dest_host,"*") == 0) {
2215 extern pstring global_myname;
2216 - ret = resolve_name(lp_workgroup(), ip, 0x1B);
2217 - lookup_dc_name(global_myname, lp_workgroup(), ip, dest_host);
2219 - ret = resolve_name(dest_host, ip, 0x20);
2221 + if(resolve_name_netbios(lp_workgroup(), &ip, 0x1B))
2223 + lookup_dc_name(global_myname, lp_workgroup(),
2225 + return make_singlet_list( &ip, port );
2230 + salist = resolve_name_smb(dest_host, port);
2232 if (is_ipaddress(dest_host))
2234 fstrcpy(dest_host, "*SMBSERVER");
2242 @@ -1066,12 +1113,12 @@
2243 struct in_addr *ip_list = NULL;
2246 - if (internal_resolve_name(group, 0x1D, &ip_list, &count)) {
2247 + if (internal_resolve_name_netbios(group, 0x1D, &ip_list, &count)) {
2248 *master_ip = ip_list[0];
2252 - if(internal_resolve_name(group, 0x1B, &ip_list, &count)) {
2253 + if(internal_resolve_name_netbios(group, 0x1B, &ip_list, &count)) {
2254 *master_ip = ip_list[0];
2257 @@ -1309,7 +1356,7 @@
2258 struct in_addr *return_iplist = NULL;
2261 - return internal_resolve_name(group, name_type, ip_list, count);
2262 + return internal_resolve_name_netbios(group, name_type, ip_list, count);
2265 while (next_token(&p,name,LIST_SEP,sizeof(name))) {
2266 @@ -1318,14 +1365,14 @@
2267 * Use 1C followed by 1B. This shouldn't work but with
2268 * broken WINS servers it might. JRA.
2270 - if (!pdc_only && internal_resolve_name(group, 0x1C, ip_list, count))
2271 + if (!pdc_only && internal_resolve_name_netbios(group, 0x1C, ip_list, count))
2273 - return internal_resolve_name(group, 0x1B, ip_list, count);
2274 + return internal_resolve_name_netbios(group, 0x1B, ip_list, count);
2278 if (num_addresses == 0)
2279 - return internal_resolve_name(group, name_type, ip_list, count);
2280 + return internal_resolve_name_netbios(group, name_type, ip_list, count);
2282 return_iplist = (struct in_addr *)malloc(num_addresses * sizeof(struct in_addr));
2283 if(return_iplist == NULL) {
2284 @@ -1337,7 +1384,7 @@
2285 while (next_token(&p,name,LIST_SEP,sizeof(name))) {
2286 struct in_addr *more_ip, *tmp;
2288 - if (resolve_name_2( name, &more_ip, &count_more, 0x20) == False)
2289 + if (internal_resolve_name_netbios( name, 0x20, &more_ip, &count_more ) == False)
2291 tmp = (struct in_addr *)realloc(return_iplist,(num_addresses + count_more) * sizeof(struct in_addr));
2292 if (return_iplist == NULL) {
2293 @@ -1355,7 +1402,7 @@
2294 *ip_list = return_iplist;
2295 return (*count != 0);
2297 - return internal_resolve_name(group, name_type, ip_list, count);
2298 + return internal_resolve_name_netbios(group, name_type, ip_list, count);
2301 /********************************************************
2302 @@ -1364,5 +1411,5 @@
2304 BOOL get_lmb_list(struct in_addr **ip_list, int *count)
2306 - return internal_resolve_name( MSBROWSE, 0x1, ip_list, count);
2307 + return internal_resolve_name_netbios( MSBROWSE, 0x1, ip_list, count);
2309 diff -ur samba-2.2.8a/source/libsmb/passchange.c samba-2.2.8a+IPv6-20030712/source/libsmb/passchange.c
2310 --- samba-2.2.8a/source/libsmb/passchange.c 2000-01-07 01:55:34.000000000 -0500
2311 +++ samba-2.2.8a+IPv6-20030712/source/libsmb/passchange.c 2003-07-12 22:28:30.000000000 -0400
2314 struct nmb_name calling, called;
2315 struct cli_state cli;
2316 - struct in_addr ip;
2317 + struct sockaddr_list *dest_addrs;
2321 - if(!resolve_name( remote_machine, &ip, 0x20)) {
2322 + if(!(dest_addrs = resolve_name_smb(remote_machine, 0))) {
2323 slprintf(err_str, err_str_len-1, "unable to find an IP address for machine %s.\n",
2330 - if (!cli_initialise(&cli) || !cli_connect(&cli, remote_machine, &ip)) {
2331 + if (!cli_initialise(&cli) ||
2332 + !cli_connect(&cli, remote_machine, dest_addrs)) {
2333 slprintf(err_str, err_str_len-1, "unable to connect to SMB server on machine %s. Error was : %s.\n",
2334 remote_machine, cli_errstr(&cli) );
2335 + free_sockaddr_list(dest_addrs);
2339 diff -ur samba-2.2.8a/source/nmbd/nmbd_synclists.c samba-2.2.8a+IPv6-20030712/source/nmbd/nmbd_synclists.c
2340 --- samba-2.2.8a/source/nmbd/nmbd_synclists.c 2003-03-14 16:34:48.000000000 -0500
2341 +++ samba-2.2.8a+IPv6-20030712/source/nmbd/nmbd_synclists.c 2003-07-12 22:28:30.000000000 -0400
2343 extern fstring local_machine;
2344 fstring unix_workgroup;
2345 static struct cli_state cli;
2346 + struct sockaddr_list *dest_addrs;
2347 uint32 local_type = local ? SV_TYPE_LOCAL_LIST_ONLY : 0;
2348 struct nmb_name called, calling;
2351 * Patch from Andy Levine andyl@epicrealm.com.
2354 - if (!cli_initialise(&cli) || !cli_set_port(&cli, 139) || !cli_connect(&cli, name, &ip)) {
2355 + dest_addrs = make_singlet_list(&ip, 0);
2356 + if (!cli_initialise(&cli) || !cli_connect(&cli, name, dest_addrs)) {
2357 + free_sockaddr_list(dest_addrs);
2361 diff -ur samba-2.2.8a/source/rpcclient/rpcclient.c samba-2.2.8a+IPv6-20030712/source/rpcclient/rpcclient.c
2362 --- samba-2.2.8a/source/rpcclient/rpcclient.c 2003-03-14 16:34:49.000000000 -0500
2363 +++ samba-2.2.8a+IPv6-20030712/source/rpcclient/rpcclient.c 2003-07-12 22:28:30.000000000 -0400
2366 /* Resolve the IP address */
2368 - if (!resolve_name(server, &server_ip, 0x20)) {
2369 + if (!resolve_name_netbios(server, &server_ip, 0x20)) {
2370 DEBUG(1,("Unable to resolve %s\n", server));
2373 diff -ur samba-2.2.8a/source/rpc_client/cli_spoolss_notify.c samba-2.2.8a+IPv6-20030712/source/rpc_client/cli_spoolss_notify.c
2374 --- samba-2.2.8a/source/rpc_client/cli_spoolss_notify.c 2003-03-14 16:34:48.000000000 -0500
2375 +++ samba-2.2.8a+IPv6-20030712/source/rpc_client/cli_spoolss_notify.c 2003-07-12 22:28:30.000000000 -0400
2380 - if(!resolve_name( remote_machine, &cli->dest_ip, 0x20)) {
2381 - DEBUG(0,("connect_to_client: Can't resolve address for %s\n", remote_machine));
2382 - cli_shutdown(cli);
2386 - if (ismyip(cli->dest_ip)) {
2387 - DEBUG(0,("connect_to_client: Machine %s is one of our addresses. Cannot add to ourselves.\n", remote_machine));
2388 - cli_shutdown(cli);
2392 - if (!cli_connect(cli, remote_machine, &cli->dest_ip)) {
2393 + if (!cli_connect(cli, remote_machine, NULL)) {
2394 DEBUG(0,("connect_to_client: unable to connect to SMB server on machine %s. Error was : %s.\n", remote_machine, cli_errstr(cli) ));
2399 - if (!attempt_netbios_session_request(cli, global_myname, remote_machine, &cli->dest_ip)) {
2400 + if (!attempt_netbios_session_request(cli, global_myname,
2401 + remote_machine)) {
2402 DEBUG(0,("connect_to_client: machine %s rejected the NetBIOS session request.\n",
2405 diff -ur samba-2.2.8a/source/rpc_client/cli_trust.c samba-2.2.8a+IPv6-20030712/source/rpc_client/cli_trust.c
2406 --- samba-2.2.8a/source/rpc_client/cli_trust.c 2003-03-14 16:34:48.000000000 -0500
2407 +++ samba-2.2.8a+IPv6-20030712/source/rpc_client/cli_trust.c 2003-07-12 22:28:30.000000000 -0400
2412 - if(!resolve_name( remote_machine, &cli.dest_ip, 0x20)) {
2413 - DEBUG(0,("modify_trust_password: Can't resolve address for %s\n", remote_machine));
2414 - cli_shutdown(&cli);
2418 - if (ismyip(cli.dest_ip)) {
2419 - DEBUG(0,("modify_trust_password: Machine %s is one of our addresses. Cannot add \
2420 -to ourselves.\n", remote_machine));
2421 - cli_shutdown(&cli);
2425 - if (!cli_connect(&cli, remote_machine, &cli.dest_ip)) {
2426 + if (!cli_connect(&cli, remote_machine, NULL)) {
2427 DEBUG(0,("modify_trust_password: unable to connect to SMB server on \
2428 machine %s. Error was : %s.\n", remote_machine, cli_errstr(&cli) ));
2433 - if (!attempt_netbios_session_request(&cli, global_myname, remote_machine, &cli.dest_ip)) {
2434 + if (!attempt_netbios_session_request(&cli, global_myname, remote_machine)) {
2435 DEBUG(0,("modify_trust_password: machine %s rejected the NetBIOS session request.\n",
2438 diff -ur samba-2.2.8a/source/smbd/password.c samba-2.2.8a+IPv6-20030712/source/smbd/password.c
2439 --- samba-2.2.8a/source/smbd/password.c 2003-04-06 21:54:00.000000000 -0400
2440 +++ samba-2.2.8a+IPv6-20030712/source/smbd/password.c 2003-07-12 22:28:30.000000000 -0400
2441 @@ -1015,7 +1015,7 @@
2443 struct cli_state *cli;
2445 - struct in_addr dest_ip;
2446 + struct sockaddr_list *dest_addrs;
2449 BOOL connected_ok = False;
2450 @@ -1032,21 +1032,23 @@
2451 standard_sub_basic(desthost,sizeof(desthost));
2454 - if(!resolve_name( desthost, &dest_ip, 0x20)) {
2455 + if(!(dest_addrs = resolve_name_smb(desthost, 0))) {
2456 DEBUG(1,("server_cryptkey: Can't resolve address for %s\n",desthost));
2461 if (ismyip(dest_ip)) {
2462 DEBUG(1,("Password server loop - disabling password server %s\n",desthost));
2467 - if (cli_connect(cli, desthost, &dest_ip)) {
2468 + if (cli_connect(cli, desthost, dest_addrs)) {
2469 DEBUG(3,("connected to password server %s\n",desthost));
2470 connected_ok = True;
2473 + } else free_sockaddr_list(dest_addrs);
2477 @@ -1057,7 +1059,7 @@
2481 - if (!attempt_netbios_session_request(cli, global_myname, desthost, &dest_ip)) {
2482 + if (!attempt_netbios_session_request(cli, global_myname, desthost)) {
2486 @@ -1223,7 +1225,7 @@
2487 static BOOL connect_to_domain_password_server(struct cli_state **ppcli,
2488 char *server, unsigned char *trust_passwd)
2490 - struct in_addr dest_ip;
2491 + struct sockaddr_list *dest_addrs;
2492 fstring remote_machine;
2493 struct cli_state *pcli = NULL;
2495 @@ -1234,7 +1236,7 @@
2499 - if (is_ipaddress(server)) {
2500 + if (is_ipv4address(server)) {
2501 struct in_addr to_ip;
2503 /* we shouldn't have 255.255.255.255 forthe IP address of a password server anyways */
2504 @@ -1256,18 +1258,20 @@
2505 standard_sub_basic(remote_machine,sizeof(remote_machine));
2506 strupper(remote_machine);
2508 - if(!resolve_name( remote_machine, &dest_ip, 0x20)) {
2509 + if(!(dest_addrs = resolve_name_smb(remote_machine, 0))) {
2510 DEBUG(1,("connect_to_domain_password_server: Can't resolve address for %s\n", remote_machine));
2516 if (ismyip(dest_ip)) {
2517 DEBUG(1,("connect_to_domain_password_server: Password server loop - not using password server %s\n",
2524 /* we use a mutex to prevent two connections at once - when a NT PDC gets
2525 two connections where one hasn't completed a negprot yet it will send a
2526 @@ -1278,15 +1282,16 @@
2530 - if (!cli_connect(pcli, remote_machine, &dest_ip)) {
2531 + if (!cli_connect(pcli, remote_machine, dest_addrs)) {
2532 DEBUG(0,("connect_to_domain_password_server: unable to connect to SMB server on \
2533 machine %s. Error was : %s.\n", remote_machine, cli_errstr(pcli) ));
2534 + free_sockaddr_list(dest_addrs);
2536 release_server_mutex();
2540 - if (!attempt_netbios_session_request(pcli, global_myname, remote_machine, &dest_ip)) {
2541 + if (!attempt_netbios_session_request(pcli, global_myname, remote_machine)) {
2542 DEBUG(0,("connect_to_password_server: machine %s rejected the NetBIOS \
2543 session request. Error was : %s.\n", remote_machine, cli_errstr(pcli) ));
2545 diff -ur samba-2.2.8a/source/smbwrapper/smbw.c samba-2.2.8a+IPv6-20030712/source/smbwrapper/smbw.c
2546 --- samba-2.2.8a/source/smbwrapper/smbw.c 2002-04-30 09:28:32.000000000 -0400
2547 +++ samba-2.2.8a+IPv6-20030712/source/smbwrapper/smbw.c 2003-07-12 22:28:30.000000000 -0400
2552 - struct in_addr *ip_list = NULL;
2555 + struct sockaddr_list *wglist, *wg;
2557 /* first off see if an existing workgroup name exists */
2558 p = smbw_getshared("WORKGROUP");
2559 @@ -273,24 +271,29 @@
2560 if (smbw_server(server, "IPC$")) return p;
2562 /* go looking for workgroups */
2563 - if (!name_resolve_bcast(MSBROWSE, 1, &ip_list, &count)) {
2564 + if (!(wglist = name_resolve_bcast(MSBROWSE, 1))) {
2565 DEBUG(1,("No workgroups found!"));
2569 - for (i=0;i<count;i++) {
2570 + for(wg = wglist; wg; wg = wg->next)
2572 static fstring name;
2573 - if (name_status_find("*", 0, 0x1d, ip_list[i], name)) {
2575 + if(wg->addr->sa_family != AF_INET) continue;
2576 + if (name_status_find("*", 0, 0x1d, ((struct sockaddr_in *)
2577 + (wg->addr))->sin_addr, name))
2579 slprintf(server, sizeof(server), "%s#1D", name);
2580 if (smbw_server(server, "IPC$")) {
2581 smbw_setshared("WORKGROUP", name);
2582 - SAFE_FREE(ip_list);
2583 + free_sockaddr_list(wglist);
2589 - SAFE_FREE(ip_list);
2590 + free_sockaddr_list(wglist);
2595 char *p, *server_n = server;
2598 - struct in_addr ip;
2599 + struct sockaddr_list *salist;
2604 get_auth_data_fn(server, share, &workgroup, &username, &password);
2605 @@ -501,13 +503,15 @@
2607 slprintf(ipenv,sizeof(ipenv)-1,"HOST_%s", server_n);
2610 + salist = resolve_name_smb((p=smbw_getshared(ipenv)) ? p : server_n, 0);
2612 if ((p=smbw_getshared(ipenv))) {
2613 ip = *(interpret_addr2(p));
2616 /* have to open a new connection */
2617 - if (!cli_initialise(&c) || !cli_connect(&c, server_n, &ip)) {
2618 + if (!cli_initialise(&c) || !cli_connect(&c, server_n, salist)) {
2619 + free_sockaddr_list(salist);
2627 - smbw_setshared(ipenv,inet_ntoa(ip));
2628 + smbw_setshared(ipenv,print_sockaddr(c.connected_addr->addr));
2630 DEBUG(4,(" tconx ok\n"));
2632 diff -ur samba-2.2.8a/source/utils/locktest2.c samba-2.2.8a+IPv6-20030712/source/utils/locktest2.c
2633 --- samba-2.2.8a/source/utils/locktest2.c 2002-04-30 09:28:37.000000000 -0400
2634 +++ samba-2.2.8a+IPv6-20030712/source/utils/locktest2.c 2003-07-12 22:28:30.000000000 -0400
2636 struct nmb_name called, calling;
2639 - struct in_addr ip;
2643 @@ -168,19 +167,14 @@
2649 slprintf(myname,sizeof(myname), "lock-%u-%u", getpid(), count++);
2651 make_nmb_name(&calling, myname, 0x0);
2652 make_nmb_name(&called , server, 0x20);
2657 /* have to open a new connection */
2658 - if (!(c=cli_initialise(NULL)) || (cli_set_port(c, 139) == 0) ||
2659 - !cli_connect(c, server_n, &ip)) {
2660 + if (!(c=cli_initialise(NULL)) || !cli_connect(c, server_n, NULL)) {
2661 DEBUG(0,("Connection to %s failed\n", server_n));
2664 diff -ur samba-2.2.8a/source/utils/locktest.c samba-2.2.8a+IPv6-20030712/source/utils/locktest.c
2665 --- samba-2.2.8a/source/utils/locktest.c 2002-04-30 09:28:37.000000000 -0400
2666 +++ samba-2.2.8a+IPv6-20030712/source/utils/locktest.c 2003-07-12 22:28:30.000000000 -0400
2668 struct nmb_name called, calling;
2671 - struct in_addr ip;
2675 @@ -126,19 +125,14 @@
2681 slprintf(myname,sizeof(myname), "lock-%u-%u", getpid(), count++);
2683 make_nmb_name(&calling, myname, 0x0);
2684 make_nmb_name(&called , server, 0x20);
2689 /* have to open a new connection */
2690 - if (!(c=cli_initialise(NULL)) || (cli_set_port(c, 139) == 0) ||
2691 - !cli_connect(c, server_n, &ip)) {
2692 + if (!(c=cli_initialise(NULL)) || !cli_connect(c, server_n, NULL)) {
2693 DEBUG(0,("Connection to %s failed\n", server_n));
2696 diff -ur samba-2.2.8a/source/utils/masktest.c samba-2.2.8a+IPv6-20030712/source/utils/masktest.c
2697 --- samba-2.2.8a/source/utils/masktest.c 2002-04-30 09:28:37.000000000 -0400
2698 +++ samba-2.2.8a+IPv6-20030712/source/utils/masktest.c 2003-07-12 22:28:30.000000000 -0400
2700 struct nmb_name called, calling;
2703 - struct in_addr ip;
2706 share = strchr(server,'\\');
2707 @@ -175,17 +174,12 @@
2713 make_nmb_name(&calling, "masktest", 0x0);
2714 make_nmb_name(&called , server, 0x20);
2719 /* have to open a new connection */
2720 - if (!(c=cli_initialise(NULL)) || (cli_set_port(c, 139) == 0) ||
2721 - !cli_connect(c, server_n, &ip)) {
2722 + if (!(c=cli_initialise(NULL)) || !cli_connect(c, server_n, NULL)) {
2723 DEBUG(0,("Connection to %s failed\n", server_n));
2726 diff -ur samba-2.2.8a/source/utils/smbcacls.c samba-2.2.8a+IPv6-20030712/source/utils/smbcacls.c
2727 --- samba-2.2.8a/source/utils/smbcacls.c 2003-03-14 16:34:49.000000000 -0500
2728 +++ samba-2.2.8a+IPv6-20030712/source/utils/smbcacls.c 2003-07-12 22:28:30.000000000 -0400
2731 struct cli_state *c;
2732 struct nmb_name called, calling;
2733 - struct in_addr ip;
2734 extern pstring global_myname;
2736 fstrcpy(server,share+2);
2737 @@ -723,18 +722,13 @@
2743 make_nmb_name(&calling, global_myname, 0x0);
2744 make_nmb_name(&called , server, 0x20);
2749 /* have to open a new connection */
2750 - if (!(c=cli_initialise(NULL)) || !cli_connect(c, server, &ip)) {
2751 + if (!(c=cli_initialise(NULL)) || !cli_connect(c, server, NULL)) {
2752 DEBUG(0,("Connection to %s failed\n", server));
2757 diff -ur samba-2.2.8a/source/utils/smbfilter.c samba-2.2.8a+IPv6-20030712/source/utils/smbfilter.c
2758 --- samba-2.2.8a/source/utils/smbfilter.c 2002-02-01 17:15:14.000000000 -0500
2759 +++ samba-2.2.8a+IPv6-20030712/source/utils/smbfilter.c 2003-07-12 22:28:30.000000000 -0400
2764 -static void filter_child(int c, struct in_addr dest_ip)
2765 +static void filter_child(int c, struct sockaddr_list *dest_addrs)
2769 /* we have a connection from a new client, now connect to the server */
2770 - s = open_socket_out(SOCK_STREAM, &dest_ip, 139, LONG_CONNECT_TIMEOUT);
2771 + s = open_socket_out(dest_addrs, NULL, LONG_CONNECT_TIMEOUT);
2772 + free_sockaddr_list(dest_addrs);
2775 - DEBUG(0,("Unable to connect to %s\n", inet_ntoa(dest_ip)));
2776 + DEBUG(0,("Unable to connect to %s\n",
2777 + print_sockaddr(dest_addrs->addr)));
2782 static void start_filter(char *desthost)
2785 - struct in_addr dest_ip;
2786 + struct sockaddr_list *dest_addrs;
2791 DEBUG(0,("listen failed\n"));
2794 - if (!resolve_name(desthost, &dest_ip, 0x20)) {
2795 + if (!(dest_addrs = resolve_name_smb(desthost, 0))) {
2796 DEBUG(0,("Unable to resolve host %s\n", desthost));
2803 - filter_child(c, dest_ip);
2804 + filter_child(c, dest_addrs);
2808 diff -ur samba-2.2.8a/source/utils/smbpasswd.c samba-2.2.8a+IPv6-20030712/source/utils/smbpasswd.c
2809 --- samba-2.2.8a/source/utils/smbpasswd.c 2003-03-14 16:34:49.000000000 -0500
2810 +++ samba-2.2.8a+IPv6-20030712/source/utils/smbpasswd.c 2003-07-12 22:28:30.000000000 -0400
2812 struct ntuser_creds creds;
2813 struct cli_state cli;
2815 - struct in_addr dest_ip;
2816 + struct sockaddr_list *dest_addrs = NULL;
2817 TALLOC_CTX *mem_ctx;
2824 - ZERO_STRUCT(dest_ip); /* Make sure no nasty surprises */
2826 if (!(mem_ctx = talloc_init())) {
2827 DEBUG(0, ("Could not initialise talloc context\n"));
2828 @@ -414,19 +413,20 @@
2829 fprintf(stderr, "Unable to lookup the name for the domain controller for domain %s.\n", domain);
2832 - dest_ip = ip_list[0];
2833 + dest_addrs = make_singlet_list( &ip_list[0], 0 );
2836 make_nmb_name(&called, pdc_name, 0x20);
2837 make_nmb_name(&calling, dns_to_netbios_name(global_myname), 0);
2839 - if (!cli_establish_connection(&cli, pdc_name, &dest_ip, &calling,
2840 + if (!cli_establish_connection(&cli, pdc_name, dest_addrs, &calling,
2841 &called, "IPC$", "IPC", False, True)) {
2842 if (!NT_STATUS_IS_OK(cli_nt_error(&cli))) {
2843 DEBUG(0, ("Error connecting to %s - %s\n", pdc_name,cli_errstr(&cli)));
2845 DEBUG(0, ("Error connecting to %s\n", pdc_name));
2847 + if( dest_addrs ) free_sockaddr_list( dest_addrs );
2852 if (cli.nt_pipe_fnum)
2853 cli_nt_session_close(&cli);
2855 + if (cli.dest_addrs)
2856 + free_sockaddr_list(cli.dest_addrs);
2858 /* Display success or failure */
2861 diff -ur samba-2.2.8a/source/utils/torture.c samba-2.2.8a+IPv6-20030712/source/utils/torture.c
2862 --- samba-2.2.8a/source/utils/torture.c 2002-04-30 09:28:39.000000000 -0400
2863 +++ samba-2.2.8a+IPv6-20030712/source/utils/torture.c 2003-07-12 22:28:30.000000000 -0400
2864 @@ -134,16 +134,13 @@
2865 static BOOL open_nbt_connection(struct cli_state *c)
2867 struct nmb_name called, calling;
2868 - struct in_addr ip;
2872 make_nmb_name(&calling, myname, 0x0);
2873 make_nmb_name(&called , host, 0x20);
2877 - if (!cli_initialise(c) || !cli_connect(c, host, &ip)) {
2878 + if (!cli_initialise(c) || !cli_connect(c, host, NULL)) {
2879 printf("Failed to connect with %s\n", host);
2882 diff -ur samba-2.2.8a/source/web/diagnose.c samba-2.2.8a+IPv6-20030712/source/web/diagnose.c
2883 --- samba-2.2.8a/source/web/diagnose.c 2003-02-28 13:47:26.000000000 -0500
2884 +++ samba-2.2.8a+IPv6-20030712/source/web/diagnose.c 2003-07-12 22:28:30.000000000 -0400
2886 BOOL smbd_running(void)
2888 static struct cli_state cli;
2889 + struct sockaddr_list *localaddrs;
2890 extern struct in_addr loopback_ip;
2892 if (!cli_initialise(&cli))
2895 - if (!cli_connect(&cli, "localhost", &loopback_ip)) {
2896 + localaddrs = make_singlet_list(&loopback_ip, 0);
2897 + if (!cli_connect(&cli, "localhost", localaddrs))
2899 + free_sockaddr_list(localaddrs);