Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //function from my Brother I4K the master of wizards
- //from Orion-Socket API
- int orion_getHostByName(const char* name, char* buffer)
- {
- struct addrinfo hints, * res, * res0 = NULL;
- struct sockaddr_in * target = NULL;
- int error;
- const char *tmp = NULL;
- memset(&hints, 0, sizeof(struct addrinfo));
- hints.ai_family = PF_UNSPEC;
- hints.ai_socktype = 0;
- error = getaddrinfo(name, "http", &hints, &res0);
- if(error)
- {
- if (res0)
- freeaddrinfo(res0);
- return 1;
- }
- for (res = res0; res; res = res->ai_next)
- {
- target = (struct sockaddr_in *) res->ai_addr;
- if (target)
- {
- // tmp = inet_ntoa(target->sin_addr);
- tmp=(char *)inet_ntop(AF_INET,&(target->sin_addr),name,INET_ADDRSTRLEN);
- if (tmp && strlen(tmp))
- {
- strncpy(buffer, tmp, strlen(tmp));
- buffer[strlen(tmp)] = '\0';
- if (res0)
- freeaddrinfo(res0);
- return 1;
- }
- }
- }
- freeaddrinfo(res0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment