This functionality is essential for those who are use NAT. Please
incorporate.
https://api.ipify.org is an alternate service to checkip.dyndns.org.
--- ez-ipupdate-3.0.11b7/ez-ipupdate.c.orig 2006-12-29 23:13:42.364545448
+0100
+++ ez-ipupdate-3.0.11b7/ez-ipupdate.c 2006-12-29 23:24:47.255466664 +0100
@@ -1630,43 +1630,132 @@
int get_if_addr(int sock, char *name, struct sockaddr_in *sin)
{
+ if (strcmp(name, "web-detect"))
+ {
#ifdef IF_LOOKUP
- struct ifreq ifr;
+ struct ifreq ifr;
- memset(&ifr, 0, sizeof(ifr));
- strcpy(ifr.ifr_name, name);
- /* why does this need to be done twice? */
- if(ioctl(sock, SIOCGIFADDR, &ifr) < 0)
- {
- perror("ioctl(SIOCGIFADDR)");
- memset(sin, 0, sizeof(struct sockaddr_in));
- dprintf((stderr, "%s: %s\n", name, "unknown interface"));
- return -1;
- }
- if(ioctl(sock, SIOCGIFADDR, &ifr) < 0)
- {
- perror("ioctl(SIOCGIFADDR)");
- memset(sin, 0, sizeof(struct sockaddr_in));
- dprintf((stderr, "%s: %s\n", name, "unknown interface"));
- return -1;
- }
+ memset(&ifr, 0, sizeof(ifr));
+ strcpy(ifr.ifr_name, name);
+ /* why does this need to be done twice? */
+ if(ioctl(sock, SIOCGIFADDR, &ifr) < 0)
+ {
+ perror("ioctl(SIOCGIFADDR)");
+ memset(sin, 0, sizeof(struct sockaddr_in));
+ dprintf((stderr, "%s: %s\n", name, "unknown interface"));
+ return -1;
+ }
+ if(ioctl(sock, SIOCGIFADDR, &ifr) < 0)
+ {
+ perror("ioctl(SIOCGIFADDR)");
+ memset(sin, 0, sizeof(struct sockaddr_in));
+ dprintf((stderr, "%s: %s\n", name, "unknown interface"));
+ return -1;
+ }
- if(ifr.ifr_addr.sa_family == AF_INET)
- {
- memcpy(sin, &(ifr.ifr_addr), sizeof(struct sockaddr_in));
- dprintf((stderr, "%s: %s\n", name, inet_ntoa(sin->sin_addr)));
- return 0;
- }
- else
- {
- memset(sin, 0, sizeof(struct sockaddr_in));
- dprintf((stderr, "%s: %s\n", name, "could not resolve interface"));
+ if(ifr.ifr_addr.sa_family == AF_INET)
+ {
+ memcpy(sin, &(ifr.ifr_addr), sizeof(struct sockaddr_in));
+ dprintf((stderr, "%s: %s\n", name, inet_ntoa(sin->sin_addr)));
+ return 0;
+ }
+ else
+ {
+ memset(sin, 0, sizeof(struct sockaddr_in));
+ dprintf((stderr, "%s: %s\n", name, "could not resolve interface"));
+ return -1;
+ }
+#endif
return -1;
+ }
+ else
+ {
+ char buf[BUFFER_SIZE+1];
+ char *bp = buf;
+ int bytes;
+ int btot;
+ int ret;
+ char *server = "checkip.dyndns.org"; // TODO: params
+ char *port = "80"; // TODO: params
+
+ buf[BUFFER_SIZE] = '\0';
+
+ if(do_connect((int*)&client_sockfd, server, port) != 0)
+ {
+ if(!(options & OPT_QUIET))
+ show_message("error connecting to ip-detection server %s:%s\n",
server, port);
+ return -1;
+ }
+
+ snprintf(buf, BUFFER_SIZE, "GET / HTTP/1.0\015\012", request);
+ output(buf);
+ snprintf(buf, BUFFER_SIZE, "User-Agent: %s-%s %s [%s] (%s)\015\012",
+ "ez-update", VERSION, OS, (options & OPT_DAEMON) ? "daemon" : "", "by
Angus Mackay");
+ output(buf);
+ snprintf(buf, BUFFER_SIZE, "Host: %s\015\012", server);
+ output(buf);
+ snprintf(buf, BUFFER_SIZE, "\015\012");
+ output(buf);
+
+ bp = buf;
+ bytes = 0;
+ btot = 0;
+ while((bytes=read_input(bp, BUFFER_SIZE-btot)) > 0)
+ {
+ bp += bytes;
+ btot += bytes;
+ dprintf((stderr, "btot: %d\n", btot));
+ }
+ close(client_sockfd);
+ buf[btot] = '\0';
+
+ dprintf((stderr, "server output: %s\n", buf));
+
+ if(sscanf(buf, " HTTP/1.%*c %3d", &ret) != 1)
+ {
+ if(!(options & OPT_QUIET))
+ show_message("strange server response, are you connecting to the right
ip-detection server?\n");
+ }
+ else if (ret != 200)
+ {
+ show_message("unknown return code: %d\n", ret);
+ }
+ else
+ {
+ char *p;
+ char *next = buf;
+ printf("request successful\n");
+ while (p = strchr(next, '.'))
+ {
+ next = p+1;
+ int dots = 1;
+ // Find beginning of number before the dot
+ while (isdigit(*(p-1)))
+ p--;
+
+ // Find end of ip
+ while (*next == '.' || isdigit(*next))
+ {
+ if (*next == '.')
+ dots++;
+ next++;
+ }
+ // If we are not at end of buffer, continue searching
+ if (*next != '\0')
+ {
+ *next = '\0';
+ next++;
+ }
+ if(dots == 3 && inet_aton(p, &sin->sin_addr))
+ {
+ dprintf((stderr, "Detected IP: %s\n", p));
+ return 0;
+ }
+ }
+ show_message("No ip address found in server response:\n%s\n",buf);
+ }
}
return -1;
-#else
- return -1;
-#endif
}
static int PGPOW_read_response(char *buf)