Original Post
I'm writing a *cough* mass net send program but something is acting strange when I try to pass a variable from CreateThread to my ThreadPoc. Basically, my program could create about 250 threads and pass an id number to each (id number starts at 0 and goes up to 250 or so). I then insert that ID number into the last ocet of an IP address and print out a list of the generated IP addresses. As you can see below, the list isn't how it should be. The last ocets should start at 0 and go up to ~250, but instead, there's lots of duplicates and missing ones:
Generating IP's IP addresses generated, Creating threads 12.230.77.0 12.230.77.18 12.230.77.18 12.230.77.18 12.230.77.18 12.230.77.18 12.230.77.18 12.230.77.18 12.230.77.18 12.230.77.18 12.230.77.18 12.230.77.18 12.230.77.18 12.230.77.18 12.230.77.18 12.230.77.18 12.230.77.18 12.230.77.18 12.230.77.18 12.230.77.36 12.230.77.36 12.230.77.36 12.230.77.36 12.230.77.36 12.230.77.36 12.230.77.36 12.230.77.36 12.230.77.36 12.230.77.36 12.230.77.36 12.230.77.36 12.230.77.36 12.230.77.36 12.230.77.36 12.230.77.36 12.230.77.36 12.230.77.36 12.230.77.54 12.230.77.54 12.230.77.54 12.230.77.54 12.230.77.54 12.230.77.54 12.230.77.54 12.230.77.54 12.230.77.54 12.230.77.54 12.230.77.54 12.230.77.54 12.230.77.54 12.230.77.54 12.230.77.54 12.230.77.54 12.230.77.54 12.230.77.54 12.230.77.72 12.230.77.72 12.230.77.72 12.230.77.72 12.230.77.72 12.230.77.72 12.230.77.72 12.230.77.72 12.230.77.72 12.230.77.72 12.230.77.72 12.230.77.72 12.230.77.72 12.230.77.72 12.230.77.72 12.230.77.72 12.230.77.72 12.230.77.72 12.230.77.87 12.230.77.87 12.230.77.87 12.230.77.87 12.230.77.87 12.230.77.87 12.230.77.87 12.230.77.87 12.230.77.87 12.230.77.87 12.230.77.87 12.230.77.87 12.230.77.87 12.230.77.87 12.230.77.87 12.230.77.105 12.230.77.105 12.230.77.105 12.230.77.105 12.230.77.105 12.230.77.105 12.230.77.105 12.230.77.105 12.230.77.105 12.230.77.105 12.230.77.105 12.230.77.105 12.230.77.105 12.230.77.105 12.230.77.105 12.230.77.105 12.230.77.105 12.230.77.105 12.230.77.123 12.230.77.123 12.230.77.123 12.230.77.123 12.230.77.123 12.230.77.123 12.230.77.123 12.230.77.123 12.230.77.123 12.230.77.123 12.230.77.123 12.230.77.123 12.230.77.123 12.230.77.123 12.230.77.123 12.230.77.123 12.230.77.123 12.230.77.123 12.230.77.141 12.230.77.141 12.230.77.141 12.230.77.141 12.230.77.141 12.230.77.141 12.230.77.141 12.230.77.141 12.230.77.141 12.230.77.141 12.230.77.141 12.230.77.141 12.230.77.141 12.230.77.141 12.230.77.141 12.230.77.141 12.230.77.141 12.230.77.141 12.230.77.159 12.230.77.159 12.230.77.159 12.230.77.159 12.230.77.159 12.230.77.159 12.230.77.159 12.230.77.159 12.230.77.159 12.230.77.159 12.230.77.159 12.230.77.159 12.230.77.159 12.230.77.159 12.230.77.159 12.230.77.159 12.230.77.159 12.230.77.159 12.230.77.177 12.230.77.177 12.230.77.177 12.230.77.177 12.230.77.177 12.230.77.177 12.230.77.177 12.230.77.177 12.230.77.177 12.230.77.177 12.230.77.177 12.230.77.177 12.230.77.177 12.230.77.177 12.230.77.177 12.230.77.177 12.230.77.177 12.230.77.177 12.230.77.195 12.230.77.195 12.230.77.195 12.230.77.195 12.230.77.195 12.230.77.195 12.230.77.195 12.230.77.195 12.230.77.195 12.230.77.195 12.230.77.195 12.230.77.195 12.230.77.195 12.230.77.195 12.230.77.195 12.230.77.195 12.230.77.195 12.230.77.195 12.230.77.213 12.230.77.213 12.230.77.213 12.230.77.213 12.230.77.213 12.230.77.213 12.230.77.213 12.230.77.213 12.230.77.213 12.230.77.213 12.230.77.213 12.230.77.213 12.230.77.213 12.230.77.213 12.230.77.213 12.230.77.213 12.230.77.213 12.230.77.213 12.230.77.231 12.230.77.231 12.230.77.231 12.230.77.231 12.230.77.231 12.230.77.231 12.230.77.231 12.230.77.231 12.230.77.231 12.230.77.231 12.230.77.231 12.230.77.231 12.230.77.231 12.230.77.231 12.230.77.231 12.230.77.231 12.230.77.231 12.230.77.231 12.230.77.249 12.230.77.249 12.230.77.249 12.230.77.249 12.230.77.249 12.230.77.249 12.230.77.249 12.230.77.249 12.230.77.249 12.230.77.249 12.230.77.249 12.230.77.249 12.230.77.249 12.230.77.249 12.230.77.249 12.230.77.249 12.230.77.249 12.230.77.249Here's my code:
// massmsg.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <windows.h>
#include <lm.h>
#include <winsock.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAXLEN 1024
DWORD WINAPI ThreadFunc( LPVOID lpParam );
int done=0;
struct ip
{
char Recp[255];
};
ip IPS[254];
int main(int argc, char* argv[])
{
// TODO: Place code here.
printf("Generating IP's\n");
for(int x=0;x<254;x++)
{
sprintf(IPS[x].Recp,"12.230.77.%i",x);
}
printf("IP addresses generated, Creating threads\n\n");
for(int i=0;i<254;i++)
{
DWORD dwThreadId=1;
DWORD dwThrdParam=i;
//Create some threads =D
HANDLE hThread;
hThread = CreateThread(
NULL, // default security attributes
0, // use default stack size
ThreadFunc, // thread function
&dwThrdParam, // argument to thread function
0, // use default creation flags
&dwThreadId); // returns the thread identifier
}
while(1) {};
return 0;
}
DWORD WINAPI ThreadFunc( LPVOID lpParam )
{
NET_API_STATUS nasRc;
char Message[] = "Block these ads FOR FREE!\n\n visit http://www.updatexp.com/destroyads.html for instructions!";
//char Recp[] = "localhost";
char Me[] = "Matt";
wchar_t wMessage[MAXLEN];
wchar_t wRecp[MAXLEN];
wchar_t wYou[MAXLEN];
wchar_t wMe[MAXLEN];
mbstowcs( wMessage, Message, MAXLEN );
mbstowcs( wRecp, IPS[*((int *)lpParam)].Recp, MAXLEN);
mbstowcs( wMe, Me, MAXLEN);
wMessage[MAXLEN - 1] = L'\0';
wRecp[MAXLEN - 1] = L'\0';
wMe[MAXLEN - 1] = L'\0';
printf(IPS[*((DWORD*)lpParam)].Recp);
//printf("%i",*((double *)lpParam));
printf("\n");
/*nasRc = NetMessageBufferSend(NULL, // server name (null means this machine)
(unsigned short*)wRecp, // name (alias) of recipient
(unsigned short*)wMe, // who this is from
(unsigned char *)&wMessage, // message
sizeof(Message));
switch(nasRc)
{
case ERROR_ACCESS_DENIED:
printf("Access Denied\n");
break;
case ERROR_INVALID_PARAMETER:
printf("Invalid Parameter\n");
break;
case ERROR_NOT_SUPPORTED:
printf("Not Supported\n");
break;
case NERR_NameNotFound:
printf("Name Not Found\n");
break;
case NERR_NetworkError:
printf("Network Error\n");
break;
case NERR_Success:
printf("Successfully sent message to ");
printf(IPS[*((int *)lpParam)].Recp);
printf("\n");
break;
}
*/
return 0;
}
Thanks
[edited by - Xtremehobo on July 22, 2003 2:56:00 AM]
[edited by - Xtremehobo on July 22, 2003 2:56:20 AM]
[edited by - Xtremehobo on July 22, 2003 2:56:42 AM]