~ubuntu-branches/ubuntu/maverick/sflphone/maverick

« back to all changes in this revision

Viewing changes to sflphone-common/libs/pjproject/pjlib/src/pj/ip_helper_symbian.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Francois Marier
  • Date: 2010-06-03 15:59:46 UTC
  • Revision ID: james.westby@ubuntu.com-20100603155946-ybe8d8o8zx8lp0m8
Tags: upstream-0.9.8.3
ImportĀ upstreamĀ versionĀ 0.9.8.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Id: ip_helper_symbian.cpp 2394 2008-12-23 17:27:53Z bennylp $ */
 
2
/* 
 
3
 * Copyright (C) 2008-2009 Teluu Inc. (http://www.teluu.com)
 
4
 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
 
5
 *
 
6
 * This program is free software; you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation; either version 2 of the License, or
 
9
 * (at your option) any later version.
 
10
 *
 
11
 * This program is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with this program; if not, write to the Free Software
 
18
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
 
19
 *
 
20
 *  Additional permission under GNU GPL version 3 section 7:
 
21
 *
 
22
 *  If you modify this program, or any covered work, by linking or
 
23
 *  combining it with the OpenSSL project's OpenSSL library (or a
 
24
 *  modified version of that library), containing parts covered by the
 
25
 *  terms of the OpenSSL or SSLeay licenses, Teluu Inc. (http://www.teluu.com)
 
26
 *  grants you additional permission to convey the resulting work.
 
27
 *  Corresponding Source for a non-source form of such a combination
 
28
 *  shall include the source code for the parts of OpenSSL used as well
 
29
 *  as that of the covered work.
 
30
 */
 
31
#include <pj/ip_helper.h>
 
32
#include <pj/addr_resolv.h>
 
33
#include <pj/assert.h>
 
34
#include <pj/errno.h>
 
35
#include <pj/log.h>
 
36
#include <pj/string.h>
 
37
#include <pj/compat/socket.h>
 
38
 
 
39
 
 
40
#include "os_symbian.h"
 
41
 
 
42
#define THIS_FILE       "ip_helper_symbian.cpp"
 
43
#define TRACE_ME        0
 
44
 
 
45
static pj_status_t rsock_enum_interface(int af,
 
46
                                        unsigned *p_cnt,
 
47
                                        pj_sockaddr ifs[]) 
 
48
{
 
49
    TInt rc;
 
50
    RSocket rSock;
 
51
    TPckgBuf<TSoInetInterfaceInfo> info;
 
52
    unsigned i;
 
53
    
 
54
    if (PjSymbianOS::Instance()->Connection()) {
 
55
        
 
56
        rc = rSock.Open(PjSymbianOS::Instance()->SocketServ(), 
 
57
                        af, PJ_SOCK_DGRAM, KProtocolInetUdp,
 
58
                        *PjSymbianOS::Instance()->Connection());
 
59
    } else {
 
60
        
 
61
        rc = rSock.Open(PjSymbianOS::Instance()->SocketServ(), 
 
62
                        af, PJ_SOCK_DGRAM, KProtocolInetUdp);
 
63
                        
 
64
    }
 
65
        
 
66
    if (rc != KErrNone)
 
67
        return PJ_RETURN_OS_ERROR(rc);
 
68
    
 
69
    rSock.SetOpt(KSoInetEnumInterfaces, KSolInetIfCtrl);
 
70
    
 
71
    for (i=0; i<*p_cnt &&
 
72
                rSock.GetOpt(KSoInetNextInterface, KSolInetIfCtrl, 
 
73
                             info) == KErrNone; ) 
 
74
    {
 
75
        TInetAddr &iAddress = info().iAddress;
 
76
        int namelen;
 
77
 
 
78
#if TRACE_ME
 
79
                if (1) {
 
80
                        pj_sockaddr a;
 
81
                        char ipaddr[PJ_INET6_ADDRSTRLEN+2];
 
82
                        
 
83
                        namelen = sizeof(pj_sockaddr);
 
84
                        if (PjSymbianOS::Addr2pj(iAddress, a, &namelen, 
 
85
                                                                         PJ_FALSE) == PJ_SUCCESS) 
 
86
                        {
 
87
                                PJ_LOG(5,(THIS_FILE, "Enum: found address %s", 
 
88
                                                pj_sockaddr_print(&a, ipaddr, sizeof(ipaddr), 2)));
 
89
                        }
 
90
                }
 
91
#endif
 
92
        
 
93
        namelen = sizeof(ifs[i]);
 
94
        if (PjSymbianOS::Addr2pj(iAddress, ifs[i], &namelen, 
 
95
                                                         PJ_TRUE) != PJ_SUCCESS)
 
96
        {
 
97
            continue;
 
98
        }
 
99
 
 
100
        if (ifs[i].addr.sa_family != af)
 
101
                    continue;
 
102
        
 
103
        ++i;
 
104
    }
 
105
    
 
106
    rSock.Close();
 
107
    
 
108
    // Done
 
109
    *p_cnt = i;
 
110
    
 
111
    return PJ_SUCCESS;
 
112
}
 
113
                                        
 
114
/*
 
115
 * Enumerate the local IP interface currently active in the host.
 
116
 */
 
117
PJ_DEF(pj_status_t) pj_enum_ip_interface(int af,
 
118
                                         unsigned *p_cnt,
 
119
                                         pj_sockaddr ifs[])
 
120
{
 
121
    unsigned start;
 
122
    pj_status_t status = PJ_SUCCESS;
 
123
 
 
124
    start = 0;
 
125
            
 
126
    /* Get IPv6 interface first. */
 
127
    if (af==PJ_AF_INET6 || af==PJ_AF_UNSPEC) {
 
128
        unsigned max = *p_cnt;
 
129
        status = rsock_enum_interface(PJ_AF_INET6, &max, &ifs[start]);
 
130
        if (status == PJ_SUCCESS) {
 
131
            (*p_cnt) -= max;
 
132
            start += max;
 
133
        }
 
134
    }
 
135
    
 
136
    /* Get IPv4 interface. */
 
137
    if (af==PJ_AF_INET || af==PJ_AF_UNSPEC) {
 
138
        unsigned max = *p_cnt;
 
139
        status = rsock_enum_interface(PJ_AF_INET, &max, &ifs[start]);
 
140
        if (status == PJ_SUCCESS) {
 
141
            (*p_cnt) -= max;
 
142
            start += max;
 
143
        }
 
144
    }
 
145
    
 
146
    *p_cnt = start;
 
147
    
 
148
    return start ? PJ_SUCCESS : PJ_ENOTFOUND;
 
149
}
 
150
 
 
151
/*
 
152
 * Enumerate the IP routing table for this host.
 
153
 */
 
154
PJ_DEF(pj_status_t) pj_enum_ip_route(unsigned *p_cnt,
 
155
                                     pj_ip_route_entry routes[])
 
156
{
 
157
    PJ_ASSERT_RETURN(p_cnt && *p_cnt > 0 && routes, PJ_EINVAL);
 
158
    *p_cnt = 0;
 
159
    return PJ_ENOTSUP;
 
160
}
 
161