aboutsummaryrefslogtreecommitdiff
path: root/networking
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2006-05-29 06:43:55 +0000
committerRob Landley <rob@landley.net>2006-05-29 06:43:55 +0000
commita6e131dab39ee67522687a56b39ed815b9ae15ec (patch)
tree1ca2de8c070d79096f6db1a4a614d00a0ef7800d /networking
parentbba7f08d2788bc9bc30a7a60fdfd873a73fead9a (diff)
downloadbusybox-a6e131dab39ee67522687a56b39ed815b9ae15ec.tar.gz
Size reductions, mostly switching things to use libbb functions.
Diffstat (limited to 'networking')
-rw-r--r--networking/dnsd.c33
-rw-r--r--networking/ifupdown.c69
-rw-r--r--networking/interface.c4
-rw-r--r--networking/libiproute/ll_map.c5
-rw-r--r--networking/nameif.c4
5 files changed, 25 insertions, 90 deletions
diff --git a/networking/dnsd.c b/networking/dnsd.c
index b9d022170..58a8fc1d2 100644
--- a/networking/dnsd.c
+++ b/networking/dnsd.c
@@ -82,8 +82,7 @@ static uint32_t ttl = DEFAULT_TTL;
/*
* 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++)
@@ -95,8 +94,7 @@ convname(char *a, uint8_t *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++;
@@ -111,8 +109,7 @@ undot(uint8_t * rip)
/*
* 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)
@@ -133,8 +130,7 @@ log_message(char *filename, char *message)
* 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;
@@ -168,19 +164,16 @@ restart:
/*
* 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))
@@ -199,8 +192,7 @@ dnsentryinit(int 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];
@@ -228,8 +220,7 @@ listen_socket(char *iface_addr, int listen_port)
* 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;
@@ -269,8 +260,7 @@ table_lookup(uint16_t type, uint8_t * as, uint8_t * qs)
* 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;
@@ -367,8 +357,7 @@ process_packet(uint8_t * buf)
/*
* Exit on signal
*/
-static void
-interrupt(int x)
+static void interrupt(int x)
{
unlink(LOCK_FILE);
write(2, "interrupt exiting\n", 18);
diff --git a/networking/ifupdown.c b/networking/ifupdown.c
index 038bb13bc..6a200bb26 100644
--- a/networking/ifupdown.c
+++ b/networking/ifupdown.c
@@ -629,10 +629,7 @@ static struct interfaces_file_t *read_interfaces(const char *filename)
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");
@@ -647,10 +644,7 @@ static struct interfaces_file_t *read_interfaces(const char *filename)
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) {
@@ -690,7 +684,7 @@ static struct interfaces_file_t *read_interfaces(const char *filename)
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);
@@ -724,9 +718,6 @@ static struct interfaces_file_t *read_interfaces(const char *filename)
return NULL;
}
- currif->max_options = 0;
- currif->n_options = 0;
- currif->option = NULL;
{
llist_t *iface_list;
@@ -845,9 +836,7 @@ static char *setlocalenv(char *format, const char *name, const char *value)
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 == '-')
@@ -878,11 +867,9 @@ static void set_environ(struct interface_defn_t *iface, const char *mode)
*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
@@ -892,19 +879,13 @@ static void set_environ(struct interface_defn_t *iface, const char *mode)
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)
@@ -1069,7 +1050,7 @@ static char *run_mapping(char *physical, struct mapping_defn_t * map)
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);
}
@@ -1177,28 +1158,6 @@ int ifupdown_main(int argc, char **argv)
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) {
@@ -1206,7 +1165,6 @@ int ifupdown_main(int argc, char **argv)
list = list->link;
}
target_list = defn->autointerfaces;
-#endif
}
} else {
llist_add_to_end(&target_list, argv[optind]);
@@ -1308,8 +1266,7 @@ int ifupdown_main(int argc, char **argv)
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 {
@@ -1318,17 +1275,7 @@ int ifupdown_main(int argc, char **argv)
}
} 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));
}
}
}
diff --git a/networking/interface.c b/networking/interface.c
index 3d399be71..260dac073 100644
--- a/networking/interface.c
+++ b/networking/interface.c
@@ -76,7 +76,6 @@
#define _PATH_PROCNET_DEV "/proc/net/dev"
#define _PATH_PROCNET_IFINET6 "/proc/net/if_inet6"
-#define new(p) ((p) = xcalloc(1,sizeof(*(p))))
#if HAVE_AFINET6
@@ -789,7 +788,8 @@ static struct interface *add_interface(char *name)
if (n < 0)
break;
}
- new(new);
+
+ new = xzalloc(sizeof(*new));
safe_strncpy(new->name, name, IFNAMSIZ);
nextp = ife ? &ife->next : &int_list;
new->prev = ife;
diff --git a/networking/libiproute/ll_map.c b/networking/libiproute/ll_map.c
index 46c873faa..24487eb3d 100644
--- a/networking/libiproute/ll_map.c
+++ b/networking/libiproute/ll_map.c
@@ -17,6 +17,7 @@
#include "libnetlink.h"
#include "ll_map.h"
+#include "libbb.h"
struct idxmap
{
@@ -57,9 +58,7 @@ int ll_remember_index(struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
break;
if (im == NULL) {
- im = malloc(sizeof(*im));
- if (im == NULL)
- return 0;
+ im = xmalloc(sizeof(*im));
im->next = *imp;
im->index = ifi->ifi_index;
*imp = im;
diff --git a/networking/nameif.c b/networking/nameif.c
index 8590a98ad..7dc48ec16 100644
--- a/networking/nameif.c
+++ b/networking/nameif.c
@@ -105,7 +105,7 @@ int nameif_main(int argc, char **argv)
if (strlen(*a) > IF_NAMESIZE)
serror("interface name `%s' too long", *a);
- ch = xcalloc(1, sizeof(mactable_t));
+ ch = xzalloc(sizeof(mactable_t));
ch->ifname = bb_xstrdup(*a++);
ch->mac = cc_macaddr(*a++);
if (clist)
@@ -126,7 +126,7 @@ int nameif_main(int argc, char **argv)
continue;
}
name_length = strcspn(line_ptr, " \t");
- ch = xcalloc(1, sizeof(mactable_t));
+ ch = xzalloc(sizeof(mactable_t));
ch->ifname = bb_xstrndup(line_ptr, name_length);
if (name_length > IF_NAMESIZE)
serror("interface name `%s' too long", ch->ifname);