1
/* $Id: ip_helper_symbian.cpp 2394 2008-12-23 17:27:53Z bennylp $ */
3
* Copyright (C) 2008-2009 Teluu Inc. (http://www.teluu.com)
4
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
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.
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.
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
20
* Additional permission under GNU GPL version 3 section 7:
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.
31
#include <pj/ip_helper.h>
32
#include <pj/addr_resolv.h>
33
#include <pj/assert.h>
36
#include <pj/string.h>
37
#include <pj/compat/socket.h>
40
#include "os_symbian.h"
42
#define THIS_FILE "ip_helper_symbian.cpp"
45
static pj_status_t rsock_enum_interface(int af,
51
TPckgBuf<TSoInetInterfaceInfo> info;
54
if (PjSymbianOS::Instance()->Connection()) {
56
rc = rSock.Open(PjSymbianOS::Instance()->SocketServ(),
57
af, PJ_SOCK_DGRAM, KProtocolInetUdp,
58
*PjSymbianOS::Instance()->Connection());
61
rc = rSock.Open(PjSymbianOS::Instance()->SocketServ(),
62
af, PJ_SOCK_DGRAM, KProtocolInetUdp);
67
return PJ_RETURN_OS_ERROR(rc);
69
rSock.SetOpt(KSoInetEnumInterfaces, KSolInetIfCtrl);
72
rSock.GetOpt(KSoInetNextInterface, KSolInetIfCtrl,
75
TInetAddr &iAddress = info().iAddress;
81
char ipaddr[PJ_INET6_ADDRSTRLEN+2];
83
namelen = sizeof(pj_sockaddr);
84
if (PjSymbianOS::Addr2pj(iAddress, a, &namelen,
85
PJ_FALSE) == PJ_SUCCESS)
87
PJ_LOG(5,(THIS_FILE, "Enum: found address %s",
88
pj_sockaddr_print(&a, ipaddr, sizeof(ipaddr), 2)));
93
namelen = sizeof(ifs[i]);
94
if (PjSymbianOS::Addr2pj(iAddress, ifs[i], &namelen,
95
PJ_TRUE) != PJ_SUCCESS)
100
if (ifs[i].addr.sa_family != af)
115
* Enumerate the local IP interface currently active in the host.
117
PJ_DEF(pj_status_t) pj_enum_ip_interface(int af,
122
pj_status_t status = PJ_SUCCESS;
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) {
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) {
148
return start ? PJ_SUCCESS : PJ_ENOTFOUND;
152
* Enumerate the IP routing table for this host.
154
PJ_DEF(pj_status_t) pj_enum_ip_route(unsigned *p_cnt,
155
pj_ip_route_entry routes[])
157
PJ_ASSERT_RETURN(p_cnt && *p_cnt > 0 && routes, PJ_EINVAL);