![]() System : Linux absol.cf 5.4.0-198-generic #218-Ubuntu SMP Fri Sep 27 20:18:53 UTC 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.33 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, Directory : /usr/share/emscripten/tests/sockets/ |
Upload File : |
#include <assert.h> #include <errno.h> #include <netdb.h> #include <stdio.h> #include <stdlib.h> #include <string.h> void checkEntryByValue(char* name, int port, char** aliasArray) { struct protoent* entry; char** aliases; // Perform a protocol look up by name entry = getprotobyname(name); assert(entry != NULL); // Check results assert(strcmp(name, entry->p_name) == 0); assert(port == entry->p_proto); aliases = entry->p_aliases; for (int i = 0; aliases[i] != NULL; i++) { assert(strcmp(aliases[i], aliasArray[i]) == 0); } // Perform a protocol look up by number entry = getprotobynumber(port); assert(entry != NULL); // Check results assert(strcmp(name, entry->p_name) == 0); assert(port == entry->p_proto); aliases = entry->p_aliases; for (int i = 0; aliases[i] != NULL; i++) { assert(strcmp(aliases[i], aliasArray[i]) == 0); } } void checkEntryDatabase() { struct protoent* entry; // Don't call setprotoent() initially as getprotoent() should open the "database" if necessary. entry = getprotoent(); assert(entry != NULL); assert(strcmp("tcp", entry->p_name) == 0); entry = getprotoent(); assert(entry != NULL); assert(strcmp("udp", entry->p_name) == 0); // Check that setprotoent() correctly sets the next entry to the first entry setprotoent(1); entry = getprotoent(); assert(entry != NULL); assert(strcmp("tcp", entry->p_name) == 0); entry = getprotoent(); assert(entry != NULL); assert(strcmp("udp", entry->p_name) == 0); // If we do a getprotoent() that goes past the end of the 'database' check that it returns NULL. entry = getprotoent(); assert(entry == NULL); } int main() { // First check getprotobyname() and getprotobynumber() char* aliases[] = {"TCP"}; checkEntryByValue("tcp", 6, aliases); aliases[0] = "UDP"; checkEntryByValue("udp", 17, aliases); // Check that the doomsday protocol hasn't been implemented :-) ...... assert(getprotobyname("doomsday") == NULL); // Now check setprotoent() and getprotoent() checkEntryDatabase(); endprotoent(); puts("success"); return EXIT_SUCCESS; }