\n");
390 | return -1;
391 | }
392 |
393 |
394 | /**
395 | * 主执行函数,解析传入参数,开始执行traceroute命令
396 | */
397 | int
398 | mainTracePath(int argc, char **argv)
399 | {
400 | struct hostent *he;
401 | int fd;
402 | int on;
403 | int ttl;
404 | char *p;
405 | int ch;
406 | #ifdef USE_IDN
407 | int rc;
408 | setlocale(LC_ALL, "");
409 | #endif
410 |
411 | //解析命令参数
412 | while ((ch = getopt(argc, argv, "nbh?l:m:p:")) != EOF) {
413 | switch(ch) {
414 | case 'n':
415 | no_resolve = 1;
416 | break;
417 | case 'b':
418 | show_both = 1;
419 | break;
420 | case 'l':
421 | if ((mtu = atoi(optarg)) <= overhead) {
422 | printf("Error: pktlen must be > %d and <= %d.\n",
423 | overhead, INT_MAX);
424 | return -1;
425 | }
426 | break;
427 | case 'm':
428 | max_hops = atoi(optarg);
429 | if (max_hops < 0 || max_hops > MAX_HOPS_LIMIT) {
430 | printf(
431 | "Error: max hops must be 0 .. %d (inclusive).\n",
432 | MAX_HOPS_LIMIT);
433 | }
434 | break;
435 | case 'p':
436 | base_port = atoi(optarg);
437 | break;
438 | default:
439 | return usage();
440 | break;
441 | }
442 | }
443 |
444 | //去掉所有的约束参数
445 | argc -= optind;
446 | argv += optind;
447 |
448 |
449 | if (argc != 1)
450 | return usage();
451 |
452 | fd = socket(AF_INET, SOCK_DGRAM, 0);
453 | if (fd < 0) {
454 | printf("socket: cant create socket");
455 | return -1;
456 | }
457 | target.sin_family = AF_INET;
458 |
459 | //获取制定的端口号
460 | /* Backward compatiblity */
461 | if (!base_port) {
462 | p = strchr(argv[0], '/');
463 | if (p) {
464 | *p = 0;
465 | base_port = atoi(p+1);
466 | } else
467 | base_port = 44444;
468 | }
469 |
470 | p = argv[0];
471 | #ifdef USE_IDN
472 | rc = idna_to_ascii_lz(argv[0], &p, 0);
473 | if (rc != IDNA_SUCCESS) {
474 | printf("IDNA encoding failed: %s\n", idna_strerror(rc));
475 | return -2;
476 | }
477 | #endif
478 |
479 | he = gethostbyname(p);
480 | if (he == NULL) {
481 | printf("gethostbyname: cant get host from hostname");
482 | return -1;
483 | }
484 |
485 | #ifdef USE_IDN
486 | free(p);
487 | #endif
488 |
489 | memcpy(&target.sin_addr, he->h_addr, 4);
490 |
491 | on = IP_PMTUDISC_PROBE;
492 | if (setsockopt(fd, SOL_IP, IP_MTU_DISCOVER, &on, sizeof(on)) &&
493 | (on = IP_PMTUDISC_DO,
494 | setsockopt(fd, SOL_IP, IP_MTU_DISCOVER, &on, sizeof(on)))) {
495 | printf("IP_MTU_DISCOVER error");
496 | return -1;
497 | }
498 | on = 1;
499 | if (setsockopt(fd, SOL_IP, IP_RECVERR, &on, sizeof(on))) {
500 | printf("IP_RECVERR error");
501 | return -1;
502 | }
503 | if (setsockopt(fd, SOL_IP, IP_RECVTTL, &on, sizeof(on))) {
504 | printf("IP_RECVTTL error");
505 | return -1;
506 | }
507 |
508 | pktbuf = malloc(mtu);
509 | if (!pktbuf) {
510 | printf("malloc pktbuf error");
511 | return -1;
512 | }
513 |
514 | //连续发送max_hops去traceroute
515 | int timeoutTTL = 0;
516 | for (ttl = 1; ttl <= max_hops; ttl++) {
517 | int res;
518 | int i;
519 |
520 | on = ttl;
521 | if (setsockopt(fd, SOL_IP, IP_TTL, &on, sizeof(on))) {
522 | printf("IP_TTL error");
523 | return -1;
524 | }
525 |
526 | restart:
527 | //每一条尝试三次发送
528 | for (i=0; i<1; i++) {
529 | int old_mtu;
530 |
531 | old_mtu = mtu;
532 | res = probe_ttl(fd, ttl);
533 | if (mtu != old_mtu)
534 | goto restart;
535 | if (res == 0)
536 | goto done;
537 | if (res > 0){
538 | timeoutTTL = 0;
539 | break;
540 | }
541 | }
542 |
543 | if (res < 0){
544 | if(timeoutTTL >= 3){
545 | return 0;
546 | }else {
547 | timeoutTTL++;
548 | printf("%2d: **********", ttl);
549 | }
550 | }
551 | }
552 | printf(" Too many hops: pmtu %d\n", mtu);
553 | done:
554 | printf(" Resume: pmtu %d ", mtu);
555 | if (hops_to>=0)
556 | printf("hops %d ", hops_to);
557 | if (hops_from>=0)
558 | printf("back %d ", hops_from);
559 | printf("\n");
560 |
561 | return 0;
562 | }
563 |
--------------------------------------------------------------------------------
/LDNetDiagnoService_Android/libs/armeabi/libtracepath.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Lede-Inc/LDNetDiagnoService_Android/3306576a682a0024d6e500ee2f955634ce4c4e0f/LDNetDiagnoService_Android/libs/armeabi/libtracepath.so
--------------------------------------------------------------------------------
/LDNetDiagnoService_Android/libs/mips/libtracepath.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Lede-Inc/LDNetDiagnoService_Android/3306576a682a0024d6e500ee2f955634ce4c4e0f/LDNetDiagnoService_Android/libs/mips/libtracepath.so
--------------------------------------------------------------------------------
/LDNetDiagnoService_Android/libs/x86/libtracepath.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Lede-Inc/LDNetDiagnoService_Android/3306576a682a0024d6e500ee2f955634ce4c4e0f/LDNetDiagnoService_Android/libs/x86/libtracepath.so
--------------------------------------------------------------------------------
/LDNetDiagnoService_Android/proguard-project.txt:
--------------------------------------------------------------------------------
1 | # To enable ProGuard in your project, edit project.properties
2 | # to define the proguard.config property as described in that file.
3 | #
4 | # Add project specific ProGuard rules here.
5 | # By default, the flags in this file are appended to flags specified
6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt
7 | # You can edit the include path and order by changing the ProGuard
8 | # include property in project.properties.
9 | #
10 | # For more details, see
11 | # http://developer.android.com/guide/developing/tools/proguard.html
12 |
13 | # Add any project specific keep options here:
14 |
15 | # If your project uses WebView with JS, uncomment the following
16 | # and specify the fully qualified class name to the JavaScript interface
17 | # class:
18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19 | # public *;
20 | #}
21 |
--------------------------------------------------------------------------------
/LDNetDiagnoService_Android/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system edit
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 | #
10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12 |
13 | # Project target.
14 | target=android-17
15 | android.library=true
16 |
--------------------------------------------------------------------------------
/LDNetDiagnoService_Android/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Lede-Inc/LDNetDiagnoService_Android/3306576a682a0024d6e500ee2f955634ce4c4e0f/LDNetDiagnoService_Android/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/LDNetDiagnoService_Android/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Lede-Inc/LDNetDiagnoService_Android/3306576a682a0024d6e500ee2f955634ce4c4e0f/LDNetDiagnoService_Android/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/LDNetDiagnoService_Android/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Lede-Inc/LDNetDiagnoService_Android/3306576a682a0024d6e500ee2f955634ce4c4e0f/LDNetDiagnoService_Android/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/LDNetDiagnoService_Android/res/values-v11/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/LDNetDiagnoService_Android/res/values-v14/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/LDNetDiagnoService_Android/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | LDNetDiagnoService_Android
4 |
5 |
6 |
--------------------------------------------------------------------------------
/LDNetDiagnoService_Android/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
14 |
15 |
16 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/LDNetDiagnoService_Android/src/com/netease/LDNetDiagnoService/LDNetAsyncTaskEx.java:
--------------------------------------------------------------------------------
1 | package com.netease.LDNetDiagnoService;
2 |
3 | import java.util.concurrent.Callable;
4 | import java.util.concurrent.CancellationException;
5 | import java.util.concurrent.ExecutionException;
6 | import java.util.concurrent.FutureTask;
7 | import java.util.concurrent.ThreadPoolExecutor;
8 |
9 | import android.os.AsyncTask;
10 | import android.os.Handler;
11 | import android.os.Message;
12 |
13 | /**
14 | *
15 | * @author liujie
16 | *
17 | *
18 | * The most part is copied for {@link AsyncTask}.
19 | *
20 | * What's we do here is to control the executor and the core
21 | *
22 | * number of thread parallely.
23 | *
24 | *
25 | * Since Starting with HONEYCOMB, tasks are executed on a single thread
26 | *
27 | * to avoid common application errors caused by parallel execution.
28 | */
29 |
30 | public abstract class LDNetAsyncTaskEx {
31 | private static final int MESSAGE_POST_RESULT = 0x1;
32 | private static final int MESSAGE_POST_PROGRESS = 0x2;
33 | private static final int MESSAGE_POST_CANCEL = 0x3;
34 |
35 | private volatile Status mStatus = Status.PENDING;
36 |
37 | public enum Status {
38 | PENDING, RUNNING, FINISHED,
39 | }
40 |
41 | private static final LDNetInternalHandler sHandler = new LDNetInternalHandler();
42 | private final LDNetWorkerRunnable mWorker;
43 | private final FutureTask mFuture;
44 |
45 | // protected Hashtable mTaskCache = new
46 | // Hashtable();
47 |
48 | public LDNetAsyncTaskEx() {
49 | mWorker = new LDNetWorkerRunnable() {
50 | public Result call() throws Exception {
51 | // Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
52 | return doInBackground(mParams);
53 | }
54 | };
55 |
56 | mFuture = new FutureTask(mWorker) {
57 | @SuppressWarnings("unchecked")
58 | @Override
59 | protected void done() {
60 | Message message;
61 | Result result = null;
62 |
63 | try {
64 | result = get();
65 | } catch (InterruptedException e) {
66 | android.util.Log.w(this.getClass().getSimpleName(), e);
67 | } catch (ExecutionException e) {
68 | throw new RuntimeException(
69 | "An error occured while executing doInBackground()",
70 | e.getCause());
71 | } catch (CancellationException e) {
72 | message = sHandler.obtainMessage(MESSAGE_POST_CANCEL,
73 | new LDNetAsyncTaskResult(LDNetAsyncTaskEx.this,
74 | (Result[]) null));
75 | message.sendToTarget();
76 | return;
77 | } catch (Throwable t) {
78 | throw new RuntimeException(
79 | "An error occured while executing "
80 | + "doInBackground()", t);
81 | }
82 |
83 | message = sHandler.obtainMessage(MESSAGE_POST_RESULT,
84 | new LDNetAsyncTaskResult(LDNetAsyncTaskEx.this, result));
85 | message.sendToTarget();
86 | }
87 | };
88 | }
89 |
90 | private static class LDNetInternalHandler extends Handler {
91 | @SuppressWarnings({ "rawtypes", "unchecked" })
92 | @Override
93 | public void handleMessage(Message msg) {
94 | LDNetAsyncTaskResult result = (LDNetAsyncTaskResult) msg.obj;
95 | switch (msg.what) {
96 | case MESSAGE_POST_RESULT:
97 | // There is only one result
98 | result.mTask.finish(result.mData[0]);
99 | break;
100 | case MESSAGE_POST_PROGRESS:
101 | result.mTask.onProgressUpdate(result.mData);
102 | break;
103 | case MESSAGE_POST_CANCEL:
104 | result.mTask.onCancelled();
105 | break;
106 | }
107 | }
108 | }
109 |
110 | public final Status getStatus() {
111 | return mStatus;
112 | }
113 |
114 | protected abstract Result doInBackground(Params... params);
115 | /**
116 | * 后台线程准备运行阶段
117 | */
118 | protected void onPreExecute() {
119 | }
120 |
121 | /**
122 | * 后台运行阶段,当前运行已经结束
123 | * @param result
124 | */
125 | protected void onPostExecute(Result result) {
126 | }
127 |
128 | /**
129 | * 进度更新阶段
130 | * @param values
131 | */
132 | protected void onProgressUpdate(Progress... values) {
133 | }
134 |
135 | /**
136 | * 取消运行
137 | */
138 | protected void onCancelled() {
139 | }
140 |
141 | public final boolean isCancelled() {
142 | return mFuture.isCancelled();
143 | }
144 |
145 | public final boolean cancel(boolean mayInterruptIfRunning) {
146 | return mFuture.cancel(mayInterruptIfRunning);
147 | }
148 |
149 | /**
150 | * 初始化运行阶段
151 | * @param params
152 | * @return
153 | */
154 | @SuppressWarnings("incomplete-switch")
155 | public final LDNetAsyncTaskEx execute(Params... params) {
156 | if (mStatus != Status.PENDING) {
157 | switch (mStatus) {
158 | case RUNNING:
159 | throw new IllegalStateException("Cannot execute task:"
160 | + " the task is already running.");
161 | case FINISHED:
162 | throw new IllegalStateException("Cannot execute task:"
163 | + " the task has already been executed "
164 | + "(a task can be executed only once)");
165 | }
166 | }
167 |
168 | mStatus = Status.RUNNING;
169 |
170 | onPreExecute();
171 |
172 | mWorker.mParams = params;
173 | ThreadPoolExecutor sExecutor = getThreadPoolExecutor();
174 | // ThreadPoolExecutor sExecutor = new ThreadPoolExecutor(CORE_POOL_SIZE,
175 | // MAXIMUM_POOL_SIZE, KEEP_ALIVE, TimeUnit.SECONDS, sWorkQueue,
176 | // sThreadFactory);
177 | if (sExecutor != null) {
178 | sExecutor.execute(mFuture);
179 | return this;
180 | } else {
181 | return null;
182 | }
183 | }
184 |
185 | protected abstract ThreadPoolExecutor getThreadPoolExecutor();
186 |
187 | protected final void publishProgress(Progress... values) {
188 | sHandler.obtainMessage(MESSAGE_POST_PROGRESS,
189 | new LDNetAsyncTaskResult