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 success = 0;
41 static int retries = 3;
42 static float timeout = 5;
43 static const char *secret = NULL;
44 static int do_output = 1;
45 static int totalapp = 0;
46 static int totaldeny = 0;
47 static int totallost = 0;
49 static int server_port = 0;
50 static int packet_code = 0;
51 static fr_ipaddr_t server_ipaddr;
52 static int resend_count = 1;
54 static int print_filename = 0;
56 static fr_ipaddr_t client_ipaddr;
57 static int client_port = 0;
60 static int last_used_id = -1;
63 const char *proto = NULL;
65 static int ipproto = IPPROTO_UDP;
67 static rbtree_t *filename_tree = NULL;
68 static fr_packet_list_t *pl = NULL;
70 static int sleep_time = -1;
72 typedef struct radclient_t {
73 struct radclient_t *prev;
74 struct radclient_t *next;
77 int packet_number; /* in the file */
80 RADIUS_PACKET *request;
87 static radclient_t *radclient_head = NULL;
88 static radclient_t *radclient_tail = NULL;
91 static void NEVER_RETURNS usage(void)
93 fprintf(stderr, "Usage: radclient [options] server[:port] <command> [<secret>]\n");
95 fprintf(stderr, " <command> One of auth, acct, status, coa, or disconnect.\n");
96 fprintf(stderr, " -c count Send each packet 'count' times.\n");
97 fprintf(stderr, " -d raddb Set dictionary directory.\n");
98 fprintf(stderr, " -f file Read packets from file, not stdin.\n");
99 fprintf(stderr, " -i id Set request id to 'id'. Values may be 0..255\n");
100 fprintf(stderr, " -n num Send N requests/s\n");
101 fprintf(stderr, " -p num Send 'num' packets from a file in parallel.\n");
102 fprintf(stderr, " -q Do not print anything out.\n");
103 fprintf(stderr, " -r retries If timeout, retry sending the packet 'retries' times.\n");
104 fprintf(stderr, " -s Print out summary information of auth results.\n");
105 fprintf(stderr, " -S file read secret from file, not command line.\n");
106 fprintf(stderr, " -t timeout Wait 'timeout' seconds before retrying (may be a floating point number).\n");
107 fprintf(stderr, " -v Show program version information.\n");
108 fprintf(stderr, " -x Debugging mode.\n");
109 fprintf(stderr, " -4 Use IPv4 address of server\n");
110 fprintf(stderr, " -6 Use IPv6 address of server.\n");
112 fprintf(stderr, " -P proto Use proto (tcp or udp) for transport.\n");
119 * Free a radclient struct, which may (or may not)
120 * already be in the list.
122 static void radclient_free(radclient_t *radclient)
124 radclient_t *prev, *next;
126 if (radclient->request) rad_free(&radclient->request);
127 if (radclient->reply) rad_free(&radclient->reply);
129 prev = radclient->prev;
130 next = radclient->next;
133 assert(radclient_head != radclient);
135 } else if (radclient_head) {
136 assert(radclient_head == radclient);
137 radclient_head = next;
141 assert(radclient_tail != radclient);
143 } else if (radclient_tail) {
144 assert(radclient_tail == radclient);
145 radclient_tail = prev;
152 * Initialize a radclient data structure and add it to
153 * the global linked list.
155 static int radclient_init(const char *filename)
159 radclient_t *radclient;
161 int packet_number = 1;
163 assert(filename != NULL);
166 * Determine where to read the VP's from.
168 if (strcmp(filename, "-") != 0) {
169 fp = fopen(filename, "r");
171 fprintf(stderr, "radclient: Error opening %s: %s\n",
172 filename, strerror(errno));
180 * Loop until the file is done.
186 radclient = malloc(sizeof(*radclient));
188 perror("radclient: X");
189 if (fp != stdin) fclose(fp);
192 memset(radclient, 0, sizeof(*radclient));
194 radclient->request = rad_alloc(1);
195 if (!radclient->request) {
196 fr_perror("radclient: Y");
198 if (fp != stdin) fclose(fp);
203 radclient->request->src_ipaddr = client_ipaddr;
204 radclient->request->src_port = client_port;
205 radclient->request->dst_ipaddr = server_ipaddr;
206 radclient->request->dst_port = server_port;
209 radclient->filename = filename;
210 radclient->request->id = -1; /* allocate when sending */
211 radclient->packet_number = packet_number++;
216 radclient->request->vps = readvp2(fp, &filedone, "radclient:");
217 if (!radclient->request->vps) {
218 rad_free(&radclient->request);
220 if (fp != stdin) fclose(fp);
225 * Keep a copy of the the User-Password attribute.
227 if ((vp = pairfind(radclient->request->vps, PW_USER_PASSWORD, 0)) != NULL) {
228 strlcpy(radclient->password, vp->vp_strvalue,
229 sizeof(radclient->password));
231 * Otherwise keep a copy of the CHAP-Password attribute.
233 } else if ((vp = pairfind(radclient->request->vps, PW_CHAP_PASSWORD, 0)) != NULL) {
234 strlcpy(radclient->password, vp->vp_strvalue,
235 sizeof(radclient->password));
237 radclient->password[0] = '\0';
241 * Fix up Digest-Attributes issues
243 for (vp = radclient->request->vps; vp != NULL; vp = vp->next) {
244 switch (vp->attribute) {
249 * Allow it to set the packet type in
250 * the attributes read from the file.
253 radclient->request->code = vp->vp_integer;
256 case PW_PACKET_DST_PORT:
257 radclient->request->dst_port = (vp->vp_integer & 0xffff);
260 case PW_PACKET_DST_IP_ADDRESS:
261 radclient->request->dst_ipaddr.af = AF_INET;
262 radclient->request->dst_ipaddr.ipaddr.ip4addr.s_addr = vp->vp_ipaddr;
265 case PW_PACKET_DST_IPV6_ADDRESS:
266 radclient->request->dst_ipaddr.af = AF_INET6;
267 radclient->request->dst_ipaddr.ipaddr.ip6addr = vp->vp_ipv6addr;
270 case PW_PACKET_SRC_PORT:
271 radclient->request->src_port = (vp->vp_integer & 0xffff);
274 case PW_PACKET_SRC_IP_ADDRESS:
275 radclient->request->src_ipaddr.af = AF_INET;
276 radclient->request->src_ipaddr.ipaddr.ip4addr.s_addr = vp->vp_ipaddr;
279 case PW_PACKET_SRC_IPV6_ADDRESS:
280 radclient->request->src_ipaddr.af = AF_INET6;
281 radclient->request->src_ipaddr.ipaddr.ip6addr = vp->vp_ipv6addr;
284 case PW_DIGEST_REALM:
285 case PW_DIGEST_NONCE:
286 case PW_DIGEST_METHOD:
289 case PW_DIGEST_ALGORITHM:
290 case PW_DIGEST_BODY_DIGEST:
291 case PW_DIGEST_CNONCE:
292 case PW_DIGEST_NONCE_COUNT:
293 case PW_DIGEST_USER_NAME:
295 memmove(&vp->vp_octets[2], &vp->vp_octets[0],
297 vp->vp_octets[0] = vp->attribute - PW_DIGEST_REALM + 1;
299 vp->vp_octets[1] = vp->length;
300 vp->attribute = PW_DIGEST_ATTRIBUTES;
303 } /* loop over the VP's we read in */
306 * Add it to the tail of the list.
308 if (!radclient_head) {
309 assert(radclient_tail == NULL);
310 radclient_head = radclient;
311 radclient->prev = NULL;
313 assert(radclient_tail->next == NULL);
314 radclient_tail->next = radclient;
315 radclient->prev = radclient_tail;
317 radclient_tail = radclient;
318 radclient->next = NULL;
320 } while (!filedone); /* loop until the file is done. */
322 if (fp != stdin) fclose(fp);
332 * Sanity check each argument.
334 static int radclient_sane(radclient_t *radclient)
336 if (radclient->request->dst_port == 0) {
337 radclient->request->dst_port = server_port;
339 if (radclient->request->dst_ipaddr.af == AF_UNSPEC) {
340 if (server_ipaddr.af == AF_UNSPEC) {
341 fprintf(stderr, "radclient: No server was given, but request %d in file %s did not contain Packet-Dst-IP-Address\n",
342 radclient->packet_number, radclient->filename);
345 radclient->request->dst_ipaddr = server_ipaddr;
347 if (radclient->request->code == 0) {
348 if (packet_code == -1) {
349 fprintf(stderr, "radclient: Request was \"auto\", but request %d in file %s did not contain Packet-Type\n",
350 radclient->packet_number, radclient->filename);
354 radclient->request->code = packet_code;
356 radclient->request->sockfd = -1;
363 * For request handline.
365 static int filename_cmp(const void *one, const void *two)
367 return strcmp((const char *) one, (const char *) two);
370 static int filename_walk(void *context, void *data)
372 const char *filename = data;
374 context = context; /* -Wunused */
377 * Read request(s) from the file.
379 if (!radclient_init(filename)) {
380 return 1; /* stop walking */
388 * Deallocate packet ID, etc.
390 static void deallocate_id(radclient_t *radclient)
392 if (!radclient || !radclient->request ||
393 (radclient->request->id < 0)) {
398 * One more unused RADIUS ID.
400 fr_packet_list_id_free(pl, radclient->request);
401 radclient->request->id = -1;
404 * If we've already sent a packet, free up the old one,
405 * and ensure that the next packet has a unique
406 * authentication vector.
408 if (radclient->request->data) {
409 free(radclient->request->data);
410 radclient->request->data = NULL;
413 if (radclient->reply) rad_free(&radclient->reply);
417 static void print_hex(RADIUS_PACKET *packet)
421 if (!packet->data) return;
423 printf(" Code:\t\t%u\n", packet->data[0]);
424 printf(" Id:\t\t%u\n", packet->data[1]);
425 printf(" Length:\t%u\n", ((packet->data[2] << 8) |
427 printf(" Vector:\t");
428 for (i = 4; i < 20; i++) {
429 printf("%02x", packet->data[i]);
433 if (packet->data_len > 20) {
438 total = packet->data_len - 20;
439 ptr = packet->data + 20;
445 if (total < 2) { /* too short */
446 printf("%02x\n", *ptr);
450 if (ptr[1] > total) { /* too long */
451 for (i = 0; i < total; i++) {
452 printf("%02x ", ptr[i]);
457 printf("%02x %02x ", ptr[0], ptr[1]);
458 attrlen = ptr[1] - 2;
462 for (i = 0; i < attrlen; i++) {
463 if ((i > 0) && ((i & 0x0f) == 0x00))
465 printf("%02x ", ptr[i]);
466 if ((i & 0x0f) == 0x0f) printf("\n");
469 if ((attrlen & 0x0f) != 0x00) printf("\n");
481 static int send_one_packet(radclient_t *radclient)
483 assert(radclient->done == 0);
486 * Remember when we have to wake up, to re-send the
487 * request, of we didn't receive a response.
489 if ((sleep_time == -1) ||
490 (sleep_time > (int) timeout)) {
491 sleep_time = (int) timeout;
495 * Haven't sent the packet yet. Initialize it.
497 if (radclient->request->id == -1) {
500 assert(radclient->reply == NULL);
503 * Didn't find a free packet ID, we're not done,
504 * we don't sleep, and we stop trying to process
508 radclient->request->src_ipaddr.af = server_ipaddr.af;
509 rcode = fr_packet_list_id_alloc(pl, ipproto,
510 radclient->request, NULL);
516 mysockfd = fr_tcp_client_socket(NULL,
521 mysockfd = fr_socket(&client_ipaddr, 0);
523 fprintf(stderr, "radclient: Can't open new socket\n");
526 if (!fr_packet_list_socket_add(pl, mysockfd, ipproto,
528 server_port, NULL)) {
529 fprintf(stderr, "radclient: Can't add new socket\n");
541 assert(radclient->request->id != -1);
542 assert(radclient->request->data == NULL);
544 for (i = 0; i < 4; i++) {
545 ((uint32_t *) radclient->request->vector)[i] = fr_rand();
549 * Update the password, so it can be encrypted with the
550 * new authentication vector.
552 if (radclient->password[0] != '\0') {
555 if ((vp = pairfind(radclient->request->vps, PW_USER_PASSWORD, 0)) != NULL) {
556 strlcpy(vp->vp_strvalue, radclient->password,
557 sizeof(vp->vp_strvalue));
558 vp->length = strlen(vp->vp_strvalue);
560 } else if ((vp = pairfind(radclient->request->vps, PW_CHAP_PASSWORD, 0)) != NULL) {
562 * FIXME: AND there's no CHAP-Challenge,
563 * AND vp->length != 17
564 * AND rad_chap_encode() != vp->vp_octets
566 strlcpy(vp->vp_strvalue, radclient->password,
567 sizeof(vp->vp_strvalue));
568 vp->length = strlen(vp->vp_strvalue);
570 rad_chap_encode(radclient->request,
572 radclient->request->id, vp);
577 radclient->timestamp = time(NULL);
578 radclient->tries = 1;
582 * Duplicate found. Serious error!
584 if (!fr_packet_list_insert(pl, &radclient->request)) {
592 if (client_port == 0) {
593 client_ipaddr = radclient->request->src_ipaddr;
594 client_port = radclient->request->src_port;
598 } else { /* radclient->request->id >= 0 */
599 time_t now = time(NULL);
602 * FIXME: Accounting packets are never retried!
603 * The Acct-Delay-Time attribute is updated to
604 * reflect the delay, and the packet is re-sent
609 * Not time for a retry, do so.
611 if ((now - radclient->timestamp) < timeout) {
613 * When we walk over the tree sending
614 * packets, we update the minimum time
617 if ((sleep_time == -1) ||
618 (sleep_time > (now - radclient->timestamp))) {
619 sleep_time = now - radclient->timestamp;
625 * We're not trying later, maybe the packet is done.
627 if (radclient->tries == retries) {
628 assert(radclient->request->id >= 0);
631 * Delete the request from the tree of
632 * outstanding requests.
634 fr_packet_list_yank(pl, radclient->request);
636 fprintf(stderr, "radclient: no response from server for ID %d socket %d\n", radclient->request->id, radclient->request->sockfd);
637 deallocate_id(radclient);
640 * Normally we mark it "done" when we've received
641 * the response, but this is a special case.
643 if (radclient->resend == resend_count) {
651 * We are trying later.
653 radclient->timestamp = now;
661 if (rad_send(radclient->request, NULL, secret) < 0) {
662 fprintf(stderr, "radclient: Failed to send packet for ID %d: %s\n",
663 radclient->request->id, fr_strerror());
666 if (fr_debug_flag > 2) print_hex(radclient->request);
672 * Receive one packet, maybe.
674 static int recv_one_packet(int wait_time)
678 radclient_t *radclient;
679 RADIUS_PACKET *reply, **request_p;
682 /* And wait for reply, timing out as necessary */
685 max_fd = fr_packet_list_fd_set(pl, &set);
686 if (max_fd < 0) exit(1); /* no sockets to listen on! */
688 if (wait_time <= 0) {
691 tv.tv_sec = wait_time;
696 * No packet was received.
698 if (select(max_fd, &set, NULL, NULL, &tv) <= 0) {
703 * Look for the packet.
706 reply = fr_packet_list_recv(pl, &set);
708 fprintf(stderr, "radclient: received bad packet: %s\n",
712 * If the packet is bad, we close the socket.
713 * I'm not sure how to do that now, so we just
718 return -1; /* bad packet */
722 * udpfromto issues. We may have bound to "*",
723 * and we want to find the replies that are sent to
726 reply->dst_ipaddr = client_ipaddr;
727 reply->dst_port = client_port;
729 reply->src_ipaddr = server_ipaddr;
730 reply->src_port = server_port;
733 if (fr_debug_flag > 2) print_hex(reply);
735 request_p = fr_packet_list_find_byreply(pl, reply);
737 fprintf(stderr, "radclient: received response to request we did not send. (id=%d socket %d)\n", reply->id, reply->sockfd);
739 return -1; /* got reply to packet we didn't send */
741 radclient = fr_packet2myptr(radclient_t, request, request_p);
744 * Fails the signature validation: not a real reply.
745 * FIXME: Silently drop it and listen for another packet.
747 if (rad_verify(reply, radclient->request, secret) < 0) {
748 fr_perror("rad_verify");
750 goto packet_done; /* shared secret is incorrect */
753 fr_packet_list_yank(pl, radclient->request);
754 if (print_filename) printf("%s:%d %d\n",
756 radclient->packet_number,
758 deallocate_id(radclient);
759 radclient->reply = reply;
763 * If this fails, we're out of memory.
765 if (rad_decode(radclient->reply, radclient->request, secret) != 0) {
766 fr_perror("rad_decode");
771 /* libradius debug already prints out the value pairs for us */
772 if (!fr_debug_flag && do_output) {
773 printf("Received response ID %d, code %d, length = %ld\n",
774 radclient->reply->id, radclient->reply->code,
775 radclient->reply->data_len);
776 vp_printlist(stdout, radclient->reply->vps);
779 if ((radclient->reply->code == PW_AUTHENTICATION_ACK) ||
780 (radclient->reply->code == PW_ACCOUNTING_RESPONSE) ||
781 (radclient->reply->code == PW_COA_ACK) ||
782 (radclient->reply->code == PW_DISCONNECT_ACK)) {
783 success = 1; /* have a good response */
789 if (radclient->resend == resend_count) {
794 rad_free(&radclient->reply);
795 rad_free(&reply); /* may be NULL */
801 static int getport(const char *name)
805 svp = getservbyname (name, "udp");
810 return ntohs(svp->s_port);
813 int main(int argc, char **argv)
817 const char *radius_dir = RADDBDIR;
818 char filesecret[256];
824 int force_af = AF_UNSPEC;
828 filename_tree = rbtree_create(filename_cmp, NULL, 0);
829 if (!filename_tree) {
830 fprintf(stderr, "radclient: Out of memory\n");
834 while ((c = getopt(argc, argv, "46c:d:f:Fhi:n:p:qr:sS:t:vx"
838 )) != EOF) switch(c) {
846 if (!isdigit((int) *optarg))
848 resend_count = atoi(optarg);
854 rbtree_insert(filename_tree, optarg);
859 case 'i': /* currently broken */
860 if (!isdigit((int) *optarg))
862 last_used_id = atoi(optarg);
863 if ((last_used_id < 0) || (last_used_id > 255)) {
869 persec = atoi(optarg);
870 if (persec <= 0) usage();
874 * Note that sending MANY requests in
875 * parallel can over-run the kernel
876 * queues, and Linux will happily discard
877 * packets. So even if the server responds,
878 * the client may not see the response.
881 parallel = atoi(optarg);
882 if (parallel <= 0) usage();
888 if (strcmp(proto, "tcp") != 0) {
889 if (strcmp(proto, "udp") == 0) {
895 ipproto = IPPROTO_TCP;
903 fr_log_fp = NULL; /* no output from you, either! */
906 if (!isdigit((int) *optarg))
908 retries = atoi(optarg);
909 if ((retries == 0) || (retries > 1000)) usage();
915 fp = fopen(optarg, "r");
917 fprintf(stderr, "radclient: Error opening %s: %s\n",
918 optarg, strerror(errno));
921 if (fgets(filesecret, sizeof(filesecret), fp) == NULL) {
922 fprintf(stderr, "radclient: Error reading %s: %s\n",
923 optarg, strerror(errno));
928 /* truncate newline */
929 p = filesecret + strlen(filesecret) - 1;
930 while ((p >= filesecret) &&
936 if (strlen(filesecret) < 2) {
937 fprintf(stderr, "radclient: Secret in %s is too short\n", optarg);
943 if (!isdigit((int) *optarg))
945 timeout = atof(optarg);
948 printf("radclient: $Id$ built on " __DATE__ " at " __TIME__ "\n");
960 argc -= (optind - 1);
961 argv += (optind - 1);
964 ((secret == NULL) && (argc < 4))) {
968 if (dict_init(radius_dir, RADIUS_DICTIONARY) < 0) {
969 fr_perror("radclient");
976 if (force_af == AF_UNSPEC) force_af = AF_INET;
977 server_ipaddr.af = force_af;
978 if (strcmp(argv[1], "-") != 0) {
979 const char *hostname = argv[1];
980 const char *portname = argv[1];
983 if (*argv[1] == '[') { /* IPv6 URL encoded */
984 p = strchr(argv[1], ']');
985 if ((size_t) (p - argv[1]) >= sizeof(buffer)) {
989 memcpy(buffer, argv[1] + 1, p - argv[1] - 1);
990 buffer[p - argv[1] - 1] = '\0';
996 p = strchr(portname, ':');
997 if (p && (strchr(p + 1, ':') == NULL)) {
1004 if (ip_hton(hostname, force_af, &server_ipaddr) < 0) {
1005 fprintf(stderr, "radclient: Failed to find IP address for host %s: %s\n", hostname, strerror(errno));
1010 * Strip port from hostname if needed.
1012 if (portname) server_port = atoi(portname);
1016 * See what kind of request we want to send.
1018 if (strcmp(argv[2], "auth") == 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_AUTHENTICATION_REQUEST;
1023 } else if (strcmp(argv[2], "challenge") == 0) {
1024 if (server_port == 0) server_port = getport("radius");
1025 if (server_port == 0) server_port = PW_AUTH_UDP_PORT;
1026 packet_code = PW_ACCESS_CHALLENGE;
1028 } else if (strcmp(argv[2], "acct") == 0) {
1029 if (server_port == 0) server_port = getport("radacct");
1030 if (server_port == 0) server_port = PW_ACCT_UDP_PORT;
1031 packet_code = PW_ACCOUNTING_REQUEST;
1034 } else if (strcmp(argv[2], "status") == 0) {
1035 if (server_port == 0) server_port = getport("radius");
1036 if (server_port == 0) server_port = PW_AUTH_UDP_PORT;
1037 packet_code = PW_STATUS_SERVER;
1039 } else if (strcmp(argv[2], "disconnect") == 0) {
1040 if (server_port == 0) server_port = PW_COA_UDP_PORT;
1041 packet_code = PW_DISCONNECT_REQUEST;
1043 } else if (strcmp(argv[2], "coa") == 0) {
1044 if (server_port == 0) server_port = PW_COA_UDP_PORT;
1045 packet_code = PW_COA_REQUEST;
1047 } else if (strcmp(argv[2], "auto") == 0) {
1050 } else if (isdigit((int) argv[2][0])) {
1051 if (server_port == 0) server_port = getport("radius");
1052 if (server_port == 0) server_port = PW_AUTH_UDP_PORT;
1053 packet_code = atoi(argv[2]);
1061 if (argv[3]) secret = argv[3];
1064 * If no '-f' is specified, we're reading from stdin.
1066 if (rbtree_num_elements(filename_tree) == 0) {
1067 rbtree_insert(filename_tree, "-");
1071 * Walk over the list of filenames, creating the requests.
1073 if (rbtree_walk(filename_tree, InOrder, filename_walk, NULL) != 0) {
1078 * No packets read. Die.
1080 if (!radclient_head) {
1081 fprintf(stderr, "radclient: Nothing to send.\n");
1086 * Bind to the first specified IP address and port.
1087 * This means we ignore later ones.
1089 if (radclient_head->request->src_ipaddr.af == AF_UNSPEC) {
1090 memset(&client_ipaddr, 0, sizeof(client_ipaddr));
1091 client_ipaddr.af = server_ipaddr.af;
1094 client_ipaddr = radclient_head->request->src_ipaddr;
1095 client_port = radclient_head->request->src_port;
1099 sockfd = fr_tcp_client_socket(NULL, &server_ipaddr, server_port);
1102 sockfd = fr_socket(&client_ipaddr, client_port);
1104 fprintf(stderr, "radclient: socket: %s\n", fr_strerror());
1108 pl = fr_packet_list_create(1);
1110 fprintf(stderr, "radclient: Out of memory\n");
1114 if (!fr_packet_list_socket_add(pl, sockfd, ipproto, &server_ipaddr,
1115 server_port, NULL)) {
1116 fprintf(stderr, "radclient: Out of memory\n");
1121 * Walk over the list of packets, sanity checking
1124 for (this = radclient_head; this != NULL; this = this->next) {
1125 this->request->src_ipaddr = client_ipaddr;
1126 this->request->src_port = client_port;
1127 if (radclient_sane(this) != 0) {
1133 * Walk over the packets to send, until
1136 * FIXME: This currently busy-loops until it receives
1137 * all of the packets. It should really have some sort of
1138 * send packet, get time to wait, select for time, etc.
1144 const char *filename = NULL;
1150 * Walk over the packets, sending them.
1153 for (this = radclient_head; this != NULL; this = next) {
1157 * If there's a packet to receive,
1158 * receive it, but don't wait for a
1164 * This packet is done. Delete it.
1167 radclient_free(this);
1172 * Packets from multiple '-f' are sent
1175 * Packets from one file are sent in
1176 * series, unless '-p' is specified, in
1177 * which case N packets from each file
1178 * are sent in parallel.
1180 if (this->filename != filename) {
1181 filename = this->filename;
1189 * Send the current packet.
1191 send_one_packet(this);
1194 * Wait a little before sending
1195 * the next packet, if told to.
1201 * Don't sleep elsewhere.
1210 tv.tv_usec = 1000000/persec;
1214 * Sleep for milliseconds,
1217 * If we get an error or
1218 * a signal, treat it like
1221 select(0, NULL, NULL, NULL, &tv);
1225 * If we haven't sent this packet
1226 * often enough, we're not done,
1227 * and we shouldn't sleep.
1229 if (this->resend < resend_count) {
1233 } else { /* haven't sent this packet, we're not done */
1234 assert(this->done == 0);
1235 assert(this->reply == NULL);
1241 * Still have outstanding requests.
1243 if (fr_packet_list_num_elements(pl) > 0) {
1250 * Nothing to do until we receive a request, so
1251 * sleep until then. Once we receive one packet,
1252 * we go back, and walk through the whole list again,
1253 * sending more packets (if necessary), and updating
1256 if (!done && (sleep_time > 0)) {
1257 recv_one_packet(sleep_time);
1261 rbtree_free(filename_tree);
1262 fr_packet_list_free(pl);
1263 while (radclient_head) radclient_free(radclient_head);
1267 printf("\n\t Total approved auths: %d\n", totalapp);
1268 printf("\t Total denied auths: %d\n", totaldeny);
1269 printf("\t Total lost auths: %d\n", totallost);
1272 if (success) return 0;