Refactoring

This commit is contained in:
Marco d'Itri 2025-05-04 16:05:54 +02:00
parent 1a148ff7e4
commit 4a5357548d
No known key found for this signature in database
GPG Key ID: CB3EC33AE1DED781
2 changed files with 9 additions and 8 deletions

15
whois.c
View File

@ -311,7 +311,7 @@ int handle_query(const char *hserver, const char *hport,
const char *query, const char *flags) const char *query, const char *flags)
{ {
char *server = NULL, *port = NULL; char *server = NULL, *port = NULL;
char *p, *query_string; char *p, *query_string, *new_server;
if (hport) { if (hport) {
server = strdup(hserver); server = strdup(hserver);
@ -408,15 +408,14 @@ int handle_query(const char *hserver, const char *hport,
printf(_("Query string: \"%s\"\n\n"), query_string); printf(_("Query string: \"%s\"\n\n"), query_string);
} }
sockfd = openconn(server, port); new_server = query_server(server, port, query_string);
free(server); free(server);
server = do_query(sockfd, query_string);
free(query_string); free(query_string);
/* recursion is fun */ /* recursion is fun */
if (!no_recursion && server && !strchr(query, ' ')) { if (!no_recursion && new_server && !strchr(query, ' ')) {
printf(_("\n\nFound a referral to %s.\n\n"), server); printf(_("\n\nFound a referral to %s.\n\n"), new_server);
handle_query(server, NULL, query, flags); handle_query(new_server, NULL, query, flags);
} }
return 0; return 0;
@ -789,17 +788,19 @@ int hide_line(int *hiding, const char *const line)
} }
/* returns a string which should be freed by the caller, or NULL */ /* returns a string which should be freed by the caller, or NULL */
char *do_query(const int sock, const char *query) char *query_server(const char *server, const char *port, const char *query)
{ {
char *temp, *p, buf[2000]; char *temp, *p, buf[2000];
FILE *fi; FILE *fi;
int hide = hide_discl; int hide = hide_discl;
int sock;
char *referral_server = NULL; char *referral_server = NULL;
temp = malloc(strlen(query) + 2 + 1); temp = malloc(strlen(query) + 2 + 1);
strcpy(temp, query); strcpy(temp, query);
strcat(temp, "\r\n"); strcat(temp, "\r\n");
sock = openconn(server, port);
fi = fdopen(sock, "r"); fi = fdopen(sock, "r");
if (!fi) if (!fi)
err_sys("fdopen"); err_sys("fdopen");

View File

@ -15,7 +15,7 @@ const char *match_config_file(const char *);
const char *whereas(const unsigned long); const char *whereas(const unsigned long);
char *queryformat(const char *, const char *, const char *); char *queryformat(const char *, const char *, const char *);
int hide_line(int *hiding, const char *const line); int hide_line(int *hiding, const char *const line);
char *do_query(const int, const char *); char *query_server(const char *, const char *, const char *);
char *query_crsnic(const int, const char *); char *query_crsnic(const int, const char *);
char *query_afilias(const int, const char *); char *query_afilias(const int, const char *);
char *query_iana(const int, const char *); char *query_iana(const int, const char *);