void send_message(const char *msg) { pstring msg_conv; int len; int grp_id; #if SAMBA_VERSION_MAJOR==2 #if SAMBA_VERSION_RELEASE < 4 /* Samba 2.2.0-2.2.3 */ pstrcpy(msg_conv, unix_to_dos(msg, FALSE)); #else /* Samba >= 2.2.4 */ pstrcpy(msg_conv, unix_to_dos(msg)); #endif #elif SAMBA_VERSION_MAJOR==3 push_ascii_pstring(msg_conv, msg); #endif len = strlen(msg_conv); if (!cli_message_start(cli, remote_machine, username, &grp_id)) { DEBUG(5,("message start: %s\n", cli_errstr(cli))); return; } if (!cli_message_text(cli, msg_conv, len, grp_id)) { DEBUG(5,("SMBsendtxt failed: %s\n",cli_errstr(cli))); return; } if (!cli_message_end(cli, grp_id)) { DEBUG(5,("SMBsendend failed: %s\n",cli_errstr(cli))); return; } }
static void send_message(void) { int total_len = 0; int grp_id; if (!cli_message_start(cli, desthost, username, &grp_id)) { d_printf("message start: %s\n", cli_errstr(cli)); return; } d_printf("Connected. Type your message, ending it with a Control-D\n"); while (!feof(stdin) && total_len < 1600) { int maxlen = MIN(1600 - total_len,127); pstring msg; int l=0; int c; ZERO_ARRAY(msg); for (l=0;l<maxlen && (c=fgetc(stdin))!=EOF;l++) { if (c == '\n') msg[l++] = '\r'; msg[l] = c; } if (!cli_message_text(cli, msg, l, grp_id)) { d_printf("SMBsendtxt failed (%s)\n",cli_errstr(cli)); return; } total_len += l; } if (total_len >= 1600) d_printf("the message was truncated to 1600 bytes\n"); else d_printf("sent %d bytes\n",total_len); if (!cli_message_end(cli, grp_id)) { d_printf("SMBsendend failed (%s)\n",cli_errstr(cli)); return; } }