Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- printf("Retrieving data for %s...\n",hostname);
- short i, j, ifd_num = 0, hst_num = 0;
- char *host_chk[20];
- char *ifad_chk[20];
- struct hostent * h_local_chk;
- char *host = (char *)malloc(255);
- gethostname(host, 255);
- if ((h_local_chk = gethostbyname(host)) < 0) die_with_signal("hostname");
- free(host);
- for (i=0; i < h_local_chk->h_length; i++) {
- host_chk[i] = calloc(1, INET_ADDRSTRLEN+1);
- inet_ntop(AF_INET, (struct in_addr *)h_local_chk->h_addr_list[i], host_chk[i], INET_ADDRSTRLEN);
- hst_num++;
- }
- struct ifaddrs *ifa = (struct ifaddrs *)malloc(sizeof(*ifa));
- if (getifaddrs(&ifa)) die_with_signal("local retr.");
- i = 0;
- for (; ifa != NULL; ifa = ifa->ifa_next) {
- if (!memcmp(ifa->ifa_name, syn->device, strlen(syn->device))) {
- ifad_chk[i] = calloc(1, INET_ADDRSTRLEN+1);
- inet_ntop(AF_INET, (void *)&((struct sockaddr_in *)ifa->ifa_addr)->sin_addr, ifad_chk[i], INET_ADDRSTRLEN);
- ifd_num++, i++;
- }
- }
- free(ifa);
- for (i = 0; i < hst_num; i++) {
- for (j = 0; j < ifd_num; j++) {
- if (!(memcmp(host_chk[i], ifad_chk[j], 10))) {
- syn->syn_data.p_src = (char *)malloc(16);
- memcpy( syn->syn_data.p_src, host_chk[i], INET_ADDRSTRLEN);
- printf("Got local IP: %s\n",syn->syn_data.p_src);
- free(host_chk[i]);
- free(ifad_chk[j]);
- break;
- }
- }
- if (syn->syn_data.p_src) break;
- }
Advertisement
Add Comment
Please, Sign In to add comment