Browse Source

* src/ipaddr.[ch] : y

master
Alex 'AdUser' Z 9 years ago
parent
commit
4c4a2091b5
  1. 37
      src/ipaddr.c
  2. 1
      src/ipaddr.h

37
src/ipaddr.c

@ -48,7 +48,6 @@ f2b_addrlist_append(f2b_ipaddr_t *list, f2b_ipaddr_t *ipaddr) {
f2b_ipaddr_t * f2b_ipaddr_t *
f2b_addrlist_lookup(f2b_ipaddr_t *list, const char *addr) { f2b_addrlist_lookup(f2b_ipaddr_t *list, const char *addr) {
assert(addr != NULL); assert(addr != NULL);
if (list == NULL) if (list == NULL)
@ -64,22 +63,36 @@ f2b_addrlist_lookup(f2b_ipaddr_t *list, const char *addr) {
f2b_ipaddr_t * f2b_ipaddr_t *
f2b_addrlist_remove(f2b_ipaddr_t *list, const char *addr) { f2b_addrlist_remove(f2b_ipaddr_t *list, const char *addr) {
f2b_ipaddr_t *a = NULL; f2b_ipaddr_t *a = NULL, *prev = NULL;
assert(addr != NULL); assert(addr != NULL);
if (list == NULL) for (a = list; a != NULL; a = a->next) {
return NULL; if (strncmp(a->text, addr, sizeof(a->text)) == 0) {
if (prev == NULL) {
if (strncmp(list->text, addr, sizeof(list->text)) == 0) { /* first elem in list */
a = list->next; list = a->next;
f2b_ipaddr_destroy(list); } else {
return a; /* somewhere in list */
prev->next = a->next;
}
f2b_ipaddr_destroy(a);
return list;
}
prev = a;
} }
for (a = list; a->next != NULL; a = a->next) { return list;
assert(0); /* TODO */ }
f2b_ipaddr_t *
f2b_addrlist_destroy(f2b_ipaddr_t *list) {
f2b_ipaddr_t *next = NULL;
for (; list != NULL; list = next) {
next = list->next;
f2b_ipaddr_destroy(list);
} }
return list; return NULL;
} }

1
src/ipaddr.h

@ -22,5 +22,6 @@ void f2b_ipaddr_destroy(f2b_ipaddr_t *ipaddr);
f2b_ipaddr_t * f2b_addrlist_append(f2b_ipaddr_t *list, f2b_ipaddr_t *ipaddr); f2b_ipaddr_t * f2b_addrlist_append(f2b_ipaddr_t *list, f2b_ipaddr_t *ipaddr);
f2b_ipaddr_t * f2b_addrlist_lookup(f2b_ipaddr_t *list, const char *addr); f2b_ipaddr_t * f2b_addrlist_lookup(f2b_ipaddr_t *list, const char *addr);
f2b_ipaddr_t * f2b_addrlist_remove(f2b_ipaddr_t *list, const char *addr); f2b_ipaddr_t * f2b_addrlist_remove(f2b_ipaddr_t *list, const char *addr);
f2b_ipaddr_t * f2b_addrlist_destroy(f2b_ipaddr_t *list);
#endif /* F2B_IPADDR_H_ */ #endif /* F2B_IPADDR_H_ */

Loading…
Cancel
Save