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,2006 The FreeRADIUS server project
21 * Copyright 2000 Miquel van Smoorenburg <miquels@cistron.nl>
22 * Copyright 2000 Alan DeKok <aland@ox.org>
25 #include <freeradius-devel/ident.h>
28 #include <freeradius-devel/libradius.h>
29 #include <freeradius-devel/conf.h>
30 #include <freeradius-devel/radpaths.h>
40 static int retries = 10;
41 static float timeout = 3;
42 static const char *secret = NULL;
43 static int do_output = 1;
44 static int totalapp = 0;
45 static int totaldeny = 0;
46 static int totallost = 0;
48 static int server_port = 0;
49 static int packet_code = 0;
50 static fr_ipaddr_t server_ipaddr;
51 static int resend_count = 1;
53 static int print_filename = 0;
55 static fr_ipaddr_t client_ipaddr;
56 static int client_port = 0;
59 static int last_used_id = -1;
61 static rbtree_t *filename_tree = NULL;
62 static fr_packet_list_t *pl = NULL;
64 static int sleep_time = -1;
66 typedef struct radclient_t {
67 struct radclient_t *prev;
68 struct radclient_t *next;
71 int packet_number; /* in the file */
74 RADIUS_PACKET *request;
81 static radclient_t *radclient_head = NULL;
82 static radclient_t *radclient_tail = NULL;
85 static void NEVER_RETURNS usage(void)
87 fprintf(stderr, "Usage: radclient [options] server[:port] <command> [<secret>]\n");
89 fprintf(stderr, " <command> One of auth, acct, status, coa, or disconnect.\n");
90 fprintf(stderr, " -c count Send each packet 'count' times.\n");
91 fprintf(stderr, " -d raddb Set dictionary directory.\n");
92 fprintf(stderr, " -f file Read packets from file, not stdin.\n");
93 fprintf(stderr, " -i id Set request id to 'id'. Values may be 0..255\n");
94 fprintf(stderr, " -n num Send N requests/s\n");
95 fprintf(stderr, " -p num Send 'num' packets from a file in parallel.\n");
96 fprintf(stderr, " -q Do not print anything out.\n");
97 fprintf(stderr, " -r retries If timeout, retry sending the packet 'retries' times.\n");
98 fprintf(stderr, " -s Print out summary information of auth results.\n");
99 fprintf(stderr, " -S file read secret from file, not command line.\n");
100 fprintf(stderr, " -t timeout Wait 'timeout' seconds before retrying (may be a floating point number).\n");
101 fprintf(stderr, " -v Show program version information.\n");
102 fprintf(stderr, " -x Debugging mode.\n");
103 fprintf(stderr, " -4 Use IPv4 address of server\n");
104 fprintf(stderr, " -6 Use IPv6 address of server.\n");
110 * Free a radclient struct, which may (or may not)
111 * already be in the list.
113 static void radclient_free(radclient_t *radclient)
115 radclient_t *prev, *next;
117 if (radclient->request) rad_free(&radclient->request);
118 if (radclient->reply) rad_free(&radclient->reply);
120 prev = radclient->prev;
121 next = radclient->next;
124 assert(radclient_head != radclient);
126 } else if (radclient_head) {
127 assert(radclient_head == radclient);
128 radclient_head = next;
132 assert(radclient_tail != radclient);
134 } else if (radclient_tail) {
135 assert(radclient_tail == radclient);
136 radclient_tail = prev;
143 * Initialize a radclient data structure
145 static radclient_t *radclient_init(const char *filename)
149 radclient_t *start, *radclient, *prev = NULL;
151 int packet_number = 1;
154 assert(filename != NULL);
157 * Determine where to read the VP's from.
159 if (strcmp(filename, "-") != 0) {
160 fp = fopen(filename, "r");
162 fprintf(stderr, "radclient: Error opening %s: %s\n",
163 filename, strerror(errno));
171 * Loop until the file is done.
177 radclient = malloc(sizeof(*radclient));
179 perror("radclient: X");
180 if (fp != stdin) fclose(fp);
181 return NULL; /* memory leak "start" */
183 memset(radclient, 0, sizeof(*radclient));
185 radclient->request = rad_alloc(1);
186 if (!radclient->request) {
187 fr_perror("radclient: Y");
188 radclient_free(radclient);
189 if (fp != stdin) fclose(fp);
190 return NULL; /* memory leak "start" */
193 radclient->filename = filename;
194 radclient->request->id = -1; /* allocate when sending */
195 radclient->packet_number = packet_number++;
200 radclient->request->vps = readvp2(fp, &filedone, "radclient:");
201 if (!radclient->request->vps) {
202 radclient_free(radclient);
203 if (fp != stdin) fclose(fp);
204 return start; /* done: return the list */
208 * Keep a copy of the the User-Password attribute.
210 if ((vp = pairfind(radclient->request->vps, PW_USER_PASSWORD)) != NULL) {
211 strlcpy(radclient->password, vp->vp_strvalue,
212 sizeof(radclient->password));
214 * Otherwise keep a copy of the CHAP-Password attribute.
216 } else if ((vp = pairfind(radclient->request->vps, PW_CHAP_PASSWORD)) != NULL) {
217 strlcpy(radclient->password, vp->vp_strvalue,
218 sizeof(radclient->password));
220 radclient->password[0] = '\0';
224 * Fix up Digest-Attributes issues
226 for (vp = radclient->request->vps; vp != NULL; vp = vp->next) {
227 switch (vp->attribute) {
232 * Allow it to set the packet type in
233 * the attributes read from the file.
236 radclient->request->code = vp->vp_integer;
239 case PW_PACKET_DST_PORT:
240 radclient->request->dst_port = (vp->vp_integer & 0xffff);
243 case PW_PACKET_DST_IP_ADDRESS:
244 radclient->request->dst_ipaddr.af = AF_INET;
245 radclient->request->dst_ipaddr.ipaddr.ip4addr.s_addr = vp->vp_ipaddr;
248 case PW_PACKET_DST_IPV6_ADDRESS:
249 radclient->request->dst_ipaddr.af = AF_INET6;
250 radclient->request->dst_ipaddr.ipaddr.ip6addr = vp->vp_ipv6addr;
253 case PW_PACKET_SRC_PORT:
254 radclient->request->src_port = (vp->vp_integer & 0xffff);
257 case PW_PACKET_SRC_IP_ADDRESS:
258 radclient->request->src_ipaddr.af = AF_INET;
259 radclient->request->src_ipaddr.ipaddr.ip4addr.s_addr = vp->vp_ipaddr;
262 case PW_PACKET_SRC_IPV6_ADDRESS:
263 radclient->request->src_ipaddr.af = AF_INET6;
264 radclient->request->src_ipaddr.ipaddr.ip6addr = vp->vp_ipv6addr;
267 case PW_DIGEST_REALM:
268 case PW_DIGEST_NONCE:
269 case PW_DIGEST_METHOD:
272 case PW_DIGEST_ALGORITHM:
273 case PW_DIGEST_BODY_DIGEST:
274 case PW_DIGEST_CNONCE:
275 case PW_DIGEST_NONCE_COUNT:
276 case PW_DIGEST_USER_NAME:
278 memmove(&vp->vp_octets[2], &vp->vp_octets[0],
280 vp->vp_octets[0] = vp->attribute - PW_DIGEST_REALM + 1;
282 vp->vp_octets[1] = vp->length;
283 vp->attribute = PW_DIGEST_ATTRIBUTES;
286 } /* loop over the VP's we read in */
292 prev->next = radclient;
293 radclient->prev = prev;
296 } while (!filedone); /* loop until the file is done. */
298 if (fp != stdin) fclose(fp);
308 * Sanity check each argument.
310 static int radclient_sane(radclient_t *radclient)
312 if (radclient->request->dst_port == 0) {
313 radclient->request->dst_port = server_port;
315 if (radclient->request->dst_ipaddr.af == AF_UNSPEC) {
316 if (server_ipaddr.af == AF_UNSPEC) {
317 fprintf(stderr, "radclient: No server was given, but request %d in file %s did not contain Packet-Dst-IP-Address\n",
318 radclient->packet_number, radclient->filename);
321 radclient->request->dst_ipaddr = server_ipaddr;
323 if (radclient->request->code == 0) {
324 if (packet_code == -1) {
325 fprintf(stderr, "radclient: Request was \"auto\", but request %d in file %s did not contain Packet-Type\n",
326 radclient->packet_number, radclient->filename);
330 radclient->request->code = packet_code;
332 radclient->request->sockfd = -1;
339 * For request handline.
341 static int filename_cmp(const void *one, const void *two)
343 return strcmp((const char *) one, (const char *) two);
346 static int filename_walk(void *context, void *data)
348 const char *filename = data;
349 radclient_t *radclient;
351 context = context; /* -Wunused */
354 * Initialize the request we're about
357 radclient = radclient_init(filename);
362 if (!radclient_head) {
363 assert(radclient_tail == NULL);
364 radclient_head = radclient;
366 assert(radclient_tail->next == NULL);
367 radclient_tail->next = radclient;
368 radclient->prev = radclient_tail;
372 * We may have had a list of "radclient" structures
375 while (radclient->next) radclient = radclient->next;
376 radclient_tail = radclient;
383 * Deallocate packet ID, etc.
385 static void deallocate_id(radclient_t *radclient)
387 if (!radclient || !radclient->request ||
388 (radclient->request->id < 0)) {
393 * One more unused RADIUS ID.
395 fr_packet_list_id_free(pl, radclient->request);
396 radclient->request->id = -1;
399 * If we've already sent a packet, free up the old one,
400 * and ensure that the next packet has a unique
401 * authentication vector.
403 if (radclient->request->data) {
404 free(radclient->request->data);
405 radclient->request->data = NULL;
408 if (radclient->reply) rad_free(&radclient->reply);
412 static void print_hex(RADIUS_PACKET *packet)
416 if (!packet->data) return;
418 printf(" Code:\t\t%u\n", packet->data[0]);
419 printf(" Id:\t\t%u\n", packet->data[1]);
420 printf(" Length:\t%u\n", ((packet->data[2] << 8) |
422 printf(" Vector:\t");
423 for (i = 4; i < 20; i++) {
424 printf("%02x", packet->data[i]);
428 if (packet->data_len > 20) {
433 total = packet->data_len - 20;
434 ptr = packet->data + 20;
437 int attrlen, vsa = 0;
441 if (total < 2) { /* too short */
442 printf("%02x\n", *ptr);
446 if (ptr[1] > total) { /* too long */
447 for (i = 0; i < total; i++) {
448 printf("%02x ", ptr[i]);
453 if (ptr[0] == PW_VENDOR_SPECIFIC) vsa = 1;
455 printf("%02x %02x ", ptr[0], ptr[1]);
456 attrlen = ptr[1] - 2;
460 if (vsa && (attrlen > 4)) {
461 int vendor, vsa_tlen, vsa_llen;
465 vendor = ((ptr[0] << 24) | (ptr[1] << 16) |
466 (ptr[2] << 8) | ptr[3]);
467 dv = dict_vendorbyvalue(vendor);
468 vsa_tlen = vsa_llen = 1;
471 vsa_llen = dv->length;
474 printf("%02x%02x%02x%02x ",
475 ptr[0], ptr[1], ptr[2], ptr[3]);
480 if (attrlen >= (vsa_tlen + vsa_llen)) {
481 for (i = 0; i < vsa_tlen; i++) {
482 printf("%02x", ptr[i]);
489 for (i = 0; i < vsa_llen; i++) {
490 printf("%02x", ptr[i]);
498 printf("\n\t\t\t\t");
501 for (i = 0; i < attrlen; i++) {
502 if ((i > 0) && ((i & mask) == 0x00)) {
504 if (mask == 7) printf("\t");
506 printf("%02x ", ptr[i]);
507 if ((i & mask) == mask) printf("\n");
510 if ((attrlen & mask) != 0x00) printf("\n");
522 static int send_one_packet(radclient_t *radclient)
524 assert(radclient->done == 0);
527 * Remember when we have to wake up, to re-send the
528 * request, of we didn't receive a response.
530 if ((sleep_time == -1) ||
531 (sleep_time > (int) timeout)) {
532 sleep_time = (int) timeout;
536 * Haven't sent the packet yet. Initialize it.
538 if (radclient->request->id == -1) {
541 assert(radclient->reply == NULL);
544 * Didn't find a free packet ID, we're not done,
545 * we don't sleep, and we stop trying to process
549 rcode = fr_packet_list_id_alloc(pl, radclient->request);
553 mysockfd = fr_socket(&client_ipaddr, 0);
555 fprintf(stderr, "radclient: Can't open new socket\n");
558 if (!fr_packet_list_socket_add(pl, mysockfd)) {
559 fprintf(stderr, "radclient: Can't add new socket\n");
571 assert(radclient->request->id != -1);
572 assert(radclient->request->data == NULL);
574 for (i = 0; i < 4; i++) {
575 ((uint32_t *) radclient->request->vector)[i] = fr_rand();
579 * Update the password, so it can be encrypted with the
580 * new authentication vector.
582 if (radclient->password[0] != '\0') {
585 if ((vp = pairfind(radclient->request->vps, PW_USER_PASSWORD)) != NULL) {
586 strlcpy(vp->vp_strvalue, radclient->password,
587 sizeof(vp->vp_strvalue));
588 vp->length = strlen(vp->vp_strvalue);
590 } else if ((vp = pairfind(radclient->request->vps, PW_CHAP_PASSWORD)) != NULL) {
592 * FIXME: AND there's no CHAP-Challenge,
593 * AND vp->length != 17
594 * AND rad_chap_encode() != vp->vp_octets
596 strlcpy(vp->vp_strvalue, radclient->password,
597 sizeof(vp->vp_strvalue));
598 vp->length = strlen(vp->vp_strvalue);
600 rad_chap_encode(radclient->request,
602 radclient->request->id, vp);
607 radclient->timestamp = time(NULL);
608 radclient->tries = 1;
612 * Duplicate found. Serious error!
614 if (!fr_packet_list_insert(pl, &radclient->request)) {
618 } else { /* radclient->request->id >= 0 */
619 time_t now = time(NULL);
622 * FIXME: Accounting packets are never retried!
623 * The Acct-Delay-Time attribute is updated to
624 * reflect the delay, and the packet is re-sent
629 * Not time for a retry, do so.
631 if ((now - radclient->timestamp) < timeout) {
633 * When we walk over the tree sending
634 * packets, we update the minimum time
637 if ((sleep_time == -1) ||
638 (sleep_time > (now - radclient->timestamp))) {
639 sleep_time = now - radclient->timestamp;
645 * We're not trying later, maybe the packet is done.
647 if (radclient->tries == retries) {
648 assert(radclient->request->id >= 0);
651 * Delete the request from the tree of
652 * outstanding requests.
654 fr_packet_list_yank(pl, radclient->request);
656 fprintf(stderr, "radclient: no response from server for ID %d socket %d\n", radclient->request->id, radclient->request->sockfd);
657 deallocate_id(radclient);
660 * Normally we mark it "done" when we've received
661 * the response, but this is a special case.
663 if (radclient->resend == resend_count) {
671 * We are trying later.
673 radclient->timestamp = now;
681 if (rad_send(radclient->request, NULL, secret) < 0) {
682 fprintf(stderr, "radclient: Failed to send packet for ID %d: %s\n",
683 radclient->request->id, fr_strerror());
686 if (fr_debug_flag > 2) print_hex(radclient->request);
692 * Receive one packet, maybe.
694 static int recv_one_packet(int wait_time)
698 radclient_t *radclient;
699 RADIUS_PACKET *reply, **request_p;
702 /* And wait for reply, timing out as necessary */
705 max_fd = fr_packet_list_fd_set(pl, &set);
706 if (max_fd < 0) exit(1); /* no sockets to listen on! */
708 if (wait_time <= 0) {
711 tv.tv_sec = wait_time;
716 * No packet was received.
718 if (select(max_fd, &set, NULL, NULL, &tv) <= 0) {
723 * Look for the packet.
725 reply = fr_packet_list_recv(pl, &set);
727 fprintf(stderr, "radclient: received bad packet: %s\n",
729 return -1; /* bad packet */
733 * udpfromto issues. We may have bound to "*",
734 * and we want to find the replies that are sent to
737 reply->dst_ipaddr = client_ipaddr;
739 if (fr_debug_flag > 2) print_hex(reply);
741 request_p = fr_packet_list_find_byreply(pl, reply);
743 fprintf(stderr, "radclient: received response to request we did not send. (id=%d socket %d)\n", reply->id, reply->sockfd);
745 return -1; /* got reply to packet we didn't send */
747 radclient = fr_packet2myptr(radclient_t, request, request_p);
750 * Fails the signature validation: not a real reply.
751 * FIXME: Silently drop it and listen for another packet.
753 if (rad_verify(reply, radclient->request, secret) < 0) {
754 fr_perror("rad_verify");
756 goto packet_done; /* shared secret is incorrect */
759 fr_packet_list_yank(pl, radclient->request);
760 if (print_filename) printf("%s:%d %d\n",
762 radclient->packet_number,
764 deallocate_id(radclient);
765 radclient->reply = reply;
768 * If this fails, we're out of memory.
770 if (rad_decode(reply, radclient->request, secret) != 0) {
771 fr_perror("rad_decode");
776 /* libradius debug already prints out the value pairs for us */
777 if (!fr_debug_flag && do_output) {
778 printf("Received response ID %d, code %d, length = %d\n",
779 reply->id, reply->code, reply->data_len);
780 vp_printlist(stdout, reply->vps);
782 if (reply->code != PW_AUTHENTICATION_REJECT) {
788 if (radclient->resend == resend_count) {
793 rad_free(&radclient->reply);
799 static int getport(const char *name)
803 svp = getservbyname (name, "udp");
808 return ntohs(svp->s_port);
811 int main(int argc, char **argv)
815 const char *radius_dir = RADDBDIR;
816 char filesecret[256];
822 int force_af = AF_UNSPEC;
826 filename_tree = rbtree_create(filename_cmp, NULL, 0);
827 if (!filename_tree) {
828 fprintf(stderr, "radclient: Out of memory\n");
832 while ((c = getopt(argc, argv, "46c:d:f:Fhi:n:p:qr:sS:t:vx")) != EOF) switch(c) {
840 if (!isdigit((int) *optarg))
842 resend_count = atoi(optarg);
848 rbtree_insert(filename_tree, optarg);
853 case 'i': /* currently broken */
854 if (!isdigit((int) *optarg))
856 last_used_id = atoi(optarg);
857 if ((last_used_id < 0) || (last_used_id > 255)) {
863 persec = atoi(optarg);
864 if (persec <= 0) usage();
868 * Note that sending MANY requests in
869 * parallel can over-run the kernel
870 * queues, and Linux will happily discard
871 * packets. So even if the server responds,
872 * the client may not see the response.
875 parallel = atoi(optarg);
876 if (parallel <= 0) usage();
881 fr_log_fp = NULL; /* no output from you, either! */
884 if (!isdigit((int) *optarg))
886 retries = atoi(optarg);
887 if ((retries == 0) || (retries > 1000)) usage();
893 fp = fopen(optarg, "r");
895 fprintf(stderr, "radclient: Error opening %s: %s\n",
896 optarg, strerror(errno));
899 if (fgets(filesecret, sizeof(filesecret), fp) == NULL) {
900 fprintf(stderr, "radclient: Error reading %s: %s\n",
901 optarg, strerror(errno));
906 /* truncate newline */
907 p = filesecret + strlen(filesecret) - 1;
908 while ((p >= filesecret) &&
914 if (strlen(filesecret) < 2) {
915 fprintf(stderr, "radclient: Secret in %s is too short\n", optarg);
921 if (!isdigit((int) *optarg))
923 timeout = atof(optarg);
926 printf("radclient: $Id$ built on " __DATE__ " at " __TIME__ "\n");
938 argc -= (optind - 1);
939 argv += (optind - 1);
942 ((secret == NULL) && (argc < 4))) {
946 if (dict_init(radius_dir, RADIUS_DICTIONARY) < 0) {
947 fr_perror("radclient");
954 server_ipaddr.af = force_af;
955 if (strcmp(argv[1], "-") != 0) {
956 const char *hostname = argv[1];
957 const char *portname = argv[1];
960 if (*argv[1] == '[') { /* IPv6 URL encoded */
961 p = strchr(argv[1], ']');
962 if ((size_t) (p - argv[1]) >= sizeof(buffer)) {
966 memcpy(buffer, argv[1] + 1, p - argv[1] - 1);
967 buffer[p - argv[1] - 1] = '\0';
973 p = strchr(portname, ':');
974 if (p && (strchr(p + 1, ':') == NULL)) {
981 if (ip_hton(hostname, force_af, &server_ipaddr) < 0) {
982 fprintf(stderr, "radclient: Failed to find IP address for host %s: %s\n", hostname, strerror(errno));
987 * Strip port from hostname if needed.
989 if (portname) server_port = atoi(portname);
993 * See what kind of request we want to send.
995 if (strcmp(argv[2], "auth") == 0) {
996 if (server_port == 0) server_port = getport("radius");
997 if (server_port == 0) server_port = PW_AUTH_UDP_PORT;
998 packet_code = PW_AUTHENTICATION_REQUEST;
1000 } else if (strcmp(argv[2], "challenge") == 0) {
1001 if (server_port == 0) server_port = getport("radius");
1002 if (server_port == 0) server_port = PW_AUTH_UDP_PORT;
1003 packet_code = PW_ACCESS_CHALLENGE;
1005 } else if (strcmp(argv[2], "acct") == 0) {
1006 if (server_port == 0) server_port = getport("radacct");
1007 if (server_port == 0) server_port = PW_ACCT_UDP_PORT;
1008 packet_code = PW_ACCOUNTING_REQUEST;
1011 } else if (strcmp(argv[2], "status") == 0) {
1012 if (server_port == 0) server_port = getport("radius");
1013 if (server_port == 0) server_port = PW_AUTH_UDP_PORT;
1014 packet_code = PW_STATUS_SERVER;
1016 } else if (strcmp(argv[2], "disconnect") == 0) {
1017 if (server_port == 0) server_port = PW_POD_UDP_PORT;
1018 packet_code = PW_DISCONNECT_REQUEST;
1020 } else if (strcmp(argv[2], "coa") == 0) {
1021 if (server_port == 0) server_port = PW_POD_UDP_PORT;
1022 packet_code = PW_COA_REQUEST;
1024 } else if (strcmp(argv[2], "auto") == 0) {
1027 } else if (isdigit((int) argv[2][0])) {
1028 if (server_port == 0) server_port = getport("radius");
1029 if (server_port == 0) server_port = PW_AUTH_UDP_PORT;
1030 packet_code = atoi(argv[2]);
1038 if (argv[3]) secret = argv[3];
1041 * If no '-f' is specified, we're reading from stdin.
1043 if (rbtree_num_elements(filename_tree) == 0) {
1044 rbtree_insert(filename_tree, "-");
1048 * Walk over the list of filenames, creating the requests.
1050 if (rbtree_walk(filename_tree, InOrder, filename_walk, NULL) != 0) {
1055 * No packets read. Die.
1057 if (!radclient_head) {
1058 fprintf(stderr, "radclient: Nothing to send.\n");
1063 * Bind to the first specified IP address and port.
1064 * This means we ignore later ones.
1066 if (radclient_head->request->src_ipaddr.af == AF_UNSPEC) {
1067 memset(&client_ipaddr, 0, sizeof(client_ipaddr));
1068 client_ipaddr.af = server_ipaddr.af;
1071 client_ipaddr = radclient_head->request->src_ipaddr;
1072 client_port = radclient_head->request->src_port;
1074 sockfd = fr_socket(&client_ipaddr, client_port);
1076 fprintf(stderr, "radclient: socket: %s\n", fr_strerror());
1080 pl = fr_packet_list_create(1);
1082 fprintf(stderr, "radclient: Out of memory\n");
1086 if (!fr_packet_list_socket_add(pl, sockfd)) {
1087 fprintf(stderr, "radclient: Out of memory\n");
1092 * Walk over the list of packets, sanity checking
1095 for (this = radclient_head; this != NULL; this = this->next) {
1096 this->request->src_ipaddr = client_ipaddr;
1097 this->request->src_port = client_port;
1098 if (radclient_sane(this) != 0) {
1104 * Walk over the packets to send, until
1107 * FIXME: This currently busy-loops until it receives
1108 * all of the packets. It should really have some sort of
1109 * send packet, get time to wait, select for time, etc.
1115 const char *filename = NULL;
1121 * Walk over the packets, sending them.
1124 for (this = radclient_head; this != NULL; this = next) {
1128 * If there's a packet to receive,
1129 * receive it, but don't wait for a
1135 * This packet is done. Delete it.
1138 radclient_free(this);
1143 * Packets from multiple '-f' are sent
1146 * Packets from one file are sent in
1147 * series, unless '-p' is specified, in
1148 * which case N packets from each file
1149 * are sent in parallel.
1151 if (this->filename != filename) {
1152 filename = this->filename;
1160 * Send the current packet.
1162 send_one_packet(this);
1165 * Wait a little before sending
1166 * the next packet, if told to.
1172 * Don't sleep elsewhere.
1181 tv.tv_usec = 1000000/persec;
1185 * Sleep for milliseconds,
1188 * If we get an error or
1189 * a signal, treat it like
1192 select(0, NULL, NULL, NULL, &tv);
1196 * If we haven't sent this packet
1197 * often enough, we're not done,
1198 * and we shouldn't sleep.
1200 if (this->resend < resend_count) {
1204 } else { /* haven't sent this packet, we're not done */
1205 assert(this->done == 0);
1206 assert(this->reply == NULL);
1212 * Still have outstanding requests.
1214 if (fr_packet_list_num_elements(pl) > 0) {
1221 * Nothing to do until we receive a request, so
1222 * sleep until then. Once we receive one packet,
1223 * we go back, and walk through the whole list again,
1224 * sending more packets (if necessary), and updating
1227 if (!done && (sleep_time > 0)) {
1228 recv_one_packet(sleep_time);
1232 rbtree_free(filename_tree);
1233 fr_packet_list_free(pl);
1237 printf("\n\t Total approved auths: %d\n", totalapp);
1238 printf("\t Total denied auths: %d\n", totaldeny);
1239 printf("\t Total lost auths: %d\n", totallost);