#include <netdb.h>
int getport(char *port)
{
struct servent *sp;
sp = getservbyname(port, "tcp");
if (sp == NULL) {
return (atoi(port));
}
else {
return (ntohs(sp->s_port)); /* 포트번호를 네트워크바이트 순서에서 호스트바이트 순서로 변경 */
}
}
#include <netdb.h>
-------------------------------------------------------------------
struct servent {
char *s_name; /* official service name */
char **s_aliases; /* alias list */
int s_port; /* port # */
char *s_proto; /* protocol to use */
};
-------------------------------------------------------------------
#include <netdb.h>
-------------------------------------------------------------------
struct servent *getservbyname(const char *, const char *);
-------------------------------------------------------------------