|
From: Peter K. <pk...@us...> - 2002-02-26 17:50:57
|
The following files were modified in apps/bluetooth/experimental:
Name Old version New version Comment
---- ----------- ----------- -------
bt_if.c 1.41 1.42=20=20=20=20=20=20=20=20=20=20=20=20
bt_misc.c 1.23 1.24=20=20=20=20=20=20=20=20=20=20=20=20
bt_misc.h 1.12 1.13=20=20=20=20=20=20=20=20=20=20=20=20
btconfig.c 1.10 1.11=20=20=20=20=20=20=20=20=20=20=20=20
The accompanying log:
Added get_domain_name() which tries to get the domain name first
from /etc/resolv.conf, and if that fails using gethostname() or
getdomainname() (whichever succeeds).
The diff of the modified file(s):
--- bt_if.c 16 Oct 2001 16:15:34 -0000 1.41
+++ bt_if.c 26 Feb 2002 17:43:32 -0000 1.42
@@ -971,13 +971,11 @@
=20
void set_local_hostname(int bt_cfd, const char *local_name)
{
- unsigned char domainname[DOMAIN_NAME_LENGTH+1];
unsigned char buf[LOCAL_NAME_LENGTH + HOST_NAME_LENGTH +=20
DOMAIN_NAME_LENGTH + 5];
int len =3D 0;
=20
*buf =3D '\0';
- *domainname =3D '\0';
=20
if (*local_name)
{
@@ -1001,11 +999,12 @@
=20
if (!strchr(&buf[len], '.'))
{
- getdomainname(domainname, DOMAIN_NAME_LENGTH);
- if (*domainname)
+ char* domain_name =3D get_domain_name();
+
+ if (*domain_name)
{
strcat(buf, ".");
- strcat(buf, domainname);
+ strncat(buf, domain_name, DOMAIN_NAME_LENGTH);
}
}
=20
--- bt_misc.c 16 Oct 2001 15:02:19 -0000 1.23
+++ bt_misc.c 26 Feb 2002 17:43:32 -0000 1.24
@@ -44,7 +44,6 @@
#include <sys/wait.h>
#include <fcntl.h>
#include <stdio.h>
-#include <fcntl.h>
#include <unistd.h>
#include <termios.h>
#include <stdlib.h>
@@ -53,6 +52,7 @@
#include <errno.h>
#include <stdarg.h>
#include <signal.h>
+#include <ctype.h>
#include <linux/serial.h> /* struct serial_struct */
=20
/* The following includes are required to be able to determine the local
@@ -313,6 +313,73 @@
strcpy(ip, inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr));
=20
return ip;
+}
+
+char*
+get_domain_name(void)
+{
+ static char domain_name[256];
+ static char line[256];
+ FILE* file;
+
+ *domain_name =3D '\0';
+
+ /* Extract the domain name from the /etc/resolv.conf file */
+
+ if ((file =3D fopen("/etc/resolv.conf", "r")))
+ {
+ while (fgets(line, sizeof line, file))
+ {
+ char* s =3D line;
+
+ while (isspace(*s))
+ {
+ s++;
+ }
+
+ if (!strncasecmp(s, "domain", 6) && isspace(s[6]))
+ {
+ char* d =3D domain_name;
+
+ s +=3D 7;
+ while (isspace(*s))
+ {
+ s++;
+ }
+
+ while (*s && !isspace(*s))
+ {
+ *d++ =3D *s++;
+ }
+ *d =3D '\0';
+
+ if (*domain_name)
+ {
+ break;
+ }
+ }
+ else if (!strncasecmp(s, "search", 6) && isspace(s[6]))
+ {
+ char* d =3D domain_name;
+
+ s +=3D 7;
+ while (isspace(*s))
+ {
+ s++;
+ }
+
+ while (*s && !isspace(*s))
+ {
+ *d++ =3D *s++;
+ }
+ *d =3D '\0';
+ }
+ }
+
+ fclose(file);
+ }
+
+ return domain_name;
}
=20
int=20
--- bt_misc.h 16 Oct 2001 15:02:20 -0000 1.12
+++ bt_misc.h 26 Feb 2002 17:43:32 -0000 1.13
@@ -64,6 +64,9 @@
int restart_btd(void);
=20
char *get_local_ip_address(void);
+
+char* get_domain_name(void);
+
const char *bd2str(const unsigned char *bd);
#ifndef BT_USERSTACK
void print_data(const char *message, const unsigned char *buf, int len);
--- btconfig.c 12 Oct 2001 07:37:39 -0000 1.10
+++ btconfig.c 26 Feb 2002 17:43:32 -0000 1.11
@@ -428,19 +428,18 @@
=20
if (var_add_host_name =3D=3D TRUE)
{
- char tmp_str[DOMAIN_NAME_LENGTH];
-
D(syslog(LOG_INFO, __FUNCTION__": Add hostname and domain name"));
=20=20=20=20=20=20=20
gethostname(ip_name, HOST_NAME_LENGTH);
=20=20=20=20=20=20=20
if (!strchr(ip_name, '.'))
{
- getdomainname(tmp_str, DOMAIN_NAME_LENGTH);
- if (*tmp_str)
+ char* domain_name =3D get_domain_name();
+
+ if (*domain_name)
{
strcat(ip_name, ".");
- strcat(ip_name, tmp_str);
+ strncat(ip_name, domain_name, DOMAIN_NAME_LENGTH);
}
}
}
|