]> rtime.felk.cvut.cz Git - socketcan-devel.git/blob - can-utils/cansniffer.c
Fixed contradiction in Sourcecode discalimer.
[socketcan-devel.git] / can-utils / cansniffer.c
1 /*
2  *  $Id$
3  */
4
5 /*
6  * can-sniffer.c
7  *
8  * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
9  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  * 3. Neither the name of Volkswagen nor the names of its contributors
20  *    may be used to endorse or promote products derived from this software
21  *    without specific prior written permission.
22  *
23  * Alternatively, provided that this notice is retained in full, this
24  * software may be distributed under the terms of the GNU General
25  * Public License ("GPL") version 2, in which case the provisions of the
26  * GPL apply INSTEAD OF those given above.
27  *
28  * The provided data structures and external interfaces from this code
29  * are not restricted to be used by modules with a GPL compatible license.
30  *
31  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
34  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
36  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
37  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
38  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
39  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
40  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
41  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
42  * DAMAGE.
43  *
44  * Send feedback to <socketcan-users@lists.berlios.de>
45  *
46  */
47
48 #include <stdio.h>
49 #include <stdlib.h>
50 #include <unistd.h>
51 #include <string.h>
52 #include <fcntl.h>
53 #include <signal.h>
54 #include <ctype.h>
55 #include <libgen.h>
56 #include <time.h>
57
58 #include <sys/time.h>
59 #include <sys/types.h>
60 #include <sys/stat.h>
61 #include <sys/socket.h>
62 #include <sys/ioctl.h>
63 #include <sys/uio.h>
64 #include <net/if.h>
65
66 #include <linux/can.h>
67 #include <linux/can/bcm.h>
68
69 #include "terminal.h"
70
71 #define U64_DATA(p) (*(unsigned long long*)(p)->data)
72
73 #define SETFNAME "sniffset."
74
75 /* flags */
76
77 #define ENABLE  1 /* by filter or user */
78 #define DISPLAY 2 /* is on the screen */
79 #define UPDATE  4 /* needs to be printed on the screen */
80 #define CLRSCR  8 /* clear screen in next loop */
81
82 /* flags testing & setting */
83
84 #define is_set(id, flag) (sniftab[id].flags & flag)
85 #define is_clr(id, flag) (!(sniftab[id].flags & flag))
86
87 #define do_set(id, flag) (sniftab[id].flags |= flag)
88 #define do_clr(id, flag) (sniftab[id].flags &= ~flag)
89
90 /* time defaults */
91
92 #define TIMEOUT 50 /* in 100ms */
93 #define HOLD    10 /* in 100ms */
94 #define LOOP     2 /* in 100ms */
95
96 #define MAXANI 8
97 const char anichar[MAXANI] = {'|', '/', '-', '\\', '|', '/', '-', '\\'};
98
99 #define ATTCOLOR ATTBOLD FGRED
100
101 #define STARTLINESTR "X  time    ID  data ... "
102
103 struct snif {
104     int flags;
105     long hold;
106     long timeout;
107     struct timeval laststamp;
108     struct timeval currstamp;
109     struct can_frame last;
110     struct can_frame current;
111     struct can_frame marker;
112     struct can_frame notch;
113 } sniftab[2048];
114
115
116 extern int optind, opterr, optopt;
117
118 static int running = 1;
119 static int clearscreen = 1;
120 static int notch = 0;
121 static long timeout = TIMEOUT;
122 static long hold = HOLD;
123 static long loop = LOOP;
124 static unsigned char binary = 0;
125 static unsigned char binary_gap = 0;
126 static unsigned char color  = 0;
127
128 void rx_setup (int fd, int id);
129 void rx_delete (int fd, int id);
130 void print_snifline(int id);
131 int handle_keyb(int fd);
132 int handle_bcm(int fd, long currcms);
133 int handle_timeo(int fd, long currcms);
134 void writesettings(char* name);
135 void readsettings(char* name, int sockfd);
136
137 void print_usage(char *prg)
138 {
139     const char manual [] = {
140         "commands that can be entered at runtime:\n"
141         "\n"
142         "q<ENTER>       - quit\n"
143         "b<ENTER>       - toggle binary / HEX-ASCII output\n"
144         "B<ENTER>       - toggle binary with gap / HEX-ASCII output (exceeds 80 chars!)\n"
145         "c<ENTER>       - toggle color mode\n"
146         "#<ENTER>       - notch currently marked/changed bits (can be used repeatedly)\n"
147         "*<ENTER>       - clear notched marked\n"
148         "rMYNAME<ENTER> - read settings file (filter/notch)\n"
149         "wMYNAME<ENTER> - write settings file (filter/notch)\n"
150         "+FILTER<ENTER> - add CAN-IDs to sniff\n"
151         "-FILTER<ENTER> - remove CAN-IDs to sniff\n"
152         "\n"
153         "FILTER can be a single CAN-ID or a CAN-ID/Bitmask:\n"
154         "+1F5<ENTER>    - add CAN-ID 0x1F5\n"
155         "-42E<ENTER>    - remove CAN-ID 0x42E\n"
156         "-42E7FF<ENTER> - remove CAN-ID 0x42E (using Bitmask)\n"
157         "-500700<ENTER> - remove CAN-IDs 0x500 - 0x5FF\n"
158         "+400600<ENTER> - add CAN-IDs 0x400 - 0x5FF\n"
159         "+000000<ENTER> - add all CAN-IDs\n"
160         "-000000<ENTER> - remove all CAN-IDs\n"
161         "\n"
162         "if (id & filter) == (sniff-id & filter) the action (+/-) is performed,\n"
163         "which is quite easy when the filter is 000\n"
164         "\n"
165     };
166
167     fprintf(stderr, "\nUsage: %s [can-interface]\n", prg);
168     fprintf(stderr, "Options: -m <mask>  (initial FILTER default 0x00000000)\n");
169     fprintf(stderr, "         -v <value> (initial FILTER default 0x00000000)\n");
170     fprintf(stderr, "         -q         (quiet - all IDs deactivated)\n");
171     fprintf(stderr, "         -r <name>  (read %sname from file)\n", SETFNAME);
172     fprintf(stderr, "         -b         (start with binary mode)\n");
173     fprintf(stderr, "         -B         (start with binary mode with gap - exceeds 80 chars!)\n");
174     fprintf(stderr, "         -c         (color changes)\n");
175     fprintf(stderr, "         -t <time>  (timeout for ID display [x100ms] default: %d)\n", TIMEOUT);
176     fprintf(stderr, "         -h <time>  (hold marker on changes [x100ms] default: %d)\n", HOLD);
177     fprintf(stderr, "         -l <time>  (loop time (display) [x100ms] default: %d)\n", LOOP);
178     fprintf(stderr, "\n");
179     fprintf(stderr, "%s", manual);
180 }
181
182 void sigterm(int signo)
183 {
184     running = 0;
185 }
186
187 int main(int argc, char **argv)
188 {
189     fd_set rdfs;
190     int s;
191     canid_t mask = 0;
192     canid_t value = 0;
193     long currcms = 0;
194     long lastcms = 0;
195     unsigned char quiet = 0;
196
197     int opt, ret;
198     struct timeval timeo, start_tv, tv;
199     struct sockaddr_can addr;
200     struct ifreq ifr;
201     int i;
202
203
204     signal(SIGTERM, sigterm);
205     signal(SIGHUP, sigterm);
206     signal(SIGINT, sigterm);
207
208     for (i=0; i < 2048 ;i++) /* default: check all CAN-IDs */
209         do_set(i, ENABLE);
210
211     while ((opt = getopt(argc, argv, "m:v:r:t:h:l:qbBc")) != -1) {
212         switch (opt) {
213         case 'm':
214             sscanf(optarg, "%x", &mask);
215             break;
216
217         case 'v':
218             sscanf(optarg, "%x", &value);
219             break;
220
221         case 'r':
222             readsettings(optarg, 0); /* no BCM-setting here */
223             break;
224
225         case 't':
226             sscanf(optarg, "%ld", &timeout);
227             break;
228
229         case 'h':
230             sscanf(optarg, "%ld", &hold);
231             break;
232
233         case 'l':
234             sscanf(optarg, "%ld", &loop);
235             break;
236
237         case 'q':
238             quiet = 1;
239             break;
240
241         case 'b':
242             binary = 1;
243             binary_gap = 0;
244             break;
245
246         case 'B':
247             binary = 1;
248             binary_gap = 1;
249             break;
250
251         case 'c':
252             color = 1;
253             break;
254
255         case '?':
256             break;
257
258         default:
259             fprintf(stderr, "Unknown option %c\n", opt);
260             break;
261         }
262     }
263
264     if (optind == argc) {
265         print_usage(basename(argv[0]));
266         exit(0);
267     }
268         
269     if (mask || value) {
270         for (i=0; i < 2048 ;i++) {
271             if ((i & mask) ==  (value & mask))
272                 do_set(i, ENABLE);
273             else
274                 do_clr(i, ENABLE);
275         }
276     }
277
278     if (quiet)
279         for (i=0; i < 2048 ;i++)
280             do_clr(i, ENABLE);
281
282     if (strlen(argv[optind]) >= IFNAMSIZ) {
283         printf("name of CAN device '%s' is too long!\n", argv[optind]);
284         return 1;
285     }
286
287     if ((s = socket(PF_CAN, SOCK_DGRAM, CAN_BCM)) < 0) {
288         perror("socket");
289         return 1;
290     }
291
292     addr.can_family = AF_CAN;
293     strcpy(ifr.ifr_name, argv[optind]);
294     ioctl(s, SIOCGIFINDEX, &ifr);
295     addr.can_ifindex = ifr.ifr_ifindex;
296
297     if (connect(s, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
298         perror("bind");
299         return 1;
300     }
301
302     for (i=0; i < 2048 ;i++) /* initial BCM setup */
303         if (is_set(i, ENABLE))
304             rx_setup(s, i);
305
306     gettimeofday(&start_tv, NULL);
307     tv.tv_sec = tv.tv_usec = 0;
308
309     printf("%s", CSR_HIDE); /* hide cursor */
310
311     while (running) {
312
313         FD_ZERO(&rdfs);
314         FD_SET(0, &rdfs);
315         FD_SET(s, &rdfs);
316
317         timeo.tv_sec  = 0;
318         timeo.tv_usec = 100000 * loop;
319
320         if ((ret = select(s+1, &rdfs, NULL, NULL, &timeo)) < 0) {
321             //perror("select");
322             running = 0;
323             continue;
324         }
325
326         gettimeofday(&tv, NULL);
327         currcms = (tv.tv_sec - start_tv.tv_sec) * 10 + (tv.tv_usec / 100000);
328
329         if (FD_ISSET(0, &rdfs))
330             running &= handle_keyb(s);
331
332         if (FD_ISSET(s, &rdfs))
333             running &= handle_bcm(s, currcms);
334
335         if (currcms - lastcms >= loop) {
336                 running &= handle_timeo(s, currcms);
337                 lastcms = currcms;
338         }
339     }
340
341     printf("%s", CSR_SHOW); /* show cursor */
342
343     close(s);
344     return 0;
345 }
346
347 void rx_setup (int fd, int id){
348
349     struct {
350         struct bcm_msg_head msg_head;
351         struct can_frame frame;
352     } txmsg;
353
354     txmsg.msg_head.opcode  = RX_SETUP;
355     txmsg.msg_head.can_id  = id;
356     txmsg.msg_head.flags   = RX_CHECK_DLC;
357     txmsg.msg_head.ival1.tv_sec  = 0;
358     txmsg.msg_head.ival1.tv_usec = 0;
359     txmsg.msg_head.ival2.tv_sec  = 0;
360     txmsg.msg_head.ival2.tv_usec = 0;
361     txmsg.msg_head.nframes = 1;
362     U64_DATA(&txmsg.frame) = (__u64) 0xFFFFFFFFFFFFFFFFULL;
363
364     if (write(fd, &txmsg, sizeof(txmsg)) < 0)
365       perror("write");
366 };
367
368 void rx_delete (int fd, int id){
369
370     struct bcm_msg_head msg_head;
371
372     msg_head.opcode  = RX_DELETE;
373     msg_head.can_id  = id;
374     msg_head.nframes = 0;
375
376     if (write(fd, &msg_head, sizeof(msg_head)) < 0)
377       perror("write");
378 }
379
380 int handle_keyb(int fd){
381
382     char cmd [20] = {0};
383     int i;
384     unsigned int mask;
385     unsigned int value;
386
387     if (read(0, cmd, 19) > strlen("+123456\n"))
388         return 1; /* ignore */
389
390     if (strlen(cmd) > 0)
391         cmd[strlen(cmd)-1] = 0; /* chop off trailing newline */
392
393     switch (cmd[0]) {
394
395     case '+':
396     case '-':
397         sscanf(&cmd[1], "%x", &value);
398         if (strlen(&cmd[1]) > 3) {
399             mask = value & 0xFFF;
400             value >>= 12;
401         }
402         else
403             mask = 0x7FF;
404
405         if (cmd[0] == '+') {
406             for (i=0; i < 2048 ;i++) {
407                 if (((i & mask) == (value & mask)) && (is_clr(i, ENABLE))) {
408                     do_set(i, ENABLE);
409                     rx_setup(fd, i);
410                 }
411             }
412         }
413         else { /* '-' */
414             for (i=0; i < 2048 ;i++) {
415                 if (((i & mask) == (value & mask)) && (is_set(i, ENABLE))) {
416                     do_clr(i, ENABLE);
417                     rx_delete(fd, i);
418                 }
419             }
420         }
421         break;
422
423     case 'w' :
424         writesettings(&cmd[1]);
425         break;
426
427     case 'r' :
428         readsettings(&cmd[1], fd);
429         break;
430
431     case 'q' :
432         running = 0;
433         break;
434
435     case 'B' :
436         binary_gap = 1;
437         if (binary)
438             binary = 0;
439         else
440             binary = 1;
441
442         break;
443
444     case 'b' :
445         binary_gap = 0;
446         if (binary)
447             binary = 0;
448         else
449             binary = 1;
450
451         break;
452
453     case 'c' :
454         if (color)
455             color = 0;
456         else
457             color = 1;
458
459         break;
460
461     case '#' :
462         notch = 1;
463         break;
464
465     case '*' :
466         for (i=0; i < 2048; i++)
467             U64_DATA(&sniftab[i].notch) = (__u64) 0;
468         break;
469
470     default:
471         break;
472     }
473
474     clearscreen = 1;
475
476     return 1; /* ok */
477 };
478
479 int handle_bcm(int fd, long currcms){
480
481     int nbytes, id;
482
483     struct {
484         struct bcm_msg_head msg_head;
485         struct can_frame frame;
486     } bmsg;
487
488     if ((nbytes = read(fd, &bmsg, sizeof(bmsg))) < 0) {
489         perror("bcm read");
490         return 0; /* quit */
491     }
492
493     id = bmsg.msg_head.can_id;
494     ioctl(fd, SIOCGSTAMP, &sniftab[id].currstamp);
495
496     if (bmsg.msg_head.opcode != RX_CHANGED) {
497         printf("received strange BCM opcode %d!\n", bmsg.msg_head.opcode);
498         return 0; /* quit */
499     }
500
501     if (nbytes != sizeof(bmsg)) {
502         printf("received strange BCM data length %d!\n", nbytes);
503         return 0; /* quit */
504     }
505
506     sniftab[id].current = bmsg.frame;
507     U64_DATA(&sniftab[id].marker) |= 
508         U64_DATA(&sniftab[id].current) ^ U64_DATA(&sniftab[id].last);
509     sniftab[id].timeout = currcms + timeout;
510
511     if (is_clr(id, DISPLAY))
512         clearscreen = 1; /* new entry -> new drawing */
513
514     do_set(id, DISPLAY);
515     do_set(id, UPDATE);
516         
517     return 1; /* ok */
518 };
519
520 int handle_timeo(int fd, long currcms){
521
522     int i;
523     int force_redraw = 0;
524
525     if (clearscreen) {
526         char startline[80];
527         printf("%s%s", CLR_SCREEN, CSR_HOME);
528         snprintf(startline, 79, "< can-sniffer parameters: l=%ld h=%ld t=%ld >", loop, hold, timeout);
529         printf("%s%*s",STARTLINESTR, 79-(int)strlen(STARTLINESTR), startline);
530         force_redraw = 1;
531         clearscreen = 0;
532     }
533
534     if (notch) {
535         for (i=0; i < 2048; i++)
536             U64_DATA(&sniftab[i].notch) |= U64_DATA(&sniftab[i].marker);
537         notch = 0;
538     }
539
540     printf("%s", CSR_HOME);
541     printf("%c\n", anichar[currcms % MAXANI]); /* funny animation */
542
543     for (i=0; i < 2048; i++) {
544
545         if is_set(i, ENABLE) {
546
547             if is_set(i, DISPLAY) {
548
549                 if (is_set(i, UPDATE) || (force_redraw)){
550                     print_snifline(i);
551                     sniftab[i].hold = currcms + hold;
552                     do_clr(i, UPDATE);
553                 }
554                 else
555                     if ((sniftab[i].hold) && (sniftab[i].hold < currcms)) {
556                         U64_DATA(&sniftab[i].marker) = (__u64) 0;
557                         print_snifline(i);
558                         sniftab[i].hold = 0; /* disable update by hold */
559                     }
560                     else
561                         printf("%s", CSR_DOWN); /* skip my line */
562
563                 if (sniftab[i].timeout < currcms) {
564                     do_clr(i, DISPLAY);
565                     do_clr(i, UPDATE);
566                     clearscreen = 1; /* removed entry -> new drawing next time */
567                 }
568             }
569             sniftab[i].last      = sniftab[i].current;
570             sniftab[i].laststamp = sniftab[i].currstamp;
571         }
572     }
573
574     return 1; /* ok */
575
576 };
577
578 void print_snifline(int id){
579
580     long diffsec  = sniftab[id].currstamp.tv_sec  - sniftab[id].laststamp.tv_sec;
581     long diffusec = sniftab[id].currstamp.tv_usec - sniftab[id].laststamp.tv_usec;
582     int dlc_diff  = sniftab[id].last.can_dlc - sniftab[id].current.can_dlc;
583     int i,j;
584
585     if (diffusec < 0)
586         diffsec--, diffusec += 1000000;
587
588     if (diffsec < 0)
589         diffsec = diffusec = 0;
590
591     if (diffsec > 10)
592         diffsec = 9, diffusec = 999999;
593
594     printf("%ld.%06ld  %3x  ", diffsec, diffusec, id);
595
596     if (binary) {
597
598         for (i=0; i<sniftab[id].current.can_dlc; i++) {
599             for (j=7; j>=0; j--) {
600                 if ((color) && (sniftab[id].marker.data[i] & 1<<j) &&
601                     (!(sniftab[id].notch.data[i] & 1<<j)))
602                     if (sniftab[id].current.data[i] & 1<<j)
603                         printf("%s1%s", ATTCOLOR, ATTRESET);
604                     else
605                         printf("%s0%s", ATTCOLOR, ATTRESET);
606                 else
607                     if (sniftab[id].current.data[i] & 1<<j)
608                         putchar('1');
609                     else
610                         putchar('0');
611             }
612             if (binary_gap)
613                 putchar(' ');
614         }
615
616         /*
617          * when the can_dlc decreased (dlc_diff > 0),
618          * we need to blank the former data printout
619          */
620         for (i=0; i<dlc_diff; i++) {
621             printf("        ");
622             if (binary_gap)
623                 putchar(' ');
624         }
625     }
626     else {
627
628         for (i=0; i<sniftab[id].current.can_dlc; i++)
629             if ((color) && (sniftab[id].marker.data[i]) && (!(sniftab[id].notch.data[i])))
630                 printf("%s%02X%s ", ATTCOLOR, sniftab[id].current.data[i], ATTRESET);
631             else
632                 printf("%02X ", sniftab[id].current.data[i]);
633
634         if (sniftab[id].current.can_dlc < 8)
635             printf("%*s", (8 - sniftab[id].current.can_dlc) * 3, "");
636
637         for (i=0; i<sniftab[id].current.can_dlc; i++)
638             if ((sniftab[id].current.data[i] > 0x1F) && 
639                 (sniftab[id].current.data[i] < 0x7F))
640                 if ((color) && (sniftab[id].marker.data[i]) && (!(sniftab[id].notch.data[i])))
641                     printf("%s%c%s", ATTCOLOR, sniftab[id].current.data[i], ATTRESET);
642                 else
643                     putchar(sniftab[id].current.data[i]);
644             else
645                 putchar('.');
646
647         /*
648          * when the can_dlc decreased (dlc_diff > 0),
649          * we need to blank the former data printout
650          */
651         for (i=0; i<dlc_diff; i++)
652             putchar(' ');
653     }
654
655     putchar('\n');
656
657     U64_DATA(&sniftab[id].marker) = (__u64) 0;
658
659 };
660
661
662 void writesettings(char* name){
663
664     int fd;
665     char fname[30] = SETFNAME;
666     int i,j;
667     char buf[8]= {0};
668
669     strncat(fname, name, 29 - strlen(fname)); 
670     fd = open(fname,  O_WRONLY|O_CREAT, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
671     
672     if (fd > 0) {
673
674         for (i=0; i < 2048 ;i++) {
675             sprintf(buf, "<%03X>%c.", i, (is_set(i, ENABLE))?'1':'0');
676             write(fd, buf, 7);
677             for (j=0; j<8 ; j++){
678                 sprintf(buf, "%02X", sniftab[i].notch.data[j]);
679                 write(fd, buf, 2);
680             }
681             write(fd, "\n", 1);
682             /* 7 + 16 + 1 = 24 bytes per entry */ 
683         }
684         close(fd);
685     }
686     else
687         printf("unable to write setting file '%s'!\n", fname);
688 };
689
690 void readsettings(char* name, int sockfd){
691
692     int fd;
693     char fname[30] = SETFNAME;
694     char buf[25] = {0};
695     int i,j;
696
697     strncat(fname, name, 29 - strlen(fname)); 
698     fd = open(fname, O_RDONLY);
699     
700     if (fd > 0) {
701         if (!sockfd)
702             printf("reading setting file '%s' ... ", fname);
703
704         for (i=0; i < 2048 ;i++) {
705             if (read(fd, &buf, 24) == 24) {
706                 if (buf[5] & 1) {
707                     if (is_clr(i, ENABLE)) {
708                         do_set(i, ENABLE);
709                         if (sockfd)
710                             rx_setup(sockfd, i);
711                     }
712                 }
713                 else
714                     if (is_set(i, ENABLE)) {
715                         do_clr(i, ENABLE);
716                         if (sockfd)
717                             rx_delete(sockfd, i);
718                     }
719                 for (j=7; j>=0 ; j--){
720                     sniftab[i].notch.data[j] =
721                         (__u8) strtoul(&buf[2*j+7], (char **)NULL, 16) & 0xFF;
722                     buf[2*j+7] = 0; /* cut off each time */
723                 }
724             }
725             else {
726                 if (!sockfd)
727                     printf("was only able to read until index %d from setting file '%s'!\n",
728                            i, fname);
729             }
730         }
731     
732         if (!sockfd)
733             printf("done\n");
734
735         close(fd);
736     }
737     else
738         printf("unable to read setting file '%s'!\n", fname);
739 };