Re: IRC Bot Connection Error
Code:
int main(int argc, char * argv[]) {
// ...
struct addrinfo *res = NULL;
// ...
getaddrinfo(argv[1], argv[2], &hints, &res);
sockfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
// ...
}
You are using res without ever allocating any memory for it.
Is there any reason why you declared it as a pointer? If you declare it a struct, then memory will be allocated for it automatically on the stack.
Re: IRC Bot Connection Error
Are you sure? I mean, from the examples I've seen online, it should automatically be allocated. And the reason it's a pointer is because getaddrinfo wants a pointer to a linked list, not just a struct. And I did declare it as a struct :/ A pointer to a struct. It's a linked list when used appropriately.
Re: IRC Bot Connection Error
OK, it seems that getaddrinfo() allocates the memory for you. But your code must thereafter call freeaddrinfo(), as described by the documentation and the sample code at http://msdn.microsoft.com/en-us/libr...20(VS.85).aspx
As for your error on connect(), why did you cast the res variable to a (struct sockaddr *), when it already is one?
Try printing out the values of res to see if they are sensible. The actual values will probably tell you why the call is failing.