BOOL cli_connect(struct cli_state *cli, const char *host, struct in_addr *ip) { extern pstring user_socket_options; int name_type = 0x20; char *p; /* reasonable default hostname */ if (!host) host = "*SMBSERVER"; fstrcpy(cli->desthost, host); /* allow hostnames of the form NAME#xx and do a netbios lookup */ if ((p = strchr(cli->desthost, '#'))) { name_type = strtol(p+1, NULL, 16); *p = 0; } if (!ip || is_zero_ip(*ip)) { if (!resolve_name(cli->desthost, &cli->dest_ip, name_type)) { return False; } if (ip) *ip = cli->dest_ip; } else { cli->dest_ip = *ip; } if (getenv("LIBSMB_PROG")) { cli->fd = sock_exec(getenv("LIBSMB_PROG")); } else { /* try 445 first, then 139 */ int port = cli->port?cli->port:445; cli->fd = open_socket_out(SOCK_STREAM, &cli->dest_ip, port, cli->timeout); if (cli->fd == -1 && cli->port == 0) { port = 139; cli->fd = open_socket_out(SOCK_STREAM, &cli->dest_ip, port, cli->timeout); } if (cli->fd != -1) cli->port = port; } if (cli->fd == -1) { DEBUG(1,("Error connecting to %s (%s)\n", inet_ntoa(*ip),strerror(errno))); return False; } set_socket_options(cli->fd,user_socket_options); return True; }
/**************************************************************************** open the client sockets ****************************************************************************/ BOOL cli_connect(struct cli_state *cli, const char *host, struct in_addr *ip) { extern pstring user_socket_options; int fd; fstrcpy(cli->desthost, host); if (!ip || ip->s_addr == 0) { if (!resolve_name(cli->desthost, &cli->dest_ip, 0x20)) { return False; } if (ip) *ip = cli->dest_ip; } else { cli->dest_ip = *ip; } if (cli->port == 0) cli->port = 139; /* Set to default */ fd = open_socket_out(SOCK_STREAM, &cli->dest_ip, cli->port, 20000); if (fd == -1 || !smb_set_fd(cli->hnd, fd)) return False; set_socket_options(fd, user_socket_options); return True; }
int main(int argc, char *argv[]) { int listen_port, dest_port; char *host; int sock_in; int sock_out; int listen_fd; struct sockaddr addr; int in_addrlen = sizeof(addr); if (argc < 4) { printf("Usage: sockspy <inport> <host> <port>\n"); exit(1); } listen_port = atoi(argv[1]); host = argv[2]; dest_port = atoi(argv[3]); listen_fd = open_socket_in(listen_port); if (listen_fd == -1) { fprintf(stderr,"listen on port %d failed - %s\n", listen_port, strerror(errno)); exit(1); } if (listen(listen_fd, 100) == -1) { fprintf(stderr,"listen failed\n"); exit(1); } while (1) { sock_in = accept(listen_fd,&addr,&in_addrlen); if (sock_in == -1) { fprintf(stderr,"accept on port %d failed - %s\n", listen_port, strerror(errno)); exit(1); } if (fork() == 0) { close(listen_fd); sock_out = open_socket_out(host, dest_port); if (sock_out == -1) { exit(1); } main_loop(sock_in, sock_out); _exit(0); } close(sock_in); } return 0; }
/** * Open an outgoing socket, but allow for it to be intercepted by * $RSYNC_CONNECT_PROG, which will execute a program across a TCP * socketpair rather than really opening a socket. * * We use this primarily in testing to detect TCP flow bugs, but not * cause security problems by really opening remote connections. * * This is based on the Samba LIBSMB_PROG feature. * * @param bind_address Local address to use. Normally NULL to get the stack default. **/ int open_socket_out_wrapped (char *host, int port, const char *bind_address, int af_hint) { char *prog; if ((prog = getenv ("RSYNC_CONNECT_PROG")) != NULL) return sock_exec (prog); else return open_socket_out (host, port, bind_address, af_hint); }
static void filter_child(int c, struct in_addr dest_ip) { int s; /* we have a connection from a new client, now connect to the server */ s = open_socket_out(SOCK_STREAM, &dest_ip, 445, LONG_CONNECT_TIMEOUT); if (s == -1) { d_printf("Unable to connect to %s\n", inet_ntoa(dest_ip)); exit(1); } while (c != -1 || s != -1) { fd_set fds; int num; FD_ZERO(&fds); if (s != -1) FD_SET(s, &fds); if (c != -1) FD_SET(c, &fds); num = sys_select_intr(MAX(s+1, c+1),&fds,NULL,NULL,NULL); if (num <= 0) continue; if (c != -1 && FD_ISSET(c, &fds)) { if (!receive_smb(c, packet, BUFFER_SIZE, 0)) { d_printf("client closed connection\n"); exit(0); } filter_request(packet); if (!send_smb(s, packet)) { d_printf("server is dead\n"); exit(1); } } if (s != -1 && FD_ISSET(s, &fds)) { if (!receive_smb(s, packet, BUFFER_SIZE, 0)) { d_printf("server closed connection\n"); exit(0); } filter_reply(packet); if (!send_smb(c, packet)) { d_printf("client is dead\n"); exit(1); } } } d_printf("Connection closed\n"); exit(0); }
void add_dev_map(char *mapping) { char *p; if (mapping[0] == ':') { vserver = open_socket_out(mapping+1, VSERVER_PORT); if (vserver == -1) { fprintf(stderr,"Failed to connect to %s\n", mapping+1); exit(1); } return; } dev_list = strdup(mapping); mfs_dev = strdup(dev_list); if ((p = strchr(mfs_dev, ' '))) *p = 0; }
static NTSTATUS get_ldapi_ctx(TALLOC_CTX *mem_ctx, struct tldap_context **pld) { struct tldap_context *ld; struct sockaddr_un addr; char *sockaddr; int fd; NTSTATUS status; int res; sockaddr = talloc_asprintf(talloc_tos(), "/%s/ldap_priv/ldapi", lp_private_dir()); if (sockaddr == NULL) { DEBUG(10, ("talloc failed\n")); return NT_STATUS_NO_MEMORY; } ZERO_STRUCT(addr); addr.sun_family = AF_UNIX; strncpy(addr.sun_path, sockaddr, sizeof(addr.sun_path)); TALLOC_FREE(sockaddr); status = open_socket_out((struct sockaddr_storage *)(void *)&addr, 0, 0, &fd); if (!NT_STATUS_IS_OK(status)) { DEBUG(10, ("Could not connect to %s: %s\n", addr.sun_path, nt_errstr(status))); return status; } set_blocking(fd, false); ld = tldap_context_create(mem_ctx, fd); if (ld == NULL) { close(fd); return NT_STATUS_NO_MEMORY; } res = tldap_fetch_rootdse(ld); if (res != TLDAP_SUCCESS) { DEBUG(10, ("tldap_fetch_rootdse failed: %s\n", tldap_errstr(talloc_tos(), ld, res))); TALLOC_FREE(ld); return NT_STATUS_LDAP(res); } *pld = ld; return NT_STATUS_OK;; }
int main(int argc, char *argv[]) { int sock; unsigned t, ofs; char *host; if (argc != 3) { printf("rtime <server> <offset>\n"); exit(1); } host = argv[1]; ofs = atoi(argv[2]); sock = open_socket_out(argv[1], 37); if (read(sock, &t, sizeof(t)) == 4) { tivo_time(ofs + ntohl(t) - 2208988800U); return 0; } return -1; }
static void filter_child(int c, struct sockaddr_storage *dest_ss) { NTSTATUS status; int s = -1; char packet[128*1024]; /* we have a connection from a new client, now connect to the server */ status = open_socket_out(dest_ss, TCP_SMB_PORT, LONG_CONNECT_TIMEOUT, &s); if (!NT_STATUS_IS_OK(status)) { char addr[INET6_ADDRSTRLEN]; if (dest_ss) { print_sockaddr(addr, sizeof(addr), dest_ss); } d_printf("Unable to connect to %s (%s)\n", dest_ss?addr:"NULL", nt_errstr(status)); exit(1); } while (c != -1 || s != -1) { struct pollfd fds[2]; int num_fds, ret; memset(fds, 0, sizeof(struct pollfd) * 2); fds[0].fd = -1; fds[1].fd = -1; num_fds = 0; if (s != -1) { fds[num_fds].fd = s; fds[num_fds].events = POLLIN|POLLHUP; num_fds += 1; } if (c != -1) { fds[num_fds].fd = c; fds[num_fds].events = POLLIN|POLLHUP; num_fds += 1; } ret = sys_poll_intr(fds, num_fds, -1); if (ret <= 0) { continue; } /* * find c in fds and see if it's readable */ if ((c != -1) && (((fds[0].fd == c) && (fds[0].revents & (POLLIN|POLLHUP|POLLERR))) || ((fds[1].fd == c) && (fds[1].revents & (POLLIN|POLLHUP|POLLERR))))) { size_t len; if (!NT_STATUS_IS_OK(receive_smb_raw( c, packet, sizeof(packet), 0, 0, &len))) { d_printf("client closed connection\n"); exit(0); } filter_request(packet, len); if (!send_smb(s, packet)) { d_printf("server is dead\n"); exit(1); } } /* * find s in fds and see if it's readable */ if ((s != -1) && (((fds[0].fd == s) && (fds[0].revents & (POLLIN|POLLHUP|POLLERR))) || ((fds[1].fd == s) && (fds[1].revents & (POLLIN|POLLHUP|POLLERR))))) { size_t len; if (!NT_STATUS_IS_OK(receive_smb_raw( s, packet, sizeof(packet), 0, 0, &len))) { d_printf("server closed connection\n"); exit(0); } filter_reply(packet); if (!send_smb(c, packet)) { d_printf("client is dead\n"); exit(1); } } } d_printf("Connection closed\n"); exit(0); }
/* Connect to an internet socket */ static int smb_traffic_analyzer_connect_inet_socket(vfs_handle_struct *handle, const char *name, uint16_t port) { /* Create a streaming Socket */ int sockfd = -1; struct addrinfo hints; struct addrinfo *ailist = NULL; struct addrinfo *res = NULL; int ret; ZERO_STRUCT(hints); /* By default make sure it supports TCP. */ hints.ai_socktype = SOCK_STREAM; hints.ai_flags = AI_ADDRCONFIG; ret = getaddrinfo(name, NULL, &hints, &ailist); if (ret) { DEBUG(3,("smb_traffic_analyzer_connect_inet_socket: " "getaddrinfo failed for name %s [%s]\n", name, gai_strerror(ret) )); return -1; } DEBUG(3,("smb_traffic_analyzer: Internet socket mode. Hostname: %s," "Port: %i\n", name, port)); for (res = ailist; res; res = res->ai_next) { struct sockaddr_storage ss; NTSTATUS status; if (!res->ai_addr || res->ai_addrlen == 0) { continue; } ZERO_STRUCT(ss); memcpy(&ss, res->ai_addr, res->ai_addrlen); status = open_socket_out(&ss, port, 10000, &sockfd); if (NT_STATUS_IS_OK(status)) { break; } } if (ailist) { freeaddrinfo(ailist); } if (sockfd == -1) { DEBUG(1, ("smb_traffic_analyzer: unable to create " "socket, error is %s", strerror(errno))); return -1; } return sockfd; }
static ADS_STATUS do_krb5_kpasswd_request(krb5_context context, const char *kdc_host, uint16 pversion, krb5_creds *credsp, const char *princ, const char *newpw) { krb5_auth_context auth_context = NULL; krb5_data ap_req, chpw_req, chpw_rep; int ret, sock; socklen_t addr_len; struct sockaddr_storage remote_addr, local_addr; struct sockaddr_storage addr; krb5_address local_kaddr, remote_kaddr; bool use_tcp = False; if (!interpret_string_addr(&addr, kdc_host, 0)) { } ret = krb5_mk_req_extended(context, &auth_context, AP_OPTS_USE_SUBKEY, NULL, credsp, &ap_req); if (ret) { DEBUG(1,("krb5_mk_req_extended failed (%s)\n", error_message(ret))); return ADS_ERROR_KRB5(ret); } do { if (!use_tcp) { sock = open_udp_socket(kdc_host, DEFAULT_KPASSWD_PORT); if (sock == -1) { int rc = errno; SAFE_FREE(ap_req.data); krb5_auth_con_free(context, auth_context); DEBUG(1,("failed to open kpasswd socket to %s " "(%s)\n", kdc_host, strerror(errno))); return ADS_ERROR_SYSTEM(rc); } } else { NTSTATUS status; status = open_socket_out(&addr, DEFAULT_KPASSWD_PORT, LONG_CONNECT_TIMEOUT, &sock); if (!NT_STATUS_IS_OK(status)) { SAFE_FREE(ap_req.data); krb5_auth_con_free(context, auth_context); DEBUG(1,("failed to open kpasswd socket to %s " "(%s)\n", kdc_host, nt_errstr(status))); return ADS_ERROR_NT(status); } } addr_len = sizeof(remote_addr); if (getpeername(sock, (struct sockaddr *)&remote_addr, &addr_len) != 0) { close(sock); SAFE_FREE(ap_req.data); krb5_auth_con_free(context, auth_context); DEBUG(1,("getpeername() failed (%s)\n", error_message(errno))); return ADS_ERROR_SYSTEM(errno); } addr_len = sizeof(local_addr); if (getsockname(sock, (struct sockaddr *)&local_addr, &addr_len) != 0) { close(sock); SAFE_FREE(ap_req.data); krb5_auth_con_free(context, auth_context); DEBUG(1,("getsockname() failed (%s)\n", error_message(errno))); return ADS_ERROR_SYSTEM(errno); } if (!setup_kaddr(&remote_kaddr, &remote_addr) || !setup_kaddr(&local_kaddr, &local_addr)) { DEBUG(1,("do_krb5_kpasswd_request: " "Failed to setup addresses.\n")); close(sock); SAFE_FREE(ap_req.data); krb5_auth_con_free(context, auth_context); errno = EINVAL; return ADS_ERROR_SYSTEM(EINVAL); } ret = krb5_auth_con_setaddrs(context, auth_context, &local_kaddr, NULL); if (ret) { close(sock); SAFE_FREE(ap_req.data); krb5_auth_con_free(context, auth_context); DEBUG(1,("krb5_auth_con_setaddrs failed (%s)\n", error_message(ret))); return ADS_ERROR_KRB5(ret); } ret = build_kpasswd_request(pversion, context, auth_context, &ap_req, princ, newpw, use_tcp, &chpw_req); if (ret) { close(sock); SAFE_FREE(ap_req.data); krb5_auth_con_free(context, auth_context); DEBUG(1,("build_setpw_request failed (%s)\n", error_message(ret))); return ADS_ERROR_KRB5(ret); } ret = write(sock, chpw_req.data, chpw_req.length); if (ret != chpw_req.length) { close(sock); SAFE_FREE(chpw_req.data); SAFE_FREE(ap_req.data); krb5_auth_con_free(context, auth_context); DEBUG(1,("send of chpw failed (%s)\n", strerror(errno))); return ADS_ERROR_SYSTEM(errno); } SAFE_FREE(chpw_req.data); chpw_rep.length = 1500; chpw_rep.data = (char *) SMB_MALLOC(chpw_rep.length); if (!chpw_rep.data) { close(sock); SAFE_FREE(ap_req.data); krb5_auth_con_free(context, auth_context); DEBUG(1,("send of chpw failed (%s)\n", strerror(errno))); errno = ENOMEM; return ADS_ERROR_SYSTEM(errno); } ret = read(sock, chpw_rep.data, chpw_rep.length); if (ret < 0) { close(sock); SAFE_FREE(chpw_rep.data); SAFE_FREE(ap_req.data); krb5_auth_con_free(context, auth_context); DEBUG(1,("recv of chpw reply failed (%s)\n", strerror(errno))); return ADS_ERROR_SYSTEM(errno); } close(sock); chpw_rep.length = ret; ret = krb5_auth_con_setaddrs(context, auth_context, NULL,&remote_kaddr); if (ret) { SAFE_FREE(chpw_rep.data); SAFE_FREE(ap_req.data); krb5_auth_con_free(context, auth_context); DEBUG(1,("krb5_auth_con_setaddrs on reply failed (%s)\n", error_message(ret))); return ADS_ERROR_KRB5(ret); } ret = parse_setpw_reply(context, use_tcp, auth_context, &chpw_rep); SAFE_FREE(chpw_rep.data); if (ret) { if (ret == KRB5KRB_ERR_RESPONSE_TOO_BIG && !use_tcp) { DEBUG(5, ("Trying setpw with TCP!!!\n")); use_tcp = True; continue; } SAFE_FREE(ap_req.data); krb5_auth_con_free(context, auth_context); DEBUG(1,("parse_setpw_reply failed (%s)\n", error_message(ret))); return ADS_ERROR_KRB5(ret); } SAFE_FREE(ap_req.data); krb5_auth_con_free(context, auth_context); } while ( ret ); return ADS_SUCCESS; }
/**************************************************************************** send a session request. see rfc1002.txt 4.3 and 4.3.2 ****************************************************************************/ BOOL cli_session_request(struct cli_state *cli, const struct nmb_name *calling, const struct nmb_name *called) { char *p; int len = 4; extern pstring user_socket_options; io_struct ps; uchar nb_type; ZERO_STRUCT(ps); io_init(&ps, 4096, MARSHALL); /* send a session request (RFC 1002) */ smb_set_nbnames(cli->hnd, calling, called); /* put in the destination name */ p = ps.data_p; name_mangle(called->name, p, called->name_type); len += name_len(p); /* and my name */ p = ps.data_p + len-4; name_mangle(calling->name, p, calling->name_type); len += name_len(p); ps.data_offset = len; smb_send_smb(cli->hnd, &ps, 0x81); io_free(&ps); DEBUG(5, ("Sent session request: %s to %s\n", nmb_namestr(calling), nmb_namestr(called))); if (!smb_receive_smb(cli->hnd, &ps, &nb_type)) return False; if (nb_type == 0x84) { int fd; /* C. Hoch 9/14/95 Start */ /* For information, here is the response structure. * We do the byte-twiddling to for portability. struct RetargetResponse{ unsigned char type; unsigned char flags; int16 length; int32 ip_addr; int16 port; }; */ int port = (CVAL(ps.data_p, 4) << 8) + CVAL(ps.data_p, 5); /* SESSION RETARGET */ putip((char *)&cli->dest_ip, ps.data_p); fd = open_socket_out(SOCK_STREAM, &cli->dest_ip, port, LONG_CONNECT_TIMEOUT); if (fd == -1 || !smb_set_fd(cli->hnd, fd)) return False; cli->dbg(3, "Retargeted\n"); set_socket_options(fd, user_socket_options); /* Try again */ { static int depth; BOOL ret; if (depth > 4) { cli->dbg( 0, "Retarget recursion - failing\n"); return False; } depth++; ret = cli_session_request(cli, calling, called); depth--; return ret; } } /* C. Hoch 9/14/95 End */ if (nb_type != 0x82) { /* This is the wrong place to put the error... JRA. */ cli->rap_error = CVAL(ps.data_p, 0); return False; } return (True); }
BOOL cli_session_request(struct cli_state *cli, struct nmb_name *calling, struct nmb_name *called) { char *p; int len = 4; extern pstring user_socket_options; /* 445 doesn't have session request */ if (cli->port == 445) return True; /* send a session request (RFC 1002) */ memcpy(&(cli->calling), calling, sizeof(*calling)); memcpy(&(cli->called ), called , sizeof(*called )); /* put in the destination name */ p = cli->outbuf+len; name_mangle(cli->called .name, p, cli->called .name_type); len += name_len(p); /* and my name */ p = cli->outbuf+len; name_mangle(cli->calling.name, p, cli->calling.name_type); len += name_len(p); /* setup the packet length * Remove four bytes from the length count, since the length * field in the NBT Session Service header counts the number * of bytes which follow. The cli_send_smb() function knows * about this and accounts for those four bytes. * CRH. */ len -= 4; _smb_setlen(cli->outbuf,len); SCVAL(cli->outbuf,0,0x81); #ifdef WITH_SSL retry: #endif /* WITH_SSL */ cli_send_smb(cli); DEBUG(5,("Sent session request\n")); if (!cli_receive_smb(cli)) return False; if (CVAL(cli->inbuf,0) == 0x84) { /* C. Hoch 9/14/95 Start */ /* For information, here is the response structure. * We do the byte-twiddling to for portability. struct RetargetResponse{ unsigned char type; unsigned char flags; int16 length; int32 ip_addr; int16 port; }; */ int port = (CVAL(cli->inbuf,8)<<8)+CVAL(cli->inbuf,9); /* SESSION RETARGET */ putip((char *)&cli->dest_ip,cli->inbuf+4); cli->fd = open_socket_out(SOCK_STREAM, &cli->dest_ip, port, LONG_CONNECT_TIMEOUT); if (cli->fd == -1) return False; DEBUG(3,("Retargeted\n")); set_socket_options(cli->fd,user_socket_options); /* Try again */ { static int depth; BOOL ret; if (depth > 4) { DEBUG(0,("Retarget recursion - failing\n")); return False; } depth++; ret = cli_session_request(cli, calling, called); depth--; return ret; } } /* C. Hoch 9/14/95 End */ #ifdef WITH_SSL if (CVAL(cli->inbuf,0) == 0x83 && CVAL(cli->inbuf,4) == 0x8e){ /* use ssl */ if (!sslutil_fd_is_ssl(cli->fd)){ if (sslutil_connect(cli->fd) == 0) goto retry; } } #endif /* WITH_SSL */ if (CVAL(cli->inbuf,0) != 0x82) { /* This is the wrong place to put the error... JRA. */ cli->rap_error = CVAL(cli->inbuf,4); return False; } return(True); }
int start_socket_client(char *host, char *path, int argc, char *argv[]) { int fd, i; char *sargs[MAX_ARGS]; int sargc=0; char line[MAXPATHLEN]; char *p, *user=NULL; extern int remote_version; extern int am_sender; if (*path == '/') { rprintf(FERROR,"ERROR: The remote path must start with a module name\n"); return -1; } p = strchr(host, '@'); if (p) { user = host; host = p+1; *p = 0; } if (!user) user = getenv("USER"); if (!user) user = getenv("LOGNAME"); fd = open_socket_out(host, rsync_port); if (fd == -1) { exit_cleanup(RERR_SOCKETIO); } server_options(sargs,&sargc); sargs[sargc++] = "."; if (path && *path) sargs[sargc++] = path; sargs[sargc] = NULL; io_printf(fd,"@RSYNCD: %d\n", PROTOCOL_VERSION); if (!read_line(fd, line, sizeof(line)-1)) { return -1; } if (sscanf(line,"@RSYNCD: %d", &remote_version) != 1) { return -1; } p = strchr(path,'/'); if (p) *p = 0; io_printf(fd,"%s\n",path); if (p) *p = '/'; while (1) { if (!read_line(fd, line, sizeof(line)-1)) { return -1; } if (strncmp(line,"@RSYNCD: AUTHREQD ",18) == 0) { auth_client(fd, user, line+18); continue; } if (strcmp(line,"@RSYNCD: OK") == 0) break; rprintf(FINFO,"%s\n", line); } for (i=0;i<sargc;i++) { io_printf(fd,"%s\n", sargs[i]); } io_printf(fd,"\n"); if (remote_version > 17 && !am_sender) io_start_multiplex_in(fd); return client_run(fd, fd, -1, argc, argv); }
int cli_get_backup_list(const char *myname, const char *send_to_name) { pstring outbuf; char *p; struct in_addr sendto_ip, my_ip; int dgram_sock; struct sockaddr_in sock_out; socklen_t name_size; if (!resolve_name(send_to_name, &sendto_ip, 0x1d)) { DEBUG(0, ("Could not resolve name: %s<1D>\n", send_to_name)); return False; } my_ip.s_addr = inet_addr("0.0.0.0"); if (!resolve_name(myname, &my_ip, 0x00)) { /* FIXME: Call others here */ DEBUG(0, ("Could not resolve name: %s<00>\n", myname)); } if ((dgram_sock = open_socket_out(SOCK_DGRAM, &sendto_ip, 138, LONG_CONNECT_TIMEOUT)) < 0) { DEBUG(4, ("open_sock_out failed ...")); return False; } /* Make it a broadcast socket ... */ set_socket_options(dgram_sock, "SO_BROADCAST"); /* Make it non-blocking??? */ if (fcntl(dgram_sock, F_SETFL, O_NONBLOCK) < 0) { DEBUG(0, ("Unable to set non blocking on dgram sock\n")); } /* Now, bind a local addr to it ... Try port 138 first ... */ memset((char *)&sock_out, '\0', sizeof(sock_out)); sock_out.sin_addr.s_addr = INADDR_ANY; sock_out.sin_port = htons(138); sock_out.sin_family = AF_INET; if (bind(dgram_sock, (struct sockaddr *)&sock_out, sizeof(sock_out)) < 0) { /* Try again on any port ... */ sock_out.sin_port = INADDR_ANY; if (bind(dgram_sock, (struct sockaddr *)&sock_out, sizeof(sock_out)) < 0) { DEBUG(4, ("failed to bind socket to address ...\n")); return False; } } /* Now, figure out what socket name we were bound to. We want the port */ name_size = sizeof(sock_out); getsockname(dgram_sock, (struct sockaddr *)&sock_out, &name_size); DEBUG(5, ("Socket bound to IP:%s, port: %d\n", inet_ntoa(sock_out.sin_addr), ntohs(sock_out.sin_port))); /* Now, build the request */ memset(cli_backup_list, '\0', sizeof(cli_backup_list)); memset(outbuf, '\0', sizeof(outbuf)); p = outbuf; SCVAL(p, 0, ANN_GetBackupListReq); p++; SCVAL(p, 0, 1); /* Count pointer ... */ p++; SIVAL(p, 0, 1); /* The sender's token ... */ p += 4; cli_send_mailslot(dgram_sock, True, "\\MAILSLOT\\BROWSE", outbuf, PTR_DIFF(p, outbuf), myname, 0, send_to_name, 0x1d, sendto_ip, my_ip, 138, sock_out.sin_port); /* We should check the error and return if we got one */ /* Now, get the response ... */ cli_get_response(dgram_sock, True, "\\MAILSLOT\\BROWSE", cli_backup_list, sizeof(cli_backup_list)); /* Should check the response here ... FIXME */ close(dgram_sock); return True; }