'getservbyname'에 해당되는 글 1건

  1. 2013.01.28 int getport(char *port)

반응형

 

#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 *);
-------------------------------------------------------------------

반응형
Posted by 공간사랑
,