Skip to content

Commit

Permalink
Move radclient to use fr_pton_port for its host and port parsing
Browse files Browse the repository at this point in the history
fr_pton_port seems to work, whereas what was there before didn't...
  • Loading branch information
arr2036 committed Jul 20, 2015
1 parent 3ca06cd commit 5e205a8
Showing 1 changed file with 11 additions and 44 deletions.
55 changes: 11 additions & 44 deletions src/main/radclient.c
Expand Up @@ -1151,16 +1151,16 @@ static int recv_one_packet(int wait_time)

int main(int argc, char **argv)
{
int c;
char const *radius_dir = RADDBDIR;
char const *dict_dir = DICTDIR;
char filesecret[256];
FILE *fp;
int do_summary = false;
int persec = 0;
int parallel = 1;
int c;
char const *radius_dir = RADDBDIR;
char const *dict_dir = DICTDIR;
char filesecret[256];
FILE *fp;
int do_summary = false;
int persec = 0;
int parallel = 1;
rc_request_t *this;
int force_af = AF_UNSPEC;
int force_af = AF_UNSPEC;

/*
* It's easier having two sets of flags to set the
Expand Down Expand Up @@ -1386,45 +1386,12 @@ int main(int argc, char **argv)
/*
* Resolve hostname.
*/
if (force_af == AF_UNSPEC) force_af = AF_INET;
server_ipaddr.af = force_af;
if (strcmp(argv[1], "-") != 0) {
char *p;
char const *hostname = argv[1];
char const *portname = argv[1];
char buffer[256];

if (*argv[1] == '[') { /* IPv6 URL encoded */
p = strchr(argv[1], ']');
if ((size_t) (p - argv[1]) >= sizeof(buffer)) {
usage();
}

memcpy(buffer, argv[1] + 1, p - argv[1] - 1);
buffer[p - argv[1] - 1] = '\0';

hostname = buffer;
portname = p + 1;

}
p = strchr(portname, ':');
if (p && (strchr(p + 1, ':') == NULL)) {
*p = '\0';
portname = p + 1;
} else {
portname = NULL;
}

if (ip_hton(&server_ipaddr, force_af, hostname, false) < 0) {
ERROR("Failed to find IP address for host %s: %s", hostname, strerror(errno));
if (fr_pton_port(&server_ipaddr, &server_port, argv[1], -1, force_af, true) < 0) {
ERROR("%s", fr_strerror());
exit(1);
}

/*
* Strip port from hostname if needed.
*/
if (portname) server_port = atoi(portname);

/*
* Work backwards from the port to determine the packet type
*/
Expand Down

0 comments on commit 5e205a8

Please sign in to comment.