1
/* $Id: ip_helper_symbian.cpp 3553 2011-05-05 06:14:19Z nanang $ */
3
* Copyright (C) 2008-2011 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
#include <pj/ip_helper.h>
21
#include <pj/addr_resolv.h>
22
#include <pj/assert.h>
25
#include <pj/string.h>
26
#include <pj/compat/socket.h>
29
#include "os_symbian.h"
31
#define THIS_FILE "ip_helper_symbian.cpp"
34
static pj_status_t rsock_enum_interface(int af,
40
TPckgBuf<TSoInetInterfaceInfo> info;
43
if (PjSymbianOS::Instance()->Connection()) {
45
rc = rSock.Open(PjSymbianOS::Instance()->SocketServ(),
46
af, PJ_SOCK_DGRAM, KProtocolInetUdp,
47
*PjSymbianOS::Instance()->Connection());
50
rc = rSock.Open(PjSymbianOS::Instance()->SocketServ(),
51
af, PJ_SOCK_DGRAM, KProtocolInetUdp);
56
return PJ_RETURN_OS_ERROR(rc);
58
rSock.SetOpt(KSoInetEnumInterfaces, KSolInetIfCtrl);
61
rSock.GetOpt(KSoInetNextInterface, KSolInetIfCtrl,
64
TInetAddr &iAddress = info().iAddress;
70
char ipaddr[PJ_INET6_ADDRSTRLEN+2];
72
namelen = sizeof(pj_sockaddr);
73
if (PjSymbianOS::Addr2pj(iAddress, a, &namelen,
74
PJ_FALSE) == PJ_SUCCESS)
76
PJ_LOG(5,(THIS_FILE, "Enum: found address %s",
77
pj_sockaddr_print(&a, ipaddr, sizeof(ipaddr), 2)));
82
namelen = sizeof(ifs[i]);
83
if (PjSymbianOS::Addr2pj(iAddress, ifs[i], &namelen,
84
PJ_TRUE) != PJ_SUCCESS)
89
if (ifs[i].addr.sa_family != af)
104
* Enumerate the local IP interface currently active in the host.
106
PJ_DEF(pj_status_t) pj_enum_ip_interface(int af,
111
pj_status_t status = PJ_SUCCESS;
115
/* Get IPv6 interface first. */
116
if (af==PJ_AF_INET6 || af==PJ_AF_UNSPEC) {
117
unsigned max = *p_cnt;
118
status = rsock_enum_interface(PJ_AF_INET6, &max, &ifs[start]);
119
if (status == PJ_SUCCESS) {
125
/* Get IPv4 interface. */
126
if (af==PJ_AF_INET || af==PJ_AF_UNSPEC) {
127
unsigned max = *p_cnt;
128
status = rsock_enum_interface(PJ_AF_INET, &max, &ifs[start]);
129
if (status == PJ_SUCCESS) {
137
return start ? PJ_SUCCESS : PJ_ENOTFOUND;
141
* Enumerate the IP routing table for this host.
143
PJ_DEF(pj_status_t) pj_enum_ip_route(unsigned *p_cnt,
144
pj_ip_route_entry routes[])
146
PJ_ASSERT_RETURN(p_cnt && *p_cnt > 0 && routes, PJ_EINVAL);