You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
110 lines
3.8 KiB
110 lines
3.8 KiB
15 years ago
|
/* This file is part of the KDE libraries
|
||
|
Copyright (c) 1999 Waldo Bastian <bastian@kde.org>
|
||
|
|
||
|
This library is free software; you can redistribute it and/or
|
||
|
modify it under the terms of the GNU Library General Public
|
||
|
License version 2 as published by the Free Software Foundation.
|
||
|
|
||
|
This library is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
Library General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU Library General Public License
|
||
|
along with this library; see the file COPYING.LIB. If not, write to
|
||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
|
#include "kuniqueapplication.h"
|
||
|
#include "kglobal.h"
|
||
|
#include "kdebug.h"
|
||
|
#include "ksock.h"
|
||
|
#include "ksockaddr.h"
|
||
|
#include "kextsock.h"
|
||
|
|
||
|
#include <kaboutdata.h>
|
||
|
#include <kcmdlineargs.h>
|
||
|
#include <unistd.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <stdio.h>
|
||
|
#include <dirent.h>
|
||
|
#include <fcntl.h>
|
||
|
#include <sys/stat.h>
|
||
|
#include <sys/time.h>
|
||
|
#include <sys/types.h>
|
||
|
#include <sys/socket.h>
|
||
|
#include <arpa/inet.h>
|
||
|
#include <netdb.h>
|
||
|
|
||
15 years ago
|
bool check(TQString txt, TQString a, TQString b)
|
||
15 years ago
|
{
|
||
|
if (a.isEmpty())
|
||
15 years ago
|
a = TQString::null;
|
||
15 years ago
|
if (b.isEmpty())
|
||
15 years ago
|
b = TQString::null;
|
||
15 years ago
|
if (a == b) {
|
||
|
kdDebug() << txt << " : checking '" << a << "' against expected value '" << b << "'... " << "ok" << endl;
|
||
|
}
|
||
|
else {
|
||
|
kdDebug() << txt << " : checking '" << a << "' against expected value '" << b << "'... " << "KO !" << endl;
|
||
|
exit(1);
|
||
|
}
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
|
||
|
int
|
||
|
main(int argc, char *argv[])
|
||
|
{
|
||
|
KAboutData about("socktest", "SockTest", "version");
|
||
|
KCmdLineArgs::init(argc, argv, &about);
|
||
|
KApplication::addCmdLineOptions();
|
||
|
|
||
|
KApplication app;
|
||
|
|
||
15 years ago
|
TQString host, port;
|
||
15 years ago
|
|
||
|
KInetSocketAddress host_address("213.203.58.36", 80);
|
||
|
|
||
|
check("KInetSocketAddress(\"213.203.58.36\", 80)", host_address.pretty(), "213.203.58.36 port 80");
|
||
|
|
||
|
int result = KExtendedSocket::resolve(&host_address, host, port, NI_NAMEREQD);
|
||
|
printf( "resolve result: %d\n", result );
|
||
|
check("KExtendedSocket::resolve() host=", host, "www.kde.org");
|
||
|
// check("KExtendedSocket::resolve() port=", port, "http");
|
||
15 years ago
|
TQPtrList<KAddressInfo> list;
|
||
15 years ago
|
list = KExtendedSocket::lookup("www.kde.org", "http", KExtendedSocket::inetSocket);
|
||
|
for(KAddressInfo *info = list.first(); info; info = list.next())
|
||
|
{
|
||
|
qWarning("Lookup: %s %s %s", info->address()->pretty().latin1(),
|
||
|
info->address()->isEqual(KInetSocketAddress("213.203.58.36", 80)) ?
|
||
|
"is equal to" : "is NOT equal to",
|
||
|
"213.203.58.36 port 80");
|
||
|
}
|
||
|
check("KExtendedSocket::lookup()", list.first()->address()->pretty(), "213.203.58.36 port 80");
|
||
|
|
||
|
|
||
|
|
||
|
int err;
|
||
|
|
||
15 years ago
|
TQPtrList<KAddressInfo> cns = KExtendedSocket::lookup("www.kde.org", 0, KExtendedSocket::canonName, &err);
|
||
15 years ago
|
for (KAddressInfo *x = cns.first(); x; x = cns.next()) {
|
||
|
const char *canon = x->canonname();
|
||
|
qWarning( "Lookup: %s", canon ? canon : "<Null>");
|
||
|
}
|
||
|
check("KExtendedSocket::lookup() canonical", cns.first()->canonname(), "www.kde.org");
|
||
|
|
||
|
KExtendedSocket * sock2 = new KExtendedSocket( "www.kde.org", 80 );
|
||
15 years ago
|
check( "KExtendedSocket ctor / connect", TQString::number( sock2->connect() ), "0" );
|
||
15 years ago
|
|
||
|
printf("FD %d\n", sock2->fd());
|
||
|
|
||
|
KSocketAddress* addr = KExtendedSocket::peerAddress( sock2->fd() );
|
||
|
check( "peerAddress:", addr->nodeName().latin1(), "213.203.58.36" );
|
||
|
|
||
|
check( "isEqual:", addr->isEqual(KInetSocketAddress("213.203.58.36", 80)) ? "TRUE" : "FALSE", "TRUE");
|
||
|
check( "isEqual:", addr->isEqual(KInetSocketAddress("213.203.58.36", 8080)) ? "TRUE" : "FALSE", "FALSE");
|
||
|
check( "isEqual:", addr->isCoreEqual(KInetSocketAddress("213.203.58.36", 8080)) ? "TRUE" : "FALSE", "TRUE");
|
||
|
}
|