-rw-r--r-- | noncore/net/opie-smb/qsmb.cpp | 77 |
1 files changed, 39 insertions, 38 deletions
diff --git a/noncore/net/opie-smb/qsmb.cpp b/noncore/net/opie-smb/qsmb.cpp index 8aa4987..d6d1b23 100644 --- a/noncore/net/opie-smb/qsmb.cpp +++ b/noncore/net/opie-smb/qsmb.cpp | |||
@@ -5,4 +5,5 @@ | |||
5 | #include <string.h> | 5 | #include <string.h> |
6 | #include <qstring.h> | 6 | #include <qstring.h> |
7 | #include <qstringlist.h> | ||
7 | #include <qdir.h> | 8 | #include <qdir.h> |
8 | #include <qfileinfo.h> | 9 | #include <qfileinfo.h> |
@@ -23,4 +24,10 @@ | |||
23 | 24 | ||
24 | 25 | ||
26 | #include <netinet/in.h> | ||
27 | #include <arpa/inet.h> | ||
28 | |||
29 | #include <rpc/clnt.h> | ||
30 | |||
31 | |||
25 | #include <opie2/odebug.h> | 32 | #include <opie2/odebug.h> |
26 | using namespace Opie::Core; | 33 | using namespace Opie::Core; |
@@ -93,5 +100,6 @@ void Qsmb::scan() | |||
93 | scanning = true; | 100 | scanning = true; |
94 | 101 | ||
95 | char match[512], lmhosts[512]; | 102 | QString match; |
103 | char lmhosts[512]; | ||
96 | QString cmd; | 104 | QString cmd; |
97 | char result[256]; | 105 | char result[256]; |
@@ -102,20 +110,11 @@ void Qsmb::scan() | |||
102 | qApp->processEvents(); | 110 | qApp->processEvents(); |
103 | 111 | ||
104 | cmd = "ifconfig |grep 'addr:'|awk '{print $2}'|awk 'BEGIN{FS=\":\"}{print $2}'|sed 's/\\.[0-9]*$//'|head -n1"; | 112 | sockaddr_in my_addr; |
113 | get_myaddress( &my_addr); | ||
105 | 114 | ||
106 | owarn << "cmd: " << cmd << oendl; | 115 | QString ip = inet_ntoa( my_addr.sin_addr); |
116 | owarn << "IP Address : " << ip<< oendl; | ||
107 | 117 | ||
108 | /* run findsmb & read output */ | 118 | match = ip.left(5); |
109 | if ((pipe = popen(cmd.latin1(), "r")) == NULL) { | ||
110 | snprintf(result, 256, "Error: Can't run %s", cmd.latin1()); | ||
111 | TextViewOutput->append(result); | ||
112 | return; | ||
113 | } | ||
114 | while(fgets(result, 256, pipe) != NULL) { | ||
115 | strcpy( match, result); | ||
116 | match[5]='\0'; | ||
117 | break; | ||
118 | } | ||
119 | owarn << "match: " << match << oendl; | ||
120 | 119 | ||
121 | cmd = "smbfind"; | 120 | cmd = "smbfind"; |
@@ -144,5 +143,5 @@ void Qsmb::scan() | |||
144 | TextViewOutput->append(result); | 143 | TextViewOutput->append(result); |
145 | 144 | ||
146 | if( strstr(result, match) != NULL ) { | 145 | if( strstr(result, match.latin1()) != NULL ) { |
147 | char ip_addr[256], host[256], *ptr1; | 146 | char ip_addr[256], host[256], *ptr1; |
148 | 147 | ||
@@ -284,4 +283,5 @@ void Qsmb::DoIt() | |||
284 | 283 | ||
285 | int i; | 284 | int i; |
285 | bool err = false; | ||
286 | 286 | ||
287 | char share[512]; | 287 | char share[512]; |
@@ -299,17 +299,24 @@ void Qsmb::DoIt() | |||
299 | 299 | ||
300 | if(! QFileInfo(text).exists()) { | 300 | if(! QFileInfo(text).exists()) { |
301 | cmd = "mkdir -p "+ text; | 301 | // /* make sure mount exists! */ |
302 | owarn<<"cmd: "<< cmd << oendl; | 302 | |
303 | /* make sure mount exists! */ | 303 | // cmd = "mkdir -p "+ text; |
304 | if ((pipe2 = popen(cmd.latin1(), "r")) == NULL) { | 304 | // owarn<<"cmd: "<< cmd << oendl; |
305 | snprintf(result, 256, "Error: Can't run %s", cmd.latin1()); | 305 | // if ((pipe2 = popen(cmd.latin1(), "r")) == NULL) { |
306 | // result = "Error: Can't run " + cmd; | 306 | // snprintf(result, 256, "Error: Can't run %s", cmd.latin1()); |
307 | TextViewOutput->append(result); | 307 | // TextViewOutput->append(result); |
308 | return; | 308 | // return; |
309 | } | 309 | // } |
310 | while(fgets(result, 256, pipe2) != NULL) { | 310 | // while(fgets(result, 256, pipe2) != NULL) { |
311 | /* put result into TextViewOutput */ | 311 | // /* put result into TextViewOutput */ |
312 | TextViewOutput->append(result); | 312 | // TextViewOutput->append(result); |
313 | } | 313 | // } |
314 | QStringList ccmd; | ||
315 | ccmd << "mkdir"; | ||
316 | ccmd << "-p"; | ||
317 | ccmd << text; | ||
318 | |||
319 | owarn<<"cmd: "<< ccmd << oendl; | ||
320 | runCommand(ccmd); | ||
314 | } | 321 | } |
315 | 322 | ||
@@ -333,26 +340,18 @@ void Qsmb::DoIt() | |||
333 | owarn << "Saving Setting permanently..." << oendl; | 340 | owarn << "Saving Setting permanently..." << oendl; |
334 | cmd2 = "echo '" + cmd + "'>/opt/QtPalmtop/etc/samba.env"; | 341 | cmd2 = "echo '" + cmd + "'>/opt/QtPalmtop/etc/samba.env"; |
335 | |||
336 | /* run command & read output */ | 342 | /* run command & read output */ |
337 | if ((pipe = popen(cmd2.latin1(), "r")) == NULL) { | 343 | if ((pipe = popen(cmd2.latin1(), "r")) == NULL) { |
338 | |||
339 | snprintf(result, 256, "Error: Can't run %s", cmd.latin1()); | 344 | snprintf(result, 256, "Error: Can't run %s", cmd.latin1()); |
340 | // result = "Error: Can't run "+ cmd; | ||
341 | //TextViewOutput->append(result); | ||
342 | return; | 345 | return; |
343 | } | 346 | } |
344 | /* parse output and display in ListViewScan */ | 347 | /* parse output and display in ListViewScan */ |
345 | while(fgets(result, 256, pipe) != NULL) { | 348 | while(fgets(result, 256, pipe) != NULL) { |
346 | /* put result into TextViewOutput */ | ||
347 | //TextViewOutput->append(result); | ||
348 | } | 349 | } |
349 | } | 350 | } |
350 | 351 | ||
352 | |||
351 | /* run command & read output */ | 353 | /* run command & read output */ |
352 | if ((pipe = popen(cmd.latin1(), "r")) == NULL) { | 354 | if ((pipe = popen(cmd.latin1(), "r")) == NULL) { |
353 | |||
354 | // result = "Error: Can't run "+ cmd; | ||
355 | snprintf(result, 256, "Error: Can't run %s", cmd.latin1()); | 355 | snprintf(result, 256, "Error: Can't run %s", cmd.latin1()); |
356 | |||
357 | TextViewOutput->append(result); | 356 | TextViewOutput->append(result); |
358 | return; | 357 | return; |
@@ -364,4 +363,6 @@ void Qsmb::DoIt() | |||
364 | TextViewOutput->append(result); | 363 | TextViewOutput->append(result); |
365 | } | 364 | } |
365 | |||
366 | |||
366 | TextViewOutput->append("\n\n================CheckMounts==================\n"); | 367 | TextViewOutput->append("\n\n================CheckMounts==================\n"); |
367 | LScan->setText(""); | 368 | LScan->setText(""); |