128 lines
3.3 KiB
Plaintext
128 lines
3.3 KiB
Plaintext
$OpenBSD: patch-noip2_c,v 1.1 2003/05/07 08:33:19 wilfried Exp $
|
|
--- noip2.c.orig Sat Mar 8 16:56:04 2003
|
|
+++ noip2.c Wed May 7 10:08:59 2003
|
|
@@ -93,7 +93,8 @@
|
|
#include <sys/ipc.h>
|
|
#include <sys/shm.h>
|
|
#include <pwd.h>
|
|
-
|
|
+#include <ifaddrs.h>
|
|
+#include <net/if_types.h>
|
|
|
|
#ifdef linux
|
|
#ifndef SIOCGIFADDR
|
|
@@ -153,11 +154,8 @@
|
|
#define NOGROUP "@@NO_GROUP@@"
|
|
#define HOST 1
|
|
#define GROUP 2
|
|
-#ifndef PREFIX
|
|
- #define PREFIX "/usr/local"
|
|
-#endif
|
|
-#define CONFIG_FILEPATH PREFIX"/etc"
|
|
-#define CONFIG_FILENAME PREFIX"/etc/no-ip2.conf"
|
|
+#define CONFIG_FILEPATH "/etc"
|
|
+#define CONFIG_FILENAME "/etc/no-ip2.conf"
|
|
#define CONFSTRLEN 1024
|
|
#define MAX_DEVLEN 16
|
|
#define MAX_INSTANCE 4
|
|
@@ -657,7 +655,7 @@ void save_IP()
|
|
void getip(char *p, char *device)
|
|
{
|
|
int fd;
|
|
- int *x;
|
|
+ struct sockaddr_in *sin;
|
|
struct ifreq ifr;
|
|
struct in_addr z;
|
|
|
|
@@ -684,8 +682,8 @@ void getip(char *p, char *device)
|
|
return;
|
|
}
|
|
close(fd);
|
|
- x = (int *)&ifr.ifr_addr; // seems to be off by 2 bytes
|
|
- z.s_addr = x[1];
|
|
+ sin = (struct sockaddr_in *)&ifr.ifr_addr;
|
|
+ z = sin->sin_addr;
|
|
strcpy(p, inet_ntoa(z));
|
|
#ifdef DEBUG
|
|
if (my_instance ? my_instance->debug : debug)
|
|
@@ -1376,7 +1374,7 @@ int dynamic_update()
|
|
if (my_instance ? my_instance->debug : debug)
|
|
Msg("Running %s %s %s", buffer, p, tbuf);
|
|
#endif
|
|
- execl(buffer, p, tbuf, NULL);
|
|
+ execl(buffer, p, tbuf, (void*)0);
|
|
Msg("execl %s failed (%s)", buffer, strerror(errno));
|
|
exit(0); // bad execute -- don't care!
|
|
default: // parent
|
|
@@ -1832,45 +1830,36 @@ void get_credentials(char *l, char *p)
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
int get_all_device_names(unsigned char *devs)
|
|
{
|
|
-
|
|
- int fd, i, devnum=0;
|
|
- int num_ifreq;
|
|
+ int devnum=0;
|
|
unsigned char *p, *q, *dq;
|
|
- struct ifreq *pIfr;
|
|
- struct ifconf Ifc;
|
|
- static struct ifreq IfcBuf[MAX_NET_DEVS];
|
|
-
|
|
- Ifc.ifc_len = sizeof(IfcBuf);
|
|
- Ifc.ifc_buf = (char *) IfcBuf;
|
|
-
|
|
- if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
|
|
- perror("socket()");
|
|
- exit(1);
|
|
+ struct ifaddrs *ifap, *ifa;
|
|
+ if (getifaddrs(&ifap) != 0) {
|
|
+ return 0;
|
|
}
|
|
- if (ioctl(fd, SIOCGIFCONF, &Ifc) < 0) {
|
|
- perror("ioctl SIOCGIFCONF");
|
|
- exit(1);
|
|
- }
|
|
- num_ifreq = Ifc.ifc_len / sizeof(struct ifreq);
|
|
dq = devs; // add new name into list
|
|
- for (pIfr=Ifc.ifc_req,i=0; i<num_ifreq; pIfr++,i++) {
|
|
- q = dq; // add new name into list
|
|
- p = pIfr->ifr_name;
|
|
- if (strcmp("lo", p) == 0)
|
|
- continue;
|
|
- if (strchr(p, ':') != NULL)
|
|
- continue;
|
|
- devnum++;
|
|
- while (*p)
|
|
- *q++ = *p++;
|
|
- *q = 0;
|
|
- if (devnum >= MAX_NET_DEVS) {
|
|
- Msg(CMSG23, MAX_NET_DEVS);
|
|
- exit(1);
|
|
- }
|
|
- dq += LINELEN;
|
|
+ for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
|
|
+ if (ifa->ifa_addr->sa_family == AF_LINK) {
|
|
+ struct if_data *ifd = (struct if_data *) ifa->ifa_data;
|
|
+ if (ifd->ifi_type != IFT_ETHER)
|
|
+ continue;
|
|
+ q = dq; // add new name into list
|
|
+ p = ifa->ifa_name;
|
|
+ if (strcmp("lo", p) == 0)
|
|
+ continue;
|
|
+ devnum++;
|
|
+ while (*p)
|
|
+ *q++ = *p++;
|
|
+ *q = 0;
|
|
+ if (devnum >= MAX_NET_DEVS) {
|
|
+ Msg(CMSG23, MAX_NET_DEVS);
|
|
+ exit(1);
|
|
+ }
|
|
+ dq += LINELEN;
|
|
+ }
|
|
}
|
|
+ freeifaddrs(ifap);
|
|
return devnum;
|
|
+
|
|
}
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
void get_device_name(char *d)
|