EDIT: Title is a misnomer, it's not an array it's a pointer
I have a struct that I use to pass arguments to a function referenced by pthread_create( ). It looks like this:
My problem is with the char * hoststr member of the struct. Take a look at this code:
When __tryConnect() is executed, "sock", "proto", and "port" are passed correctly, but "hoststr" becomes gibberish.
__tryConnect() looks like this:
The program's output looks like this:
What is happening with hoststr?
I have a struct that I use to pass arguments to a function referenced by pthread_create( ). It looks like this:
Code:
struct __tryConnect_args
{
int sock;
char * hoststr;
unsigned int port;
int proto;
};
Code:
char * hostString;
hostString = dnsLookup(argv[1], AF_INET); /* prototype : char * dnsLookup(char *, int) */
printf("Connecting to %s\n", hostString);
for (i = 0; i < maxConns; i++)
{
connArgs[i].sock = sock;
connArgs[i].hoststr = hostString;
connArgs[i].proto = PF_INET;
connArgs[i].port = port;
pthread_create( &connThreads[i],
NULL,
&__tryConnect,
(void *) &connArgs[i] );
}
__tryConnect() looks like this:
Code:
void * __tryConnect(void * args)
{
struct __tryConnect_args * argsStruct;
argsStruct = (struct __tryConnect_args *) args;
printf("args: hoststr: %s\nport: %d\n", argsStruct->hoststr, argsStruct->port);
}
Code:
Getting address info for google.com Connecting to 209.85.171.100 args: hoststr: � �@ port: 80
Comment