/* Copyright (c) 2001-2009 by SoftIntegration, Inc. All Rights Reserved */
/* a sample program that gets the service name by specified port. */
#include <stdlib.h>
#include <stdio.h>
#include <netdb.h>
#include <netinet/in.h>

int main() {
    struct servent *sp;
    int port = 21;
    
    if((sp = getservbyport(port,"tcp")) == NULL) {
        perror("getservbyport:\n");
        exit(1);
    }
    printf("%s\n",sp->s_name);  /* service name */
    printf("%d\n",sp->s_port);  /* port number */
}
