/*
* Convert host name from C-string to dns length/string.
*/
-static void
-convname(char *a, uint8_t *q)
+static void convname(char *a, uint8_t *q)
{
int i = (q[0] == '.') ? 0 : 1;
for(; i < MAX_HOST_LEN-1 && *q; i++, q++)
/*
* Insert length of substrings insetad of dots
*/
-static void
-undot(uint8_t * rip)
+static void undot(uint8_t * rip)
{
int i = 0, s = 0;
while(rip[i]) i++;
/*
* Append message to log file
*/
-static void
-log_message(char *filename, char *message)
+static void log_message(char *filename, char *message)
{
FILE *logfile;
if (!daemonmode)
* converting to a length/string substring for that label.
*/
-static int
-getfileentry(FILE * fp, struct dns_entry *s, int verb)
+static int getfileentry(FILE * fp, struct dns_entry *s, int verb)
{
unsigned int a,b,c,d;
char *r, *name;
/*
* Read hostname/IP records from file
*/
-static void
-dnsentryinit(int verb)
+static void dnsentryinit(int verb)
{
FILE *fp;
struct dns_entry *m, *prev;
prev = dnsentry = NULL;
- if(!(fp = fopen(fileconf, "r")))
- bb_perror_msg_and_die("open %s",fileconf);
+ fp = bb_xfopen(fileconf, "r");
while (1) {
- if(!(m = (struct dns_entry *)malloc(sizeof(struct dns_entry))))
- bb_perror_msg_and_die("malloc dns_entry");
+ m = xmalloc(sizeof(struct dns_entry));
m->next = NULL;
if (getfileentry(fp, m, verb))
/*
* Set up UDP socket
*/
-static int
-listen_socket(char *iface_addr, int listen_port)
+static int listen_socket(char *iface_addr, int listen_port)
{
struct sockaddr_in a;
char msg[100];
* Look query up in dns records and return answer if found
* qs is the query string, first byte the string length
*/
-static int
-table_lookup(uint16_t type, uint8_t * as, uint8_t * qs)
+static int table_lookup(uint16_t type, uint8_t * as, uint8_t * qs)
{
int i;
struct dns_entry *d=dnsentry;
* Decode message and generate answer
*/
#define eret(s) do { fprintf (stderr, "%s\n", s); return -1; } while (0)
-static int
-process_packet(uint8_t * buf)
+static int process_packet(uint8_t * buf)
{
struct dns_head *head;
struct dns_prop *qprop;
/*
* Exit on signal
*/
-static void
-interrupt(int x)
+static void interrupt(int x)
{
unlink(LOCK_FILE);
write(2, "interrupt exiting\n", 18);
enum { NONE, IFACE, MAPPING } currently_processing = NONE;
- defn = xmalloc(sizeof(struct interfaces_file_t));
- defn->autointerfaces = NULL;
- defn->mappings = NULL;
- defn->ifaces = NULL;
+ defn = xzalloc(sizeof(struct interfaces_file_t));
f = bb_xfopen(filename, "r");
if (strcmp(firstword, "mapping") == 0) {
#ifdef CONFIG_FEATURE_IFUPDOWN_MAPPING
- currmap = xmalloc(sizeof(struct mapping_defn_t));
- currmap->max_matches = 0;
- currmap->n_matches = 0;
- currmap->match = NULL;
+ currmap = xzalloc(sizeof(struct mapping_defn_t));
while ((firstword = next_word(&buf_ptr)) != NULL) {
if (currmap->max_matches == currmap->n_matches) {
NULL
};
- currif = xmalloc(sizeof(struct interface_defn_t));
+ currif = xzalloc(sizeof(struct interface_defn_t));
iface_name = next_word(&buf_ptr);
address_family_name = next_word(&buf_ptr);
method_name = next_word(&buf_ptr);
return NULL;
}
- currif->max_options = 0;
- currif->n_options = 0;
- currif->option = NULL;
{
llist_t *iface_list;
char *here;
char *there;
- result = xmalloc(strlen(format) + strlen(name) + strlen(value) + 1);
-
- sprintf(result, format, name, value);
+ result = bb_xasprintf(format, name, value);
for (here = there = result; *there != '=' && *there; there++) {
if (*there == '-')
*ppch = NULL;
}
free(__myenviron);
- __myenviron = NULL;
}
- __myenviron = xmalloc(sizeof(char *) * (n_env_entries + 1 /* for final NULL */ ));
+ __myenviron = xzalloc(sizeof(char *) * (n_env_entries + 1 /* for final NULL */ ));
environend = __myenviron;
- *environend = NULL;
for (i = 0; i < iface->n_options; i++) {
if (strcmp(iface->option[i].name, "up") == 0
continue;
}
*(environend++) = setlocalenv("IF_%s=%s", iface->option[i].name, iface->option[i].value);
- *environend = NULL;
}
*(environend++) = setlocalenv("%s=%s", "IFACE", iface->iface);
- *environend = NULL;
*(environend++) = setlocalenv("%s=%s", "ADDRFAM", iface->address_family->name);
- *environend = NULL;
*(environend++) = setlocalenv("%s=%s", "METHOD", iface->method->name);
- *environend = NULL;
*(environend++) = setlocalenv("%s=%s", "MODE", mode);
- *environend = NULL;
*(environend++) = setlocalenv("%s=%s", "PATH", "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin");
- *environend = NULL;
}
static int doit(char *str)
free(logical);
logical = new_logical;
} else {
- /* If we are UNABLE to read a line of output, discard are
+ /* If we are UNABLE to read a line of output, discard our
* freshly allocated memory. */
free(new_logical);
}
if (cmds == iface_up) {
target_list = defn->autointerfaces;
} else {
-#if 0
- /* iface_down */
- llist_t *new_item;
- const llist_t *list = state_list;
- while (list) {
- new_item = xmalloc(sizeof(llist_t));
- new_item->data = bb_xstrdup(list->data);
- new_item->link = NULL;
- list = target_list;
- if (list == NULL)
- target_list = new_item;
- else {
- while (list->link) {
- list = list->link;
- }
- list = new_item;
- }
- list = list->link;
- }
- target_list = defn->autointerfaces;
-#else
-
/* iface_down */
const llist_t *list = state_list;
while (list) {
list = list->link;
}
target_list = defn->autointerfaces;
-#endif
}
} else {
llist_add_to_end(&target_list, argv[optind]);
llist_t *iface_state = find_iface_state(state_list, iface);
if (cmds == iface_up) {
- char *newiface = xmalloc(strlen(iface) + 1 + strlen(liface) + 1);
- sprintf(newiface, "%s=%s", iface, liface);
+ char *newiface = bb_xasprintf("%s=%s", iface, liface);
if (iface_state == NULL) {
llist_add_to_end(&state_list, newiface);
} else {
}
} else {
/* Remove an interface from the linked list */
- if (iface_state) {
- llist_t *l = iface_state->link;
- free(iface_state->data);
- iface_state->data = NULL;
- iface_state->link = NULL;
- if (l) {
- iface_state->data = l->data;
- iface_state->link = l->link;
- }
- free(l);
- }
+ free(llist_pop(&iface_state));
}
}
}