Changeset 4777:5a250aafb5ba in roaraudio


Ignore:
Timestamp:
03/10/11 16:11:03 (13 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

Added support for use of DECnet and ARP neighbour tables to locate servers (enumdev only at the moment).

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • ChangeLog

    r4774 r4777  
    99        * Added IPv6 support 
    1010        * Updated Debian init script (See: DEB#613772) 
     11        * Added support for use of DECnet and ARP neighbour tables to locate servers 
     12          (enumdev only at the moment) (pr1) 
    1113 
    1214v. 0.4beta3 - Wed Jan 26 2011 23:26 CET 
  • libroar/enumdev.c

    r4775 r4777  
    4141 struct roar_connection con; 
    4242 struct roar_server_info * info; 
     43 int checked = 0; 
    4344 
    4445 if ( c->server == NULL ) 
     
    4748 if ( flags & ROAR_ENUM_FLAG_NONBLOCK ) 
    4849  return 0; 
     50 
     51 ROAR_DBG("_test_server(c=%p{.server='%s', ...}, flags=0x%.4X) = ?", c, c->server, flags); 
    4952 
    5053 if ( roar_connect(&con, (char*)c->server) == -1 ) 
     
    5457  info = roar_server_info(&con); 
    5558  if ( info != NULL ) { 
     59   checked = 1; 
    5660   if ( info->location != NULL ) 
    5761    c->location = roar_mm_strdup(info->location); 
     
    6165 
    6266   roar_server_info_free(info); 
     67  } 
     68 } 
     69 
     70 // make sure we get at least a NOOP from the server to detect protocol mismatch. 
     71 if ( !checked ) { 
     72  if ( roar_noop(&con) != 0 ) { 
     73   roar_disconnect(&con); 
     74   return -1; 
    6375  } 
    6476 } 
     
    162174} 
    163175 
     176static ssize_t _esl_neighbours(int flags, int dir, int socktype, char ** servers, size_t maxlen) { 
     177 ssize_t ret = 0; 
     178 char buf[1024]; 
     179 FILE * inp; 
     180 size_t i; 
     181 char * delm; 
     182 const struct { 
     183  const char * file; 
     184  const char * suffix; 
     185  const size_t skip; 
     186 } *f, files[] = { 
     187#ifdef ROAR_PROC_NET_DECNET_NEIGH 
     188  {ROAR_PROC_NET_DECNET_NEIGH, "::", 1}, 
     189#endif 
     190#ifdef ROAR_PROC_NET_ARP 
     191  {ROAR_PROC_NET_ARP, NULL, 1}, 
     192#endif 
     193  {NULL, NULL, 0} 
     194 }; 
     195 
     196 for (f = &(files[0]); f->file != NULL; f++) { 
     197  if ( (inp = fopen(f->file, "r")) == NULL ) 
     198   continue; 
     199 
     200  for (i = 0; i < f->skip; i++) { 
     201   if ( fgets(buf, sizeof(buf), inp) == NULL ) { 
     202    // bad error... 
     203    fclose(inp); 
     204    return ret; 
     205   } 
     206  } 
     207 
     208  while (ret < (ssize_t)maxlen && fgets(buf, sizeof(buf), inp) != NULL) { 
     209   // skip comments and empty lions 
     210   if ( buf[0] == '#' || buf[0] == '\0' ) 
     211    continue; 
     212 
     213   // ensure we have a tailing \0. 
     214   buf[sizeof(buf)-1] = 0; 
     215 
     216   delm = strstr(buf, " "); 
     217   if ( delm == NULL ) 
     218    delm = strstr(buf, "\t"); 
     219 
     220   // does it look like a correctly formated lion? 
     221   // we may remove this check or relax it later. 
     222   if ( delm == NULL ) 
     223    continue; 
     224 
     225   *delm = 0; 
     226 
     227   if ( f->suffix != NULL ) { 
     228    if ( (strlen(buf) + strlen(f->suffix) + 1) > sizeof(buf) ) 
     229     continue; 
     230 
     231    strcat(buf, f->suffix); 
     232   } 
     233 
     234   // work around a bug in Linux kernel which always reports node 0.2 to be up. 
     235   if ( !strcmp(buf, "0.2::") ) 
     236    continue; 
     237 
     238   _add(buf); 
     239  } 
     240 
     241  fclose(inp); 
     242  if ( ret == (ssize_t)maxlen ) 
     243   break; 
     244 } 
     245 
     246 return ret; 
     247} 
     248 
    164249struct locmed { 
    165250 int supflags; 
     
    169254static struct locmed _libroar_locmod[] = { 
    170255 {ROAR_ENUM_FLAG_NONBLOCK|ROAR_ENUM_FLAG_HARDNONBLOCK, _esl_defaults}, 
    171  {ROAR_ENUM_FLAG_NONE,                                 _esl_slp} 
     256 {ROAR_ENUM_FLAG_NONE,                                 _esl_slp}, 
     257 {ROAR_ENUM_FLAG_NONBLOCK,                             _esl_neighbours} 
    172258}; 
    173259 
Note: See TracChangeset for help on using the changeset viewer.