| 135 | } |
| 136 | |
| 137 | void ConfigureDomainName() { |
| 138 | char resolv_conf_file[] = "/etc/resolv.conf"; |
| 139 | FILE *file_handle = fopen(resolv_conf_file, "r"); |
| 140 | char *file_buffer = NULL; |
| 141 | size_t file_length; |
| 142 | char *domain_name_string = NULL; |
| 143 | char *dns1_string = NULL; |
| 144 | char *dns2_string = NULL; |
| 145 | |
| 146 | if(file_handle) { |
| 147 | fseek(file_handle, 0, SEEK_END); |
| 148 | file_length = ftell(file_handle); |
| 149 | fseek(file_handle, 0, SEEK_SET); |
| 150 | file_buffer = malloc(file_length); |
| 151 | if(file_buffer) { |
| 152 | fread(file_buffer, 1, file_length, file_handle); |
| 153 | fclose(file_handle); |
| 154 | } |
| 155 | else{ |
| 156 | OPENER_TRACE_ERR("Could not allocate memory for reading file %s\n", |
| 157 | resolv_conf_file); |
| 158 | fclose(file_handle); |
| 159 | exit(1); |
| 160 | } |
| 161 | } else { |
| 162 | OPENER_TRACE_ERR("Could not open file %s\n", resolv_conf_file); |
| 163 | exit(1); |
| 164 | } |
| 165 | |
| 166 | if(strstr(file_buffer, "domain") ) { |
| 167 | char *strtok_save = NULL; |
| 168 | strtok_r(file_buffer, " ", &strtok_save); |
| 169 | domain_name_string = strtok_r(file_buffer, "\n", &strtok_save); |
| 170 | |
| 171 | if(NULL != interface_configuration_.domain_name.string) { |
| 172 | /* if the string is already set to a value we have to free the resources |
| 173 | * before we can set the new value in order to avoid memory leaks. |
| 174 | */ |
| 175 | CipFree(interface_configuration_.domain_name.string); |
| 176 | } |
| 177 | interface_configuration_.domain_name.length = strlen(domain_name_string); |
| 178 | |
| 179 | if(interface_configuration_.domain_name.length) { |
| 180 | interface_configuration_.domain_name.string = (EipByte *) CipCalloc( |
| 181 | interface_configuration_.domain_name.length + 1, |
| 182 | sizeof(EipByte) ); |
| 183 | snprintf(interface_configuration_.domain_name.string, |
| 184 | (interface_configuration_.domain_name.length + 1) * |
| 185 | sizeof(EipByte), |
| 186 | "%s", |
| 187 | domain_name_string); |
| 188 | } |
| 189 | else{ |
| 190 | interface_configuration_.domain_name.string = NULL; |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | if(strstr(file_buffer, "nameserver") ) { |