diff options
Diffstat (limited to 'src/util.c')
-rw-r--r-- | src/util.c | 28 |
1 files changed, 25 insertions, 3 deletions
@@ -28,6 +28,7 @@ #include <libdaemon/dlog.h> #include "util.h" +#include "iwapi.h" struct hw_addr null_ap = { { 0, 0, 0, 0, 0, 0 } }; @@ -38,11 +39,11 @@ void print_hex(FILE *f, uint8_t *w, int l) { } } -int hw_addr_equal(struct hw_addr *a, struct hw_addr *b) { +int hw_addr_equal(const struct hw_addr *a, const struct hw_addr *b) { return memcmp(a->addr, b->addr, ETH_ALEN) == 0; } -int is_assoc_ap(struct hw_addr *ap) { +int is_assoc_ap(const struct hw_addr *ap) { int b, j; b = 1; assert(ap); @@ -134,7 +135,7 @@ int get_ifname(int idx, char *p, int l) { return 0; } -int is_iface_available(char *p) { +int is_iface_available(const char *p) { struct ifreq req; int s, r; @@ -154,3 +155,24 @@ int is_iface_available(char *p) { close(s); return r >= 0 && req.ifr_ifindex >= 0; } + +const char* escape_essid(const char *s) { + static const char hextab[] = "0123456789ABCDEF"; + static char output[3*IW_ESSID_MAX_SIZE + 1]; + const char *i; + char *o; + + for (i = s, o = output; i-s < IW_ESSID_MAX_SIZE && *i; i++) { + + if (*i >= 32 && *i < 126 && *i != '/' && *i != '%') { + *(o++) = '%'; + *(o++) = hextab[*i >> 4]; + *(o++) = hextab[*i & 0xF]; + } else + *(o++) = *i; + } + + *(o++) = 0; + + return output; +} |