2 * radclient.c General radius packet debug tool.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 * Copyright 2000 The FreeRADIUS server project
21 * Copyright 2000 Miquel van Smoorenburg <miquels@cistron.nl>
22 * Copyright 2000 Alan DeKok <aland@ox.org>
24 static const char rcsid[] = "$Id$";
26 #include <freeradius-devel/autoconf.h>
39 #ifdef HAVE_SYS_SELECT_H
40 # include <sys/select.h>
49 #include <freeradius-devel/conf.h>
50 #include <freeradius-devel/radpaths.h>
51 #include <freeradius-devel/missing.h>
52 #include <freeradius-devel/libradius.h>
54 static int retries = 10;
55 static float timeout = 3;
56 static const char *secret = NULL;
57 static int do_output = 1;
58 static int totalapp = 0;
59 static int totaldeny = 0;
60 static int totallost = 0;
62 static int server_port = 0;
63 static int packet_code = 0;
64 static lrad_ipaddr_t server_ipaddr;
65 static int resend_count = 1;
69 static int radius_id[256];
70 static int last_used_id = -1;
72 static rbtree_t *filename_tree = NULL;
73 static rbtree_t *request_tree = NULL;
75 static int sleep_time = -1;
77 typedef struct radclient_t {
78 struct radclient_t *prev;
79 struct radclient_t *next;
82 int packet_number; /* in the file */
85 RADIUS_PACKET *request;
92 static radclient_t *radclient_head = NULL;
93 static radclient_t *radclient_tail = NULL;
96 static void NEVER_RETURNS usage(void)
98 fprintf(stderr, "Usage: radclient [options] server[:port] <command> [<secret>]\n");
100 fprintf(stderr, " <command> One of auth, acct, status, coa, or disconnect.\n");
101 fprintf(stderr, " -c count Send each packet 'count' times.\n");
102 fprintf(stderr, " -d raddb Set dictionary directory.\n");
103 fprintf(stderr, " -f file Read packets from file, not stdin.\n");
104 fprintf(stderr, " -i id Set request id to 'id'. Values may be 0..255\n");
105 fprintf(stderr, " -n num Send N requests/s\n");
106 fprintf(stderr, " -p num Send 'num' packets from a file in parallel.\n");
107 fprintf(stderr, " -q Do not print anything out.\n");
108 fprintf(stderr, " -r retries If timeout, retry sending the packet 'retries' times.\n");
109 fprintf(stderr, " -s Print out summary information of auth results.\n");
110 fprintf(stderr, " -S file read secret from file, not command line.\n");
111 fprintf(stderr, " -t timeout Wait 'timeout' seconds before retrying (may be a floating point number).\n");
112 fprintf(stderr, " -v Show program version information.\n");
113 fprintf(stderr, " -x Debugging mode.\n");
114 fprintf(stderr, " -4 Use IPv4 address of server\n");
115 fprintf(stderr, " -6 Use IPv6 address of server.\n");
121 * Free a radclient struct, which may (or may not)
122 * already be in the list.
124 static void radclient_free(radclient_t *radclient)
126 radclient_t *prev, *next;
128 if (radclient->request) rad_free(&radclient->request);
129 if (radclient->reply) rad_free(&radclient->reply);
131 prev = radclient->prev;
132 next = radclient->next;
135 assert(radclient_head != radclient);
137 } else if (radclient_head) {
138 assert(radclient_head == radclient);
139 radclient_head = next;
143 assert(radclient_tail != radclient);
145 } else if (radclient_tail) {
146 assert(radclient_tail == radclient);
147 radclient_tail = prev;
154 * Initialize a radclient data structure
156 static radclient_t *radclient_init(const char *filename)
160 radclient_t *start, *radclient, *prev = NULL;
162 int packet_number = 1;
165 assert(filename != NULL);
168 * Determine where to read the VP's from.
170 if (strcmp(filename, "-") != 0) {
171 fp = fopen(filename, "r");
173 fprintf(stderr, "radclient: Error opening %s: %s\n",
174 filename, strerror(errno));
182 * Loop until the file is done.
188 radclient = malloc(sizeof(*radclient));
190 perror("radclient: X");
191 return NULL; /* memory leak "start" */
193 memset(radclient, 0, sizeof(*radclient));
195 radclient->request = rad_alloc(1);
196 if (!radclient->request) {
197 librad_perror("radclient: Y");
198 radclient_free(radclient);
199 return NULL; /* memory leak "start" */
202 radclient->filename = filename;
203 radclient->request->id = -1; /* allocate when sending */
204 radclient->packet_number = packet_number++;
209 radclient->request->vps = readvp2(fp, &filedone, "radclient:");
210 if (!radclient->request->vps) {
211 radclient_free(radclient);
212 return start; /* done: return the list */
216 * Keep a copy of the the User-Password attribute.
218 if ((vp = pairfind(radclient->request->vps, PW_PASSWORD)) != NULL) {
219 strNcpy(radclient->password, vp->vp_strvalue,
220 sizeof(radclient->password));
222 * Otherwise keep a copy of the CHAP-Password attribute.
224 } else if ((vp = pairfind(radclient->request->vps, PW_CHAP_PASSWORD)) != NULL) {
225 strNcpy(radclient->password, vp->vp_strvalue,
226 sizeof(radclient->password));
228 radclient->password[0] = '\0';
232 * Fix up Digest-Attributes issues
234 for (vp = radclient->request->vps; vp != NULL; vp = vp->next) {
235 switch (vp->attribute) {
240 * Allow it to set the packet type in
241 * the attributes read from the file.
244 radclient->request->code = vp->lvalue;
247 case PW_PACKET_DST_PORT:
248 radclient->request->dst_port = (vp->lvalue & 0xffff);
251 case PW_PACKET_DST_IP_ADDRESS:
252 radclient->request->dst_ipaddr.af = AF_INET;
253 radclient->request->dst_ipaddr.ipaddr.ip4addr.s_addr = vp->lvalue;
256 case PW_PACKET_DST_IPV6_ADDRESS:
257 radclient->request->dst_ipaddr.af = AF_INET6;
258 radclient->request->dst_ipaddr.ipaddr.ip6addr = vp->vp_ipv6addr;
261 case PW_PACKET_SRC_PORT:
262 radclient->request->src_port = (vp->lvalue & 0xffff);
265 case PW_PACKET_SRC_IP_ADDRESS:
266 radclient->request->src_ipaddr.af = AF_INET;
267 radclient->request->src_ipaddr.ipaddr.ip4addr.s_addr = vp->lvalue;
270 case PW_PACKET_SRC_IPV6_ADDRESS:
271 radclient->request->src_ipaddr.af = AF_INET6;
272 radclient->request->src_ipaddr.ipaddr.ip6addr = vp->vp_ipv6addr;
275 case PW_DIGEST_REALM:
276 case PW_DIGEST_NONCE:
277 case PW_DIGEST_METHOD:
280 case PW_DIGEST_ALGORITHM:
281 case PW_DIGEST_BODY_DIGEST:
282 case PW_DIGEST_CNONCE:
283 case PW_DIGEST_NONCE_COUNT:
284 case PW_DIGEST_USER_NAME:
286 memmove(&vp->vp_octets[2], &vp->vp_octets[0],
288 vp->vp_octets[0] = vp->attribute - PW_DIGEST_REALM + 1;
290 vp->vp_octets[1] = vp->length;
291 vp->attribute = PW_DIGEST_ATTRIBUTES;
294 } /* loop over the VP's we read in */
300 prev->next = radclient;
301 radclient->prev = prev;
304 } while (!filedone); /* loop until the file is done. */
306 if (fp != stdin) fclose(fp);
316 * Sanity check each argument.
318 static int radclient_sane(radclient_t *radclient)
320 if (radclient->request->dst_port == 0) {
321 radclient->request->dst_port = server_port;
323 if (radclient->request->dst_ipaddr.af == AF_UNSPEC) {
324 if (server_ipaddr.af == AF_UNSPEC) {
325 fprintf(stderr, "radclient: No server was given, but request %d in file %s did not contain Packet-Dst-IP-Address\n",
326 radclient->packet_number, radclient->filename);
329 radclient->request->dst_ipaddr = server_ipaddr;
331 if (radclient->request->code == 0) {
332 if (packet_code == -1) {
333 fprintf(stderr, "radclient: Request was \"auto\", but request %d in file %s did not contain Packet-Type\n",
334 radclient->packet_number, radclient->filename);
338 radclient->request->code = packet_code;
340 radclient->request->sockfd = sockfd;
347 * For request handline.
349 static int filename_cmp(const void *one, const void *two)
351 return strcmp((const char *) one, (const char *) two);
354 static int filename_walk(void *context, void *data)
356 const char *filename = data;
357 radclient_t *radclient;
359 context = context; /* -Wunused */
362 * Initialize the request we're about
365 radclient = radclient_init(filename);
370 if (!radclient_head) {
371 assert(radclient_tail == NULL);
372 radclient_head = radclient;
374 assert(radclient_tail->next == NULL);
375 radclient_tail->next = radclient;
376 radclient->prev = radclient_tail;
380 * We may have had a list of "radclient" structures
383 while (radclient->next) radclient = radclient->next;
384 radclient_tail = radclient;
391 * Compare two RADIUS_PACKET data structures, based on a number
394 static int request_cmp(const void *one, const void *two)
397 const radclient_t *a = one;
398 const radclient_t *b = two;
401 * The following code looks unreasonable, but it's
402 * the only way to make the comparisons work.
404 if (a->request->id < b->request->id) return -1;
405 if (a->request->id > b->request->id) return +1;
407 if (a->request->dst_ipaddr.af < b->request->dst_ipaddr.af) return -1;
408 if (a->request->dst_ipaddr.af > b->request->dst_ipaddr.af) return +1;
410 switch (a->request->dst_ipaddr.af) {
412 rcode = memcmp(&a->request->dst_ipaddr.ipaddr.ip4addr,
413 &b->request->dst_ipaddr.ipaddr.ip4addr,
414 sizeof(a->request->dst_ipaddr.ipaddr.ip4addr));
417 rcode = memcmp(&a->request->dst_ipaddr.ipaddr.ip6addr,
418 &b->request->dst_ipaddr.ipaddr.ip6addr,
419 sizeof(a->request->dst_ipaddr.ipaddr.ip6addr));
421 default: /* FIXME: die! */
425 if (rcode != 0) return rcode;
427 if (a->request->dst_port < b->request->dst_port) return -1;
428 if (a->request->dst_port > b->request->dst_port) return +1;
431 * Everything's equal. Say so.
439 static void request_free(void *data)
441 radclient_t *radclient = (radclient_t *) data;
443 if (!radclient || !radclient->request ||
444 (radclient->request->id < 0)) {
449 * One more unused RADIUS ID.
451 radius_id[radclient->request->id] = 0;
452 radclient->request->id = -1;
455 * If we've already sent a packet, free up the old one,
456 * and ensure that the next packet has a unique
457 * authentication vector.
459 if (radclient->request->data) {
460 free(radclient->request->data);
461 radclient->request->data = NULL;
464 if (radclient->reply) rad_free(&radclient->reply);
468 static void print_hex(RADIUS_PACKET *packet)
472 if (!packet->data) return;
474 printf(" Code:\t\t%u\n", packet->data[0]);
475 printf(" Id:\t\t%u\n", packet->data[1]);
476 printf(" Length:\t%u\n", ((packet->data[2] << 8) |
478 printf(" Vector:\t");
479 for (i = 4; i < 20; i++) {
480 printf("%02x", packet->data[i]);
484 if (packet->data_len > 20) {
489 total = packet->data_len - 20;
490 ptr = packet->data + 20;
496 if (total < 2) { /* too short */
497 printf("%02x\n", *ptr);
501 if (ptr[1] > total) { /* too long */
502 for (i = 0; i < total; i++) {
503 printf("%02x ", ptr[i]);
508 printf("%02x %02x ", ptr[0], ptr[1]);
509 attrlen = ptr[1] - 2;
513 for (i = 0; i < attrlen; i++) {
514 if ((i > 0) && ((i & 0x0f) == 0x00))
516 printf("%02x ", ptr[i]);
517 if ((i & 0x0f) == 0x0f) printf("\n");
520 if ((attrlen & 0x0f) != 0x00) printf("\n");
532 static int send_one_packet(radclient_t *radclient)
536 assert(radclient->done == 0);
539 * Remember when we have to wake up, to re-send the
540 * request, of we didn't receive a response.
542 if ((sleep_time == -1) ||
543 (sleep_time > (int) timeout)) {
544 sleep_time = (int) timeout;
548 * Haven't sent the packet yet. Initialize it.
550 if (radclient->request->id == -1) {
553 assert(radclient->reply == NULL);
556 * Find a free packet Id
558 for (i = 0; i < 256; i++) {
559 if (radius_id[(last_used_id + i) & 0xff] == 0) {
560 last_used_id = (last_used_id + i) & 0xff;
561 radius_id[last_used_id] = 1;
562 radclient->request->id = last_used_id++;
569 * Didn't find a free packet ID, we're not done,
570 * we don't sleep, and we stop trying to process
579 assert(radclient->request->id != -1);
580 assert(radclient->request->data == NULL);
582 librad_md5_calc(radclient->request->vector, radclient->request->vector,
583 sizeof(radclient->request->vector));
586 * Update the password, so it can be encrypted with the
587 * new authentication vector.
589 if (radclient->password[0] != '\0') {
592 if ((vp = pairfind(radclient->request->vps, PW_PASSWORD)) != NULL) {
593 strNcpy(vp->vp_strvalue, radclient->password,
594 sizeof(vp->vp_strvalue));
595 vp->length = strlen(vp->vp_strvalue);
597 } else if ((vp = pairfind(radclient->request->vps, PW_CHAP_PASSWORD)) != NULL) {
599 * FIXME: AND there's no CHAP-Challenge,
600 * AND vp->length != 17
601 * AND rad_chap_encode() != vp->vp_octets
603 strNcpy(vp->vp_strvalue, radclient->password,
604 sizeof(vp->vp_strvalue));
605 vp->length = strlen(vp->vp_strvalue);
607 rad_chap_encode(radclient->request,
609 radclient->request->id, vp);
614 radclient->timestamp = time(NULL);
615 radclient->tries = 1;
619 * Duplicate found. Serious error!
621 if (rbtree_insert(request_tree, radclient) == 0) {
625 } else { /* radclient->request->id >= 0 */
626 time_t now = time(NULL);
629 * FIXME: Accounting packets are never retried!
630 * The Acct-Delay-Time attribute is updated to
631 * reflect the delay, and the packet is re-sent
636 * Not time for a retry, do so.
638 if ((now - radclient->timestamp) < timeout) {
640 * When we walk over the tree sending
641 * packets, we update the minimum time
644 if ((sleep_time == -1) ||
645 (sleep_time > (now - radclient->timestamp))) {
646 sleep_time = now - radclient->timestamp;
652 * We're not trying later, maybe the packet is done.
654 if (radclient->tries == retries) {
656 assert(radclient->request->id >= 0);
659 * Delete the request from the tree of
660 * outstanding requests.
662 node = rbtree_find(request_tree, radclient);
663 assert(node != NULL);
665 fprintf(stderr, "radclient: no response from server for ID %d\n", radclient->request->id);
666 rbtree_delete(request_tree, node);
669 * Normally we mark it "done" when we've received
670 * the response, but this is a special case.
672 if (radclient->resend == resend_count) {
680 * We are trying later.
682 radclient->timestamp = now;
690 if (rad_send(radclient->request, NULL, secret) < 0) {
691 fprintf(stderr, "radclient: Failed to send packet for ID %d: %s\n",
692 radclient->request->id, librad_errstr);
695 if (librad_debug > 2) print_hex(radclient->request);
701 * Receive one packet, maybe.
703 static int recv_one_packet(int wait_time)
707 radclient_t myclient, *radclient;
708 RADIUS_PACKET myrequest, *reply;
712 /* And wait for reply, timing out as necessary */
714 FD_SET(sockfd, &set);
716 if (wait_time <= 0) {
719 tv.tv_sec = wait_time;
724 * No packet was received.
726 if (select(sockfd + 1, &set, NULL, NULL, &tv) != 1) {
731 * Look for the packet.
733 reply = rad_recv(sockfd);
735 fprintf(stderr, "radclient: received bad packet: %s\n",
737 return -1; /* bad packet */
740 if (librad_debug > 2) print_hex(reply);
742 myclient.request = &myrequest;
743 myrequest.id = reply->id;
744 myrequest.dst_ipaddr = reply->src_ipaddr;
745 myrequest.dst_port = reply->src_port;
747 node = rbtree_find(request_tree, &myclient);
749 fprintf(stderr, "radclient: received response to request we did not send. (%d)\n", myrequest.id);
751 return -1; /* got reply to packet we didn't send */
754 radclient = rbtree_node2data(request_tree, node);
755 assert(radclient != NULL);
756 rbtree_delete(request_tree, node);
757 assert(radclient->request->id == -1);
758 assert(radclient->request->data == NULL);
760 assert(radclient->reply == NULL);
761 radclient->reply = reply;
764 * Fails the signature validation: not a real reply.
765 * FIXME: Silently drop it and listen for another packet.
767 if (rad_verify(reply, radclient->request, secret) < 0) {
768 librad_perror("rad_verify");
770 goto packet_done; /* shared secret is incorrect */
774 * If this fails, we're out of memory.
776 if (rad_decode(reply, radclient->request, secret) != 0) {
777 librad_perror("rad_decode");
782 /* libradius debug already prints out the value pairs for us */
783 if (!librad_debug && do_output) {
784 printf("Received response ID %d, code %d, length = %d\n",
785 reply->id, reply->code, reply->data_len);
786 vp_printlist(stdout, reply->vps);
788 if (reply->code != PW_AUTHENTICATION_REJECT) {
795 rad_free(&radclient->reply);
798 * Once we've sent the packet as many times as requested,
801 if (radclient->resend == resend_count) {
802 assert((node = rbtree_find(request_tree, radclient)) == NULL);
810 static int getport(const char *name)
814 svp = getservbyname (name, "udp");
819 return ntohs(svp->s_port);
822 int main(int argc, char **argv)
826 const char *radius_dir = RADDBDIR;
827 char filesecret[256];
833 int force_af = AF_UNSPEC;
837 filename_tree = rbtree_create(filename_cmp, NULL, 0);
838 if (!filename_tree) {
839 fprintf(stderr, "radclient: Out of memory\n");
843 request_tree = rbtree_create(request_cmp, request_free, 0);
845 fprintf(stderr, "radclient: Out of memory\n");
849 while ((c = getopt(argc, argv, "46c:d:f:hi:n:p:qr:sS:t:vx")) != EOF) switch(c) {
857 if (!isdigit((int) *optarg))
859 resend_count = atoi(optarg);
865 rbtree_insert(filename_tree, optarg);
868 if (!isdigit((int) *optarg))
870 last_used_id = atoi(optarg);
871 if ((last_used_id < 0) || (last_used_id > 255)) {
877 persec = atoi(optarg);
878 if (persec <= 0) usage();
882 parallel = atoi(optarg);
883 if (parallel <= 0) usage();
890 if (!isdigit((int) *optarg))
892 retries = atoi(optarg);
893 if ((retries == 0) || (retries > 1000)) usage();
899 fp = fopen(optarg, "r");
901 fprintf(stderr, "radclient: Error opening %s: %s\n",
902 optarg, strerror(errno));
905 if (fgets(filesecret, sizeof(filesecret), fp) == NULL) {
906 fprintf(stderr, "radclient: Error reading %s: %s\n",
907 optarg, strerror(errno));
912 /* truncate newline */
913 p = filesecret + strlen(filesecret) - 1;
914 while ((p >= filesecret) &&
920 if (strlen(filesecret) < 2) {
921 fprintf(stderr, "radclient: Secret in %s is too short\n", optarg);
927 if (!isdigit((int) *optarg))
929 timeout = atof(optarg);
932 printf("radclient: $Id$ built on " __DATE__ " at " __TIME__ "\n");
943 argc -= (optind - 1);
944 argv += (optind - 1);
947 ((secret == NULL) && (argc < 4))) {
951 if (dict_init(radius_dir, RADIUS_DICTIONARY) < 0) {
952 librad_perror("radclient");
959 server_ipaddr.af = force_af;
960 if (strcmp(argv[1], "-") != 0) {
961 const char *hostname = argv[1];
962 const char *portname = argv[1];
965 if (*argv[1] == '[') { /* IPv6 URL encoded */
966 p = strchr(argv[1], ']');
967 if ((p - argv[1]) >= sizeof(buffer)) {
971 memcpy(buffer, argv[1] + 1, p - argv[1] - 1);
972 buffer[p - argv[1] - 1] = '\0';
978 p = strchr(portname, ':');
979 if (p && (strchr(p + 1, ':') == NULL)) {
986 if (ip_hton(hostname, force_af, &server_ipaddr) < 0) {
987 fprintf(stderr, "radclient: Failed to find IP address for host %s: %s\n", hostname, strerror(errno));
992 * Strip port from hostname if needed.
994 if (portname) server_port = atoi(portname);
997 memset(radius_id, 0, sizeof(radius_id));
1000 * See what kind of request we want to send.
1002 if (strcmp(argv[2], "auth") == 0) {
1003 if (server_port == 0) server_port = getport("radius");
1004 if (server_port == 0) server_port = PW_AUTH_UDP_PORT;
1005 packet_code = PW_AUTHENTICATION_REQUEST;
1007 } else if (strcmp(argv[2], "challenge") == 0) {
1008 if (server_port == 0) server_port = getport("radius");
1009 if (server_port == 0) server_port = PW_AUTH_UDP_PORT;
1010 packet_code = PW_ACCESS_CHALLENGE;
1012 } else if (strcmp(argv[2], "acct") == 0) {
1013 if (server_port == 0) server_port = getport("radacct");
1014 if (server_port == 0) server_port = PW_ACCT_UDP_PORT;
1015 packet_code = PW_ACCOUNTING_REQUEST;
1018 } else if (strcmp(argv[2], "status") == 0) {
1019 if (server_port == 0) server_port = getport("radius");
1020 if (server_port == 0) server_port = PW_AUTH_UDP_PORT;
1021 packet_code = PW_STATUS_SERVER;
1023 } else if (strcmp(argv[2], "disconnect") == 0) {
1024 if (server_port == 0) server_port = PW_POD_UDP_PORT;
1025 packet_code = PW_DISCONNECT_REQUEST;
1027 } else if (strcmp(argv[2], "coa") == 0) {
1028 if (server_port == 0) server_port = PW_POD_UDP_PORT;
1029 packet_code = PW_COA_REQUEST;
1031 } else if (strcmp(argv[2], "auto") == 0) {
1034 } else if (isdigit((int) argv[2][0])) {
1035 if (server_port == 0) server_port = getport("radius");
1036 if (server_port == 0) server_port = PW_AUTH_UDP_PORT;
1037 packet_code = atoi(argv[2]);
1045 if (argv[3]) secret = argv[3];
1048 * If no '-f' is specified, we're reading from stdin.
1050 if (rbtree_num_elements(filename_tree) == 0) {
1051 rbtree_insert(filename_tree, "-");
1055 * Walk over the list of filenames, creating the requests.
1057 if (rbtree_walk(filename_tree, InOrder, filename_walk, NULL) != 0) {
1062 * No packets read. Die.
1064 if (!radclient_head) {
1065 fprintf(stderr, "radclient: Nothing to send.\n");
1070 * Bind to the first specified IP address and port.
1071 * This means we ignore later ones.
1073 if (radclient_head->request->src_ipaddr.af == AF_UNSPEC) {
1074 sockfd = lrad_socket(&server_ipaddr, 0);
1076 sockfd = lrad_socket(&radclient_head->request->src_ipaddr,
1077 radclient_head->request->src_port);
1080 fprintf(stderr, "radclient: socket: %s\n", librad_errstr);
1085 * Walk over the list of packets, sanity checking
1088 for (this = radclient_head; this != NULL; this = this->next) {
1089 if (radclient_sane(this) != 0) {
1094 if (last_used_id < 0) last_used_id = getpid() & 0xff;
1097 * Walk over the packets to send, until
1100 * FIXME: This currently busy-loops until it receives
1101 * all of the packets. It should really have some sort of
1102 * send packet, get time to wait, select for time, etc.
1108 const char *filename = NULL;
1114 * Walk over the packets, sending them.
1117 for (this = radclient_head; this != NULL; this = next) {
1121 * If there's a packet to receive,
1122 * receive it, but don't wait for a
1128 * This packet is done. Delete it.
1131 radclient_free(this);
1136 * Packets from multiple '-f' are sent
1139 * Packets from one file are sent in
1140 * series, unless '-p' is specified, in
1141 * which case N packets from each file
1142 * are sent in parallel.
1144 if (this->filename != filename) {
1145 filename = this->filename;
1153 * Send the current packet.
1155 send_one_packet(this);
1158 * Wait a little before sending
1159 * the next packet, if told to.
1165 * Don't sleep elsewhere.
1174 tv.tv_usec = 1000000/persec;
1178 * Sleep for milliseconds,
1181 * If we get an error or
1182 * a signal, treat it like
1185 select(0, NULL, NULL, NULL, &tv);
1189 * If we haven't sent this packet
1190 * often enough, we're not done,
1191 * and we shouldn't sleep.
1193 if (this->resend < resend_count) {
1197 } else { /* haven't sent this packet, we're not done */
1198 assert(this->done == 0);
1199 assert(this->reply == NULL);
1205 * Still have outstanding requests.
1207 if (rbtree_num_elements(request_tree) > 0) {
1214 * Nothing to do until we receive a request, so
1215 * sleep until then. Once we receive one packet,
1216 * we go back, and walk through the whole list again,
1217 * sending more packets (if necessary), and updating
1220 if (!done && (sleep_time > 0)) {
1221 recv_one_packet(sleep_time);
1225 rbtree_free(filename_tree);
1226 rbtree_free(request_tree);
1229 printf("\n\t Total approved auths: %d\n", totalapp);
1230 printf("\t Total denied auths: %d\n", totaldeny);
1231 printf("\t Total lost auths: %d\n", totallost);