/* 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 result;
    char buffer[128];
    int port = 21;
    
    getservbyport_r(port,"tcp",&result,buffer,sizeof(buffer));
    printf("%s\n",result.s_name);  /* service name */
    printf("%d\n",result.s_port);  /* port number */
}
 