Socket ÁÖ¼Ò ±¸Á¶´Â?

SUBJECT:   Socket ÁÖ¼Ò ±¸Á¶´Â?

Description :

    ########   ¼ÒÄÏ ÁÖ¼Ò  ±¸Á¶    ##########

  ¸¹Àº BSD network ½Ã½ºÅÛ È£ÃâÀº µ¶¸³º¯¼ö·Î¼­ ¼ÒÄÏÁÖ¼Ò ±¸Á¶ÀÇ Áö½ÃÀÚ¸¦ 
  ÇÊ¿ä·Î ÇÑ´Ù.  ÀÌ ±¸Á¶ÀÇ Á¤ÀÇ´Â ¿¡ ÀÖ´Ù.

       struct sockaddr {
           u_short  sa_family;    /* address family: AF_XXX value */
           char     sa_data[14];  /* up to 14 bytes of protocol-specific address */  

 1 Internet family(°¡Á·)¿¡ ´ëÇÏ¿© ´ÙÀ½±¸Á¶ ¿¡ 
   Á¤ÀǵǾî ÀÖ´Ù.

       struct in_addr {
           u_long   s_addr        /* 32-bit netid/hostid */
       };

       struct sockaddr_in {
           short           sin_family;   /* AF_INET */
           u_short         sin_port;     /* 16-bit port number */
           struct in_addr  sin_addr;     /* 32-bit netid/hostid */
           char            sin_zero[8];  /* unused, padding to 16 bytes */
       };

     ¢Í ¿¡ Á¤ÀÇµÈ ¹«ºÎÈ£ µ¥ÀÌŸ Çü
       --------------------------------------------
         C Data Type        4.3 BSD    System V
       --------------------------------------------
         unsigned char      u_char     unchar
         unsigned short     u_short    ushort
         unsigned int       u_int      uint
         unsigned long      u_long     ulong
       --------------------------------------------

 2 Xerox NS °¡Á·¿¡ ´ëÇÏ¿© ´ÙÀ½°ú °°Àº ±¸Á¶ ¿¡ Á¤ÀǵǾî ÀÖ´Ù.

       union ns_host {
           u_char       c_host[6]     /* hostid addr as six bytes  */
           u_short      s_host[3]     /* hostid addr as three 16-bit shorts */
       }

       union ns_net {
           u_char       c_net[4]      /* netid  as four bytes  */
           u_short      s_net[2]      /* netid  as two 16-bit shorts */
       }

       struct ns_addr {
           union ns_net  x_net;        /* 4-byte netid */
           union ns_host x_host;       /* 6-byte hostid */
           u_short       x_port;       /* 2-byte port (XNS "socket") */
       };

       struct sockaddr_ns {
           u_short         sns_family;   /* AF_NS */
           struct ns_addr  sns_addr;     /* the 12-byte XNS address */
           char            sns_zeor[2];  /* unused */
       };
       #define sns_port  sns_addr.x_port

 3 À¯´Ð½º ¹üÁÖ¿¡ ´ëÇÏ¿© ´ÙÀ½±¸Á¶´Â ¿¡ Á¤ÀǵǾî ÀÖ´Ù. 

       struct sockaddr_un {
            short        sun_family;     /* AF_UNIX */
            char         sun_path[108];  /* pathname */
       };





 ¡Ù XX_family ±¸¼º¿øÀÎ À̵é ÁÖ¼Ò ±¸Á¶Áß Ã³À½ µÎ ¹ÙÀÌÆ®ÀÇ ¼±¾ðÀÌ ÀÏÄ¡ÇÏÁö ¾Ê´Â´Ù.
    Internet°ú À¯´Ð½º¹üÁÖ ±¸¼º¿øµéÀº ªÀº Á¤¼ö·Î ¼±¾ðµÇ¾î ÀÖ´Â ¹Ý¸é, 
    XNS ±¸¼º¿ø°ú ÀϹÝÀûÀÎ sockaddr±¸¼º¿øÀº ¹«ºÎÈ£ ªÀº Á¤¼öÀÌ´Ù. 
    ´ÙÇེ·´°Ôµµ AF_XXX »ó¼öµé¿¡ ÀúÀåµÇ´Â °ªµéÀº ¸ðµÎ 1°ú 20»çÀÌÀ̹ǷΠ
    µ¥ÀÌŸ Çü¿¡ À־ ÀÌ·¯ÇÑ ºÒÀÏÄ¡´Â ¹®Á¦°¡ µÇÁö ¾Ê´Â´Ù.  


        ¡ß  Internet, XNS, Unix °¡Á·¿¡ ´ëÇÑ ¼ÒÄÏÁÖ¼Ò ±¸Á¶  ¡ß

      struct sockaddr_in         struct sockaddr_ns     struct sockaddr_un
      ------------------         ------------------     -------------------
      |    family      |         |     family     |     |     family      | 
      ------------------         ------------------     -------------------
      |   2-byte port  |         |  4-byte net ID |     |                 |
      ------------------         ------------------     |                 |
      |    4-byte      |         |                |     |                 |
      | net ID,host ID |         |                |     |     pathname    |
      ------------------         | 6-byte host ID |     |(up to 108 bytes)|
      |                |         |                |     |                 |
      |                |         |                |     |                 |
      |    (unused)    |         ------------------     |                 |
      |                |         |  2-byte port   |     |                 |
      |                |         ------------------     |                 |
      |                |         |    (unused)    |     |                 |
      ------------------         ------------------     -------------------
      
 ¢Ñ Address family ´Â ¿¡ Á¤ÀǵÇÀÖÀ½
   
     #define AF_UNIX     1      /* local to host (pipes, portals) */
     #define AF_INET     2      /* internetwork: UDP, TCP, etc. */
     #define AF_NS       6      /* XEROX NS protocols */

 ¢Ñ ¼ÒÄÏ Á¢¼ÓÀÇ ¼³°èÀÚ´Â ¼ÒÄÏ ÁÖ¼Ò ±¸Á¶¸¦ Á¤ÀÇÇϱâ À§Çؼ­ CÀÇ unionÀ» 
    »ç¿ëÇÒ ¼öµµ ÀÖ´Ù. ±× ¼±¾ðÀº ´ÙÀ½°ú °°ÀÌ ÀÛ¼ºÇÒ ¼ö ÀÖ´Ù.

     struct sock_addr {
        short   sa_family;       /*  AF_XXX value */ 
        union {
           struct sockaddr_in sa_in;   /* Internet address */
           struct sockaddr_ns sa_ns;   /* XNS address */
           struct sockaddr_un sa_un;   /* Unix address */
        } sa_val;
      };

     ÀÌ·¯ÇÑ Á¢±Ù¹æ¹ýÀÇ ¹®Á¦´Â unionÀÇ Å©±â°¡ À¯´Ð½º ¹üÁÖ ÁÖ¼Ò Å©±âÀÎ °¡Àå Å« 
     ±¸¼º¿øÀÇ Å©±â¿¡ ÀÇÇÏ¿© °áÁ¤µÈ´Ù´Â °ÍÀÌ´Ù. ÀÌ´Â Internet°ú XNSÁÖ¼Ò°¡ °¢°¢ 
     8¹ÙÀÌÆ®¿Í 14¹ÙÀÌÆ®¸¸ ÇÊ¿ä·Î ÇÒÁö¶óµµ ¸ðµç sock_addr ±¸Á¶ÀÇ Å©±â¸¦ 
     110¹ÙÀÌÆ®°¡ µÇ°Ô ÇÑ´Ù (ÀÌ °æ¿ì¿¡ Internet sockadd_inÀÇ ¸¶Áö¸· ºÎºÐ¿¡ 
     0À¸·Î ±¸¼ºµÈ 8¹ÙÀÌÆ®¿Í XNS sockaddr_nsÀÇ ¸¶Áö¸· ºÎºÐ¿¡ 0À¸·Î ±¸¼ºµÈ 
     2¹ÙÀÌÆ®°¡ ÇÊ¿ä¾ø´Ù´Â »ç½Ç¿¡ ÁÖÀÇ)

Revision History

ÀÛ¼ºÀÏÀÚ : 96.10.11
ÀÛ¼ºÀÚ : ÀÌÁø¼ö

¼öÁ¤ÀÏÀÚ :
¼öÁ¤ÀÚ :