| 44 | } |
| 45 | |
| 46 | void checkEntryDatabase() { |
| 47 | struct protoent* entry; |
| 48 | |
| 49 | // Don't call setprotoent() initially as getprotoent() should open the "database" if necessary. |
| 50 | entry = getprotoent(); |
| 51 | assert(entry != NULL); |
| 52 | assert(strcmp("tcp", entry->p_name) == 0); |
| 53 | |
| 54 | entry = getprotoent(); |
| 55 | assert(entry != NULL); |
| 56 | assert(strcmp("udp", entry->p_name) == 0); |
| 57 | |
| 58 | // Check that setprotoent() correctly sets the next entry to the first entry |
| 59 | setprotoent(1); |
| 60 | |
| 61 | entry = getprotoent(); |
| 62 | assert(entry != NULL); |
| 63 | assert(strcmp("tcp", entry->p_name) == 0); |
| 64 | |
| 65 | entry = getprotoent(); |
| 66 | assert(entry != NULL); |
| 67 | assert(strcmp("udp", entry->p_name) == 0); |
| 68 | |
| 69 | // If we do a getprotoent() that goes past the end of the 'database' check that it returns NULL. |
| 70 | entry = getprotoent(); |
| 71 | assert(entry == NULL); |
| 72 | } |
| 73 | |
| 74 | int main() { |
| 75 | // First check getprotobyname() and getprotobynumber() |
no test coverage detected