1
/***************************************************************************
2
mymaster.cpp - description
5
copyright : (C) 2000 by
7
***************************************************************************/
9
/***************************************************************************
11
* This program is free software; you can redistribute it and/or modify *
12
* it under the terms of the GNU General Public License as published by *
13
* the Free Software Foundation; either version 2 of the License, or *
14
* (at your option) any later version. *
16
***************************************************************************/
17
#include <netinet/in.h>
18
#include <sys/socket.h>
19
#include <arpa/inet.h>
25
MyMaster::MyMaster (const QString & workgroup, QObject * parent):
32
MyMaster::~MyMaster ()
36
kdWarning (7199) << "MyMaster: Process not exited..." << endl;
42
/** Liest den Masterbrowser ein */
44
MyMaster::getMaster ()
46
proc = new KProcess ();
49
kdError (7199) << "MyMaster : Can't create a process." << endl;
52
(*proc) << "nmblookup" << "-M" << wg << "-S";
53
connect (proc, SIGNAL (processExited (KProcess *)), this,
54
SLOT (onProcExit (KProcess *)));
55
connect (proc, SIGNAL (receivedStdout (KProcess *, char *, int)), this,
56
SLOT (MyMasterStdout (KProcess *, char *, int)));
57
proc->start (KProcess::NotifyOnExit, KProcess::Stdout);
63
MyMaster::MyMasterStdout (KProcess *, char *buffer, int n)
65
out.append (QString::fromLocal8Bit (buffer, n));
68
/** Wird aufgerufen wenn der Process sich beendet */
70
MyMaster::onProcExit (KProcess * killedproc)
72
if (killedproc == proc)
78
kdWarning (7199) << "MyMaster : Mmmhhh... not my process" << endl;
82
i = s.find (wg + "<1d>"); // <1d> means ->Workgroup
89
s = s.right (s.length () - i - 1);
90
ip = htonl (inet_addr ((const char *) s.stripWhiteSpace ()));
92
// Find the Mastername
93
i = s.find ("<00>"); // <00> means ->Workstation
100
s = s.right (s.length () - i - 1);
101
s = s.stripWhiteSpace ();
106
emit isMasterName (s, wg, ip);
108
emit isExited (this);