|
From: Peter K. <pk...@us...> - 2001-04-26 15:58:15
|
The following files were modified in apps/bluetooth/experimental:
Name Old version New version Comment
---- ----------- ----------- -------
bt_misc.c 1.7 1.8=20=20=20=20=20=20=20=20=20=20=20=20=20
bt_misc.h 1.4 1.5=20=20=20=20=20=20=20=20=20=20=20=20=20
btd.c 1.10 1.11=20=20=20=20=20=20=20=20=20=20=20=20
The accompanying log:
Renamed get_local_addr() to get_local_ip_address(), and improved
the way it works.
The diff of the modified file(s):
--- bt_misc.c 2001/04/25 18:04:23 1.7
+++ bt_misc.c 2001/04/26 15:58:15 1.8
@@ -231,28 +231,33 @@
=20
=20
/*=20
- * Set server_name to the numerical IP of eth0 instead of using DNS or
- * relying on /etc/hosts being correct. for now.
+ * Retrieve the numerical IP address of eth0 for now.
*/
-void get_local_addr(char *str)
+char * get_local_ip_address(void)
{
- char *local_address =3D NULL;
- int fd =3D socket(AF_INET, SOCK_DGRAM, 0);
+ int fd;
struct ifreq ifr;
- strcpy(ifr.ifr_name, "eth0");
- ioctl(fd, SIOCGIFADDR, (int)&ifr);
- close(fd);
- local_address =3D strdup(inet_ntoa(((struct sockaddr_in *)
- &ifr.ifr_addr)->sin_addr));
+ static char ip[20];
=20=20=20
- if (!local_address)
+ if ((fd =3D socket(AF_INET, SOCK_DGRAM, 0)) < 0)
{
- syslog(LOG_INFO, "could not determine local IP address!\n");
+ syslog(LOG_INFO, "Could not determine local IP address!");
+ return "0.0.0.0";
}
=20
- strcpy(str, local_address);
+ strcpy(ifr.ifr_name, "eth0");
+ if (ioctl(fd, SIOCGIFADDR, (int)&ifr) < 0)
+ {
+ syslog(LOG_INFO, "Could not determine local IP address!");
+ close(fd);
+ return "0.0.0.0";
+ }
=20
- free(local_address);
+ close(fd);
+
+ strcpy(ip, inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr));
+
+ return ip;
}
=20
int=20
--- bt_misc.h 2001/04/04 10:43:04 1.4
+++ bt_misc.h 2001/04/26 15:58:15 1.5
@@ -58,7 +58,7 @@
int open_tcpsocket(char *addrstr, int role);
=20
int write_pidfile(char *pidname);
-void get_local_addr(char *str);
+char *get_local_ip_address(void);
const char* bd2str(const unsigned char *bd);
#ifndef BT_USERSTACK
void print_data(const char *message, unsigned char *buf, int len);
--- btd.c 2001/04/25 17:58:24 1.10
+++ btd.c 2001/04/26 15:58:15 1.11
@@ -480,7 +480,7 @@
opts[i++] =3D "ktune"; /* enables ip_forwarding */
}=20=20
=20=20=20=20=20
- get_local_addr(local_ip);
+ strcpy(local_ip, get_local_ip_address());
/* local/remote ip */
sprintf(ip_addresses, "%s:%s", local_ip, inet_ntoa(ipset->ip));
=20=20=20=20=20
@@ -527,7 +527,7 @@
}
else
{=20=20=20=20
- get_local_addr(local_ip);
+ strcpy(local_ip, get_local_ip_address());
=20=20=20=20=20
/* local IP */
sprintf(ip_addresses, "%s:", local_ip);
|