From Jo-Philipp Wich <freifunk@wwsnet.net>: name-service plugin - write MID entries...
authorHannes Gredler <hannes@gredler.at>
Fri, 28 Dec 2007 11:17:46 +0000 (12:17 +0100)
committerHannes Gredler <hannes@gredler.at>
Fri, 28 Dec 2007 11:17:46 +0000 (12:17 +0100)
lib/nameservice/src/nameservice.c
lib/nameservice/src/nameservice.h

index 086ef73..dedb199 100644 (file)
@@ -992,6 +992,10 @@ write_hosts_file(void)
        int c=0;
        time_t currtime;
 
        int c=0;
        time_t currtime;
 
+#ifdef MID_ENTRIES
+       struct mid_address *alias;
+#endif
+
        if (!name_table_changed)
                return;
 
        if (!name_table_changed)
                return;
 
@@ -1038,11 +1042,54 @@ write_hosts_file(void)
                        for (name = entry->names; name != NULL; name = name->next) 
                        {
                                struct ipaddr_str strbuf;
                        for (name = entry->names; name != NULL; name = name->next) 
                        {
                                struct ipaddr_str strbuf;
-                               OLSR_PRINTF(6, "%s\t%s%s", olsr_ip_to_string(&strbuf, &name->ip), name->name, my_suffix);
-                               OLSR_PRINTF(6, "\t#%s\n", olsr_ip_to_string(&strbuf, &entry->originator));
 
 
-                               fprintf(hosts, "%s\t%s%s", olsr_ip_to_string(&strbuf, &name->ip), name->name, my_suffix);
-                               fprintf(hosts, "\t# %s\n", olsr_ip_to_string(&strbuf, &entry->originator));
+                               OLSR_PRINTF(
+                                       6, "%s\t%s%s\t#%s\n",
+                                               olsr_ip_to_string( &strbuf, &name->ip ), name->name, my_suffix,
+                                               olsr_ip_to_string( &strbuf, &entry->originator )
+                               );
+
+                               fprintf(
+                                       hosts, "%s\t%s%s\t# %s\n",
+                                               olsr_ip_to_string( &strbuf, &name->ip ), name->name, my_suffix,
+                                               olsr_ip_to_string( &strbuf, &entry->originator )
+                               );
+
+#ifdef MID_ENTRIES
+                               // write mid entries
+                               if( ( alias = mid_lookup_aliases( &name->ip ) ) != NULL )
+                               {
+                                       unsigned short mid_num = 1;
+                                       char       mid_prefix[MID_MAXLEN];
+
+                                       while( alias != NULL )
+                                       {
+                                               struct ipaddr_str midbuf;
+
+                                               // generate mid prefix
+                                               sprintf( mid_prefix, MID_PREFIX, mid_num );
+
+                                               OLSR_PRINTF(
+                                                       6, "%s\t%s%s%s\t# %s (mid #%i)\n",
+                                                               olsr_ip_to_string( &midbuf, &alias->alias ),
+                                                               mid_prefix, name->name, my_suffix,
+                                                               olsr_ip_to_string( &strbuf, &entry->originator ),
+                                                               mid_num
+                                               );
+
+                                               fprintf(
+                                                       hosts, "%s\t%s%s%s\t# %s (mid #%i)\n",
+                                                               olsr_ip_to_string( &midbuf, &alias->alias ),
+                                                               mid_prefix, name->name, my_suffix,
+                                                               olsr_ip_to_string( &strbuf, &entry->originator ),
+                                                               mid_num
+                                               );
+
+                                               alias = alias->next_alias;
+                                               mid_num++;
+                                       }
+                               }
+#endif
                        }
                }
        }
                        }
                }
        }
index a413a70..53679cd 100644 (file)
 #define MAX_FILE 255
 #define MAX_SUFFIX 63
 
 #define MAX_FILE 255
 #define MAX_SUFFIX 63
 
+#define MID_ENTRIES 1
+#define MID_MAXLEN 16
+#define MID_PREFIX "mid%i."
+
 /**
  * a linked list of name_entry
  * if type is NAME_HOST, name is a hostname and ip its IP addr
 /**
  * a linked list of name_entry
  * if type is NAME_HOST, name is a hostname and ip its IP addr