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