Ignore:
Timestamp:
Nov 1, 2006 1:57:01 PM (17 years ago)
Author:
bennylp
Message:

Ported all projects (except pjmedia-codec) on Symbian. PJMEDIA's sound device is still in progress

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/branches/symbian/pjlib/src/pj/addr_resolv_symbian.cpp

    r788 r791  
    2020#include <pj/assert.h> 
    2121#include <pj/errno.h> 
     22#include <pj/string.h> 
    2223#include <pj/unicode.h> 
    2324 
     
    7879} 
    7980 
     81 
     82/* Resolve the IP address of local machine */ 
     83pj_status_t pj_gethostip(pj_in_addr *addr) 
     84{ 
     85    const pj_str_t *hostname = pj_gethostname(); 
     86    struct pj_hostent he; 
     87    pj_str_t cp; 
     88    pj_in_addr loopip; 
     89    pj_status_t status; 
     90 
     91    cp = pj_str("127.0.0.1"); 
     92    loopip = pj_inet_addr(&cp); 
     93 
     94    /* Try with resolving local hostname first */ 
     95    status = pj_gethostbyname(hostname, &he); 
     96    if (status == PJ_SUCCESS) { 
     97        *addr = *(pj_in_addr*)he.h_addr; 
     98    } 
     99 
     100 
     101    /* If we end up with 127.0.0.1 or 0.0.0.0, resolve the IP by getting  
     102     * the default interface to connect to some public host. 
     103     */ 
     104    if (status!=PJ_SUCCESS || addr->s_addr == loopip.s_addr || !addr->s_addr) { 
     105        pj_sock_t fd; 
     106        pj_sockaddr_in a; 
     107        int len; 
     108 
     109        status = pj_sock_socket(PJ_AF_INET, PJ_SOCK_DGRAM, 0, &fd); 
     110        if (status != PJ_SUCCESS) { 
     111            return status; 
     112        } 
     113 
     114        cp = pj_str("1.1.1.1"); 
     115        pj_sockaddr_in_init(&a, &cp, 53); 
     116 
     117        status = pj_sock_connect(fd, &a, sizeof(a)); 
     118        if (status != PJ_SUCCESS) { 
     119            pj_sock_close(fd); 
     120            return status; 
     121        } 
     122 
     123        len = sizeof(a); 
     124        status = pj_sock_getsockname(fd, &a, &len); 
     125        if (status != PJ_SUCCESS) { 
     126            pj_sock_close(fd); 
     127            return status; 
     128        } 
     129 
     130        pj_sock_close(fd); 
     131         
     132        *addr = a.sin_addr; 
     133 
     134        if (a.sin_addr.s_addr == 0) 
     135            return PJ_ENOTFOUND; 
     136    } 
     137 
     138    return status; 
     139} 
     140 
     141 
     142 
Note: See TracChangeset for help on using the changeset viewer.