#include #include #include int main(int argc, char **argv) { char service[] = "echo"; char protocol[] = "tcp"; struct servent *p = getservbyname(service, protocol); if (p == NULL) { fprintf(stderr, "%s: service %s with protocol %s not found\n", argv[0], service, protocol); return EXIT_FAILURE; } printf("service name %s\n", p->s_name); printf("port number %d\n", p->s_port); printf("protocol %s\n", p->s_proto); return EXIT_SUCCESS; }