~ubuntu-branches/ubuntu/gutsy/wpasupplicant/gutsy

« back to all changes in this revision

Viewing changes to src/utils/ip_addr.c

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler, Alexander Sack
  • Date: 2007-08-26 16:06:57 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20070826160657-2m8pxoweuxe8f93t
Tags: 0.6.0+0.5.8-0ubuntu1
* New upstream release
* remove patch 11_erroneous_manpage_ref, applied upstream
* remove patch 25_wpas_dbus_unregister_iface_fix, applied upstream

[ Alexander Sack ]
* bumping upstream version to replace development version 0.6.0 with
  this package from stable release branch.
* attempt to fix wierd timeout and high latency issues by going
  back to stable upstream version (0.5.9) (LP: #140763,
  LP: #141233).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * IP address processing
3
 
 * Copyright (c) 2003-2006, Jouni Malinen <j@w1.fi>
4
 
 *
5
 
 * This program is free software; you can redistribute it and/or modify
6
 
 * it under the terms of the GNU General Public License version 2 as
7
 
 * published by the Free Software Foundation.
8
 
 *
9
 
 * Alternatively, this software may be distributed under the terms of BSD
10
 
 * license.
11
 
 *
12
 
 * See README and COPYING for more details.
13
 
 */
14
 
 
15
 
#include "includes.h"
16
 
 
17
 
#include "common.h"
18
 
#include "ip_addr.h"
19
 
 
20
 
const char * hostapd_ip_txt(const struct hostapd_ip_addr *addr, char *buf,
21
 
                            size_t buflen)
22
 
{
23
 
        if (buflen == 0 || addr == NULL)
24
 
                return NULL;
25
 
 
26
 
        if (addr->af == AF_INET) {
27
 
                os_strlcpy(buf, inet_ntoa(addr->u.v4), buflen);
28
 
        } else {
29
 
                buf[0] = '\0';
30
 
        }
31
 
#ifdef CONFIG_IPV6
32
 
        if (addr->af == AF_INET6) {
33
 
                if (inet_ntop(AF_INET6, &addr->u.v6, buf, buflen) == NULL)
34
 
                        buf[0] = '\0';
35
 
        }
36
 
#endif /* CONFIG_IPV6 */
37
 
 
38
 
        return buf;
39
 
}
40
 
 
41
 
 
42
 
int hostapd_ip_diff(struct hostapd_ip_addr *a, struct hostapd_ip_addr *b)
43
 
{
44
 
        if (a == NULL && b == NULL)
45
 
                return 0;
46
 
        if (a == NULL || b == NULL)
47
 
                return 1;
48
 
 
49
 
        switch (a->af) {
50
 
        case AF_INET:
51
 
                if (a->u.v4.s_addr != b->u.v4.s_addr)
52
 
                        return 1;
53
 
                break;
54
 
#ifdef CONFIG_IPV6
55
 
        case AF_INET6:
56
 
                if (os_memcpy(&a->u.v6, &b->u.v6, sizeof(a->u.v6))
57
 
                    != 0)
58
 
                        return 1;
59
 
                break;
60
 
#endif /* CONFIG_IPV6 */
61
 
        }
62
 
 
63
 
        return 0;
64
 
}
65
 
 
66
 
 
67
 
int hostapd_parse_ip_addr(const char *txt, struct hostapd_ip_addr *addr)
68
 
{
69
 
#ifndef CONFIG_NATIVE_WINDOWS
70
 
        if (inet_aton(txt, &addr->u.v4)) {
71
 
                addr->af = AF_INET;
72
 
                return 0;
73
 
        }
74
 
 
75
 
#ifdef CONFIG_IPV6
76
 
        if (inet_pton(AF_INET6, txt, &addr->u.v6) > 0) {
77
 
                addr->af = AF_INET6;
78
 
                return 0;
79
 
        }
80
 
#endif /* CONFIG_IPV6 */
81
 
#endif /* CONFIG_NATIVE_WINDOWS */
82
 
 
83
 
        return -1;
84
 
}