Changeset 1566
- Timestamp:
- 01/25/10 10:25:47 (6 months ago)
- Files:
-
- 1 modified
-
branches/batctl-0.2.x/bat-hosts.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/batctl-0.2.x/bat-hosts.c
r1463 r1566 1 /* 1 /* 2 2 * Copyright (C) 2007-2009 B.A.T.M.A.N. contributors: 3 3 * … … 64 64 { 65 65 FILE *fd; 66 char *line_ptr = NULL; 66 67 char name[HOST_NAME_MAX_LEN], mac_str[18]; 67 68 struct ether_addr *mac_addr; 68 69 struct bat_host *bat_host; 69 70 struct hashtable_t *swaphash; 71 size_t len = 0; 70 72 71 73 name[0] = mac_str[0] = '\0'; … … 75 77 return; 76 78 77 while (fscanf(fd,"%[^ \t]%s\n", mac_str, name) != EOF) { 79 while (getline(&line_ptr, &len, fd) != -1) { 80 /* ignore empty lines and comments */ 81 if ((line_ptr[0] == '\n') || (line_ptr[0] == '#')) 82 continue; 83 84 if (sscanf(line_ptr, "%[^ \t]%s\n", mac_str, name) != 2) { 85 fprintf(stderr, "Warning - unrecognized bat-host definition: %s", line_ptr); 86 continue; 87 } 78 88 79 89 mac_addr = ether_aton(mac_str); 80 90 if (!mac_addr) { 81 printf("Warning - invalid mac address in '%s' detected: %s\n", path, mac_str);91 fprintf(stderr, "Warning - invalid mac address in '%s' detected: %s\n", path, mac_str); 82 92 continue; 83 93 } … … 87 97 /* mac entry already exists - we found a new name for it */ 88 98 if (bat_host) { 89 printf("Warning - mac already known (changing name from '%s' to '%s'): %s\n",99 fprintf(stderr, "Warning - mac already known (changing name from '%s' to '%s'): %s\n", 90 100 bat_host->name, name, mac_str); 91 101 strncpy(bat_host->name, name, HOST_NAME_MAX_LEN - 1); … … 97 107 /* name entry already exists - we found a new mac address for it */ 98 108 if (bat_host) { 99 printf("Warning - name already known (changing mac from '%s' to '%s'): %s\n",109 fprintf(stderr, "Warning - name already known (changing mac from '%s' to '%s'): %s\n", 100 110 ether_ntoa(&bat_host->mac_addr), mac_str, name); 101 111 hash_remove(*hash, bat_host); … … 106 116 107 117 if (!bat_host) { 108 printf("Error - could not allocate memory: %s\n", strerror(errno));118 fprintf(stderr, "Error - could not allocate memory: %s\n", strerror(errno)); 109 119 goto out; 110 120 } … … 119 129 120 130 if (swaphash == NULL) 121 printf("Warning - couldn't resize bat hosts hash table\n");131 fprintf(stderr, "Warning - couldn't resize bat hosts hash table\n"); 122 132 else 123 133 *hash = swaphash; 124 134 } 125 126 135 } 127 136 … … 129 138 if (fd) 130 139 fclose(fd); 140 if (line_ptr) 141 free(line_ptr); 131 142 return; 132 143 }
