~ubuntu-branches/ubuntu/lucid/havp/lucid

« back to all changes in this revision

Viewing changes to havp/sockethandler.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Andres Rodriguez
  • Date: 2010-02-10 15:46:22 UTC
  • mfrom: (1.1.9 upstream) (2.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20100210154622-qovsa7xbpa84nwtf
Tags: 0.91-1.1ubuntu1
* Merge from debian testing (LP: #487776), remaining changes:
  - Under certain circumstances, the init script and/or postrm script
    will fail to umount loop-back devices. This issue has been addressed
    by performing a lazy umount in these two scripts. 
* debian/havp.init: Fixes "Fails to restart because of mounted
  '/var/spool/havp'" Thanks to Imre Gergely for the fix. (LP: #401048)
* 05_include_libraries.dpatch: Dropped. Fixed in upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
482
482
    if ( domainT == "" ) return false;
483
483
    if ( portT < 1 || portT > 65536 ) return false;
484
484
 
485
 
    domainT = domainT.substr(0, 250);
 
485
    int domlen = domainT.length();
 
486
 
 
487
    if (domlen > 250) domainT = domainT.substr(0, 250);
486
488
    my_s_addr.sin_port = htons(portT);
487
489
 
488
490
    //IP?
489
 
    if ( inet_aton( domainT.c_str(), &ip_addr ) != 0 )
 
491
    if ( domlen >= 7 && domlen <= 15 && domainT.find_first_not_of("0123456789.") == string::npos )
490
492
    {
491
 
        my_s_addr.sin_addr = ip_addr;
 
493
        LastHost = "";
 
494
        if ( inet_aton( domainT.c_str(), &my_s_addr.sin_addr ) != 0 ) return true;
 
495
        return false;
 
496
    }
492
497
 
493
 
        return true;
494
 
    }
495
498
    //Same host as last time, use next IP
496
 
    else if ( LastHost == domainT )
 
499
    if ( server && LastHost == domainT )
497
500
    {
 
501
        if ( ips == 1 ) return true;
 
502
 
498
503
        if ( ++ip_count == ips ) ip_count = 0;
499
 
 
500
 
        memcpy(&my_s_addr.sin_addr, server->h_addr_list[ip_count], server->h_length);
 
504
        memcpy((char *) &my_s_addr.sin_addr.s_addr, server->h_addr_list[ip_count], server->h_length);
501
505
 
502
506
        return true;
503
507
    }
 
508
 
504
509
    //Resolve host
505
 
    else if ( (server = gethostbyname( domainT.c_str() )) )
 
510
    if ( (server = gethostbyname( domainT.c_str() )) )
506
511
    {
507
512
        //Count IPs
508
 
        for ( ips = 0; server->h_addr_list[ips] != NULL && ips != 16; ips++ );
 
513
        for ( ips = 0; server->h_addr_list[ips] != NULL && server->h_addrtype == AF_INET && ips != 16; ips++ );
509
514
 
510
515
        if ( !ips ) return false;
511
516
 
512
 
        memcpy(&my_s_addr.sin_addr, server->h_addr_list[0], server->h_length);
 
517
        memcpy((char *) &my_s_addr.sin_addr.s_addr, server->h_addr_list[0], server->h_length);
513
518
 
514
519
        ip_count = 0;
515
520
        LastHost = domainT;
517
522
        return true;
518
523
    }
519
524
 
 
525
    LastHost = "";
520
526
    return false;
521
527
}
522
528