forked from OSchip/llvm-project
[sanitizer] Another attempt to fix protoent test
Now we are going to pick name and index based on output of getprotoent_r.
This commit is contained in:
parent
b0a971d25c
commit
1bbed69059
|
@ -7,6 +7,10 @@
|
|||
#include <errno.h>
|
||||
#include <netdb.h>
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
|
||||
std::string any_name;
|
||||
int total_count;
|
||||
|
||||
void print_protoent(protoent *curr_entry) {
|
||||
fprintf(stderr, "%s (%d)\n", curr_entry->p_name, curr_entry->p_proto);
|
||||
|
@ -23,6 +27,8 @@ void print_all_protoent() {
|
|||
protoent *curr_entry;
|
||||
|
||||
while (getprotoent_r(&entry, buf, sizeof(buf), &curr_entry) != ENOENT && curr_entry) {
|
||||
++total_count;
|
||||
any_name = curr_entry->p_name;
|
||||
print_protoent(curr_entry);
|
||||
}
|
||||
}
|
||||
|
@ -51,10 +57,13 @@ int main() {
|
|||
fprintf(stderr, "All protoent\n");
|
||||
print_all_protoent();
|
||||
|
||||
if (!total_count)
|
||||
return 0;
|
||||
|
||||
fprintf(stderr, "Protoent by name\n");
|
||||
print_protoent_by_name("ipv6");
|
||||
print_protoent_by_name(any_name.c_str());
|
||||
|
||||
fprintf(stderr, "Protoent by num\n");
|
||||
print_protoent_by_num(17);
|
||||
print_protoent_by_num(total_count / 2);
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue