http://www.hackerschool.org/HS_Boards/zboard.php?id=Free_Lectures&no=32 [º¹»ç]
_____ _______
/ __ \ |___ (_)
| / \/ ___ _ __ ___ / / _ _ __ ___
| | / _ \| '__/ _ \ / / | | '_ \ / _ \
| \__/\ (_) | | | __/./ /__| | | | | __/
\____/\___/|_| \___|\_____/_|_| |_|\___|
------[ Corezine volume 01 - Juli 1999
Corezine #01
==================
=+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+=
The *beginners* guide to sockets in C
By: xphantom
=+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+=
¹ø¿ª : Anesra (anesra@hanmail.net)
/*
´Ã ÇÏ´Â ¸»ÀÌÁö¸¸ ¹ø¿ª»ó ÀÌ»óÇÑ°ÍÀ̳ª ¹«½¼ ÇÒ¸»ÀÌ ÀÖÀ¸½Å ºÐÀº Àú ¸ÞÀÏ·Î º¸³»Áֽñâ
¹Ù¶ø´Ï´Ù
*/
´ç½ÅÀÌ ´Ù¸¥ ÄÄÇ»ÅÍ¿¡ ¿¬°áÇϱ⠿øÇÑ´Ù¸é ¾î¶»°Ô ÇÁ·Î±×·¥À» ¸¸µå´Â°¡?
´ç½ÅÀº ³×Æ®¿öÅ©»ó¿¡ ¾î¶² Á¤º¸µµ ãÀ» ¼ö ¾ø´Ù. ´ç½ÅÀº ¸Ç ÆäÀÌÁö¿¡ ÀÖ´Â °ÍÀ»
º¼ °ÍÀΰ¡? ¾î¶² Ã¥À» º¼ °ÍÀΰ¡? ±Û½ê, ´ç½ÅÀº ¿ÇÀº Àå¼Ò¿¡ °¥ ¼ö ÀÖ´Ù.
ÀÌ ¹®¼¿¡¼ ³ª´Â ´ç½ÅÀÌ C·Î½á ÀÎÅÍ³Ý ¾îÇø®ÄÉÀ̼ÇÀ» ÇÁ·Î±×·¡¹Ö ÇÒ¼ö ÀÖ°Ô
µµ¿òÀ» ÁÖ´Â °ÍÀ» ¿øÇÑ´Ù. ÀÌ ¹®¼¿¡¼ ÃÖ¼ÒÇÑ C¿¡ ¾î´ÀÁ¤µµ ¾Ë°íÀÖ´Ù°í °¡Á¤ÇÏ°í
±×°ÍÀÇ ¹®¹ý°ú ¶ÇÇÑ À¯´Ð½º ¶Ç´Â ¸®´ª½º»ó¿¡¼ »ç¿ëÇغ» ÀûÀÌ ÀÖ´Ù°í °¡Á¤ÇÑ´Ù.
ÀÌ ¹®¼¿¡ Æ÷ÇÔµÈ ¸ðµç ÄÚµå¿Í ¼³¸íÀº glibc 2.07°ú libc5.3.12¸¦ »ç¿ëÇÏ´Â
·¹µå Çò 5.2 »ó¿¡¼ ÄÄÆÄÀÏ µÇ¾ú°í ¸ðµç ÄÚµåµéÀÌ Àß ¼öÇàµÇ¾ú´Ù.
ÀÚ ÀÌÁ¦ ÇÔ²² Çغ¸ÀÚ
ÇÁ·Î±×·¡¸Ó¿¡°Ô, ¼ÒÄÏÀº low levelÀÇ ÆÄÀÏ ±â¼úÀÚ(´ç½ÅÀÌ »ç¿ëÇÏ´Â ¼ÒÄÏÀÇ
read() ¿Í write() ÇÔ¼ö)¿Í ¸Å¿ì À¯»çÇÏ´Ù. ºñ·Ï ¼ÒÄÏ ±× ÀÚü¸¦ »ý¼ºÇÏ´Â °ÍÀÌ
´ç½Å ÀÚ½ÅÀÇ ÇÏµå µð½ºÅ©·Î ºÎÅÍ ¾²°í Àд °Í°ú ºñ±³ÇÏ¿© ³×Æ®¿öÅ© ¿¬°áÀÇ
º¹À⼺ÀÇ ÀÌÀ¯·Î ÆÄÀÏ¿¡ ÀÐ°í ¾²°í ¿©´Â °Íº¸´Ù ´õ º¹ÀâÇÒ Áö¶óµµ
´ëºÎºÐ ¼ÒÄÏÀ» »ç¿ëÇϱâ À§Çؼ, ´ç½ÅÀº Ŭ¶óÀ̾ðÆ®¿Í ¼¹ö ½ÖÀÌ ÇÊ¿äÇÏ´Ù. ¼¹ö°¡
ÇÏ´Â ÀÏÀº Ưº°ÇÑ Æ÷Æ®¿¡¼ ±â´Ù¸®°í Ŭ¶óÀ̾ðÆ®·ÎºÎÅÍ ¿äûÀ» ¹Þ¾ÒÀ» ¶§ ¾î¶²
ÀÏÀ» ¼öÇàÇÏ´Â °ÍÀÌ´Ù. Ŭ¶óÀ̾ðÆ®ÀÇ ÀÏÀº(¸íÈ®È÷) ¾î¶² °ÍÀ» Çϱâ À§ÇØ ÇÁ·Î±×·¡¹Ö
µÇ¾îÁø ¹«½¼ ÀÏÀÌµç ½ÇÇàÇϱâ À§Çؼ ¼¹ö¿¡ "ask"¸¦ ÇÏ´Â °ÍÀÌ´Ù.
¿ì¸®´Â ÀÌ ¹®¼¿¡¼ *¸ðµç* ¼ÒÄÏ Å¸ÀÔ ÇÔ¼ö¸¦ »ç¿ëÇÏÁö ¾ÊÀ» °ÍÀÌ´Ù. ÀÌ°ÍÀº Ãʺ¸ÀÚ¸¦
À§ÇÑ Áöµµ¼À̱⠶§¹®¿¡, ±×·¯³ª Áñ°Å¿òÀ» ¾ò°í ´ç½ÅÀÇ ½Ç·ÂÀ» ³ôÀ̱â À§ÇÑ Á¤º¸¸¦ ¾ò±â¿£
ÃæºÐÇÒ °ÍÀÌ´Ù. ÀÚ ÀÌÁ¦ ¸î°³ÀÇ ¼ÒÄÏÀ» ¸¸µé¾î º¸ÀÚ.
=+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+=
¼ÒÄÏÀ» »ý¼º : socket()
´ç½ÅÀÇ ¼ÒÄÏ ÇÁ·Î±×·¡¹ÖÀ» Çϱâ À§Çؼ °¡Àå ¸ÕÀú ÇؾßÇÒ ÀÏÀº socket()ÇÔ¼ö¸¦
»ç¿ëÇÏ¿© ¼ÒÄÏÀ» »ý¼ºÇÏ´Â ÀÏÀÌ´Ù.
-------
#include <sys/types.h>
#include <sys/socket.h>
int socket(int af, int type, int protocol)
------
'int af'´Â ¼ÒÄÏ µµ¸ÞÀΰú ÁÖ¼Ò Æйи® ºÎºÐÀ̸ç. ´ëºÎºÐ µÎ°¡Áö¸¦ »ç¿ëÇÑ´Ù.
AF_UNIX - ÇÑ È£½ºÆ®³»¿¡¼ »óÈ£ Åë½ÅÇϱâ À§Çؼ »ç¿ëµÈ´Ù.
AF_INET - °°°Å³ª ¶Ç´Â ´Ù¸¥ DARPAÇÁ·ÎÅäÄÝ(UDP/TCP/IP)¸¦ »ç¿ëÇÏ´Â ½Ã½ºÅÛ
°£ÀÇ »óÈ£ Åë½ÅÀ» Çϱâ À§Çؼ »ç¿ëµÈ´Ù.
'int type'Àº ´ç½ÅÀÌ »ç¿ëÇÒ ¿¬°áÀÇ ÇüÅ°¡ ¹«¾ùÀÎÁö, ´ëºÎºÐ µÎ°¡Áö¸¦ »ç¿ëÇÑ´Ù.
SOCK_STREAM - ¿¬°á ÁöÇâÀûÀÎ ¼ÒÄÏÀ» À§ÇØ »ç¿ëµÈ´Ù. µ¥ÀÌŸ Àü¼ÛÀÌ º¸ÁõµÇ°í,
±×·¸Áö ¾ÊÀ¸¸é ¹ÞÀº °÷¿¡ ÀÇÇØ ¿¡·¯°¡ Àü¼ÛµÉ°ÍÀÌ´Ù.
SOCK_DGRAM - ¿¬°áÀÌ ´ú ÇÑ ¼ÒÄÏÀ» À§ÇØ »ç¿ëµÈ´Ù. µ¥ÀÌŸ º¸ÀåÀÌ ¾øÀÌ Àü¼ÛµÈ´Ù.
ÀÌ ¹®¼¿¡¼´Â ¿ì¸®´Â family AF_INET°ú SOCK_STREAM ŸÀÔ¿¡ ÁßÁ¡À» µÑ °ÍÀÌ´Ù.
'int protocol'Àº º¸Åë protocal°ªÀÌ 0ÀÌ´Ù. ÀÌ°ÍÀº ½Ã½ºÅÛÀÌ family¿Í typeÀ» À§ÇÑ
Ưº°ÇÑ °ªÀÇ ½ÖÀ¸·Î Çã¶ôµÇ¾îÁø ù¹ø° ÇÁ·ÎÅäÄÝÀ» ¼±ÅÃÇϱâÀ§ÇØ Çã¶ôµÇ¾îÁø´Ù.
¼º°øÇϸé, ÆÄÀÏ ±â¼úÀÚ°¡ ¸®ÅÏÇÏ°í, ½ÇÆÐÇϸé -1À» ¸®ÅÏÇÏ°í errno°¡ ±×°Í¿¡ ¾Ë¸Â°Ô
¼³Á¤µÉ °ÍÀÌ´Ù.
------
#include <sys/types.h>
#include <sys/socket.h>
int sockfd /* soon to be socket file descriptor */
sockfd = socket(AF_INET, SOCK_STREAM, 0)
/* error checking here */
------
±×¸®°í ¸¸ÀÏ ¸ðµç°ÍÀÌ Àß ¼öÇàµÇ¾úÀ¸¸é, ¿ì¸®´Â ¿ì¸®°¡ ¿¬°áÁöÇâÀûÀÎ ±âº»ÀûÀÎ
ÇÁ·ÎÅäÄÝ(SOCK_STREAM)À» »ç¿ëÇÏ´Â ÀÎÅͳÝ(AF_INET)À» ÅëÇؼ »ç¿ëÇÒ¼ö ÀÖ´Â
¼ÒÄÏ ±â¼úÀÚ¸¦ °¡Áø´Ù. protocol(0)Àº ÀÚµ¿ÀûÀ¸·Î ¿ì¸®¿¡ ÀÇÇؼ ¼³Á¤µÈ´Ù´Â °ÍÀ» ±â¾ïÇ϶ó.
=+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+=
´ç½ÅÀÇ ¼ÒÄÏÀ» »ç¿ëÇϱâ À§ÇÑ À̸§À» ÁÖ¾î¶ó : bind()
ÁÁ´Ù, Áö±Ý ¿ì¸®´Â ¿ì¸®ÀÇ ¼ÒÄÏÀ» »ý¼ºÇÏ¿´´Ù. ´ÙÀ½À¸·Î ÇÒ °ÍÀº ±×°Å¿¡ ¾î¶²ÀÏÀ» ÇÒ¼ö ÀÖ°Ô
Çϴ°ÍÀÌ ÇÊ¿äÇÏ´Ù. À̸§À» »ç¿ëÇϱâ À§ÇØ bind()¸¦ Áִ°ÍÀ» ½ÃµµÇ϶ó.
------
#include <sys/types.h>
#include <sys/socket.h>
int bind(int sockfd, struct sockaddr *name, int namelen)
------
bind()¸¦ È£ÃâÇ϶§ ÀÎÀÚÀÎ, sockfd´Â ¼ÒÄÏÀ» À§ÇÑ ÆÄÀÏ ±â¼úÀÚÀÌ°í, socket()À»
È£ÃâÇϱâ À§ÇØ ¾ò´Â °ÍÀ̸ç, NameÀº sockaddrŸÀÔ ±¸Á¶Ã¼ÀÇ Æ÷ÀÎÅÍÀÌ´Ù.
¸¸ÀÏ address family°¡ AF_UNIX(¼ÒÄÏÀÌ »ý¼ºµÉ¶§ ÁöÁ¤µÇ¾îÁø °ÍÀ̶ó¸é)À̸é,
±¸Á¶Ã¼´Â ¾Æ·¡¿Í °°ÀÌ Á¤ÀÇ µÉ °ÍÀÌ´Ù.
------
struct sockaddr {
u_short sa_family;
char sa_data[14];
};
------
name.sa_family´Â AF_UNIT·Î µÇ¾îÁú °ÍÀÌ´Ù. name.sa_data´Â ¼ÒÄÏÀ» ÇÒ´çÇϱâ À§Çؼ
»ç¿ëµÈ ÆÄÀÏ À̸§ÀÇ 14byte¸¦ °¡Áú°ÍÀÌ´Ù. namelenÀº µ¥ÀÌÅÍ ±¸Á¶¸¦ Æ÷ÇÔÇÏ´Â ÃʱâȵÈ
±æÀÌÀÎ nameÀÇ ½ÇÁ¦ ±æÀÌ·Î ÁÖ¾îÁø´Ù.
------
#include <sys/types.h>
#include <sys/socket.h>
struct sockaddr name;
int sockfd;
name.sa_family = AF_UNIX;
strcpy(name.sa_data, "/tmp/whatever");
sockfd = socket(AF_UNIX, SOCK_STREAM, 0)
/* error checking code here */
bind(s, &name, strlen(name.sa_data) + sizeof(name.sa_family)
/* error checking code here */
------
¿¡·¯ üŷ ÅëÁö : bind()°¡ ¼º°øÇϸé 0À», ½ÇÆÐÇϸé bind()´Â -1À» ¸®ÅÏÇÏ°í
±×°Í¿¡ ¾Ë¸Â°Ô errno¸¦ ¼³Á¤ÇÑ´Ù.
ÀÌÁ¦, AF_INETÀ» »ç¿ëÇÏ´Â bind¸¦ È£ÃâÇÒ¶§ ¿ì¸®´Â ´Ù¸¥ ±¸Á¶Ã¼¸¦ »ç¿ëÇÑ´Ù.
-----
struct sockaddr_in {
short int sin_family; /* Address family */
unsigned short int sin_port; /* Port number */
struct in_addr sin_addr; /* Internet address */
unsigned char sin_zero[8]; /* Same size as struct sockaddr */
};
------
ÀÌ°ÍÀº Á¶±Ý ´õ Å©°í ´õ º¹ÀâÇϳª ¾î·Á¿î°ÍÀº ¾Æ´Ï´Ù. ¾Æ·¡¿Í °°Àº
¿¹¸¦ º¸ÀÚ.
------
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <errno.h>
int sockfd, port = 23;
struct sockaddr_in my_addr;
if((sockfd=socket(AF_INET, SOCK_STREAM, 0)) == -1)
{
printf("Socket Error,
exit(1);
}
my_addr.sin_family = AF_INET; /* host byte order */
my_addr.sin_port = htons(port); /* see man htons for more information */
my_addr.sin_addr.s_addr = htonl(INADDR_ANY); /* get our address */
bzero(&(my_addr.sin_zero), 8); /* zero out the rest of the space */
if((bind(sockfd, (struct sockaddr *)&my_addr, sizeof(struct sockaddr)) == -1)
{
printf("Bind Error,
close(sockfd);
exit(1);
}
------
ÀÚ, ¸¸ÀÏ ¸ðµç °ÍÀÌ Àß µÇ¾ú´Ù¸é, ¿ì¸®ÀÇ ¼ÒÄÏÀº Áö±Ý À̸§À» °¡Áú °ÍÀÌ°í, ¸¸ÀÏ
¸ðµç°ÍÀÌ Àß µÇÁö ¾Ê¾Ò´Ù¸é, ¿¡·Î°¡ ¹ß»ýÇÒ °ÍÀÌ°í ÇÁ·Î±×·¥Àº Á¾·áµÉ °ÍÀÌ´Ù.
Á¶±Ý ÀÛÀº ¸Þ¸ð - ¸¸ÀÏ ¸ðµç ´ç½ÅÀÇ ÇÁ·Î±×·¥ÀÌ ´Ù¸¥ ÄÄÇ»ÅÍ¿¡ ¿¬°áµÇ°í,
´ç½ÅÀº ÀüÇô bind()ÇÔ¼öÀÇ »ç¿ëÀÌ ÇÊ¿äÇÏÁö ¾ÊÀ»¼öµµ ÀÖ´Ù(ºñ·Ï ±×°ÍÀÌ ¾î¶² °Í¿¡
¼Õ»óÀ» ÀÔÈ÷Áö ¾Ê´Â´Ù¸é). ÀÌ ¶óÀÎ : my_addr.sin_port = htons(port); Àº
¿ì¸®ÀÇ Æ÷Æ®°¡ ´ÜÁö 0À¸·Î ¼ÂÆÃÇÔÀ¸·Î½á ÀÚµ¿ÀûÀ¸·Î Á¤ÇØÁú¼ö ÀÖ°í, Ŭ¶óÀ̾ðÆ® ÇÁ·Î±×·¥Àº
ÁÁÀ» °ÍÀ̳ª, ´ç½ÅÀÌ ±×°ÍÀÌ ¹«½¼ Æ÷Æ®¸¦ »ç¿ëÇÏ´ÂÁö ¾Ë¼ö ¾ø±â ¶§¹®¿¡ ¼¹ö ÇÁ·Î±×·¥À»
À§Çؼ´Â ³ª»Ú´Ù.
=+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+=
¿ø°Ý ¿¬°áÀ» À§ÇØ »ç¿ë : connect()
¸¸ÀÏ ´ç½ÅÀÌ ¿ø°Ý ¸Ó½Å¿¡ ¿¬°áÇϱ⠿øÇÑ´Ù¸é, connect()ÇÔ¼ö¸¦ »ç¿ëÇÏ¿©¾ß ÇÑ´Ù.
------
#include <sys/types.h>
#include <sys/socket.h>
int connect(int sockfd, struct sockaddr *serv_addr, int addrlen);
------
sockfd´Â socket()À» È£ÃâÇÏ°í ³ª¼ ¸®ÅϵǴ ¿ì¸®ÀÇ Ä£±ÙÇÑ ¼ÒÄÏ ÆÄÀÏ ±â¼úÀÚÀÌ´Ù.
serv_addr´Â ¸ñÀûÁö Æ÷Æ®¿Í IPÁÖ¼Ò¸¦ °¡Áö°í ÀÖ´Â sockaddr±¸Á¶Ã¼ÀÌ´Ù.
addrlenÀº sizeof(struct sockaddr)·Î ¼³Á¤ÇÒ¼ö ÀÖ´Ù.
ÀÚ ´Ù¸¥ ¿¹Á¦¸¦ º¸ÀÚ.
------
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#define DEST_IP "132.241.5.10"
#define DEST_PORT 23
main()
{
int sockfd;
struct sockaddr_in dest_addr; /* will hold the destination addr */
sockfd = socket(AF_INET, SOCK_STREAM, 0); /* do some error checking! */
dest_addr.sin_family = AF_INET; /* host byte order */
dest_addr.sin_port = htons(DEST_PORT); /* short, network byte order */
dest_addr.sin_addr.s_addr = inet_addr(DEST_IP);
bzero(&(dest_addr.sin_zero), 8); /* zero the rest of the struct */
connect(sockfd, (struct sockaddr *)&dest_addr, sizeof(struct sockaddr));
/* error checking code here */
/* more code
.
.
.
*/
}
------
¶Ç, connect()´Â ¼º°øÇϸé 0À» ¸®ÅÏÇÏ°í ½ÇÆÐÇϸé -1À» ¸®ÅÏÇÏ°í errno¸¦ ¼³Á¤ÇÑ´Ù.
´ç½ÅÀº bind()ÇÔ¼ö°¡ ºüÁø°É ´«Ä¡Ã§Áö ¸ð¸¥´Ù. ¿ì¸®´Â ¿¬°áÇϱâ À§ÇØ ¾î¶² Æ÷Æ®¸¦
»ç¿ëÇÒÁö ¸ð¸£±â ¶§¹®¿¡, ÀÌ°Í°ú °°Àº °æ¿ì ¿ì¸®°¡ ¿¬°áÇÏ°íÀÚ ÇÏ´Â Æ÷Æ®¸¸À» »ç¿ëÇÑ´Ù.
(¿ªÀÚ ÁÖ: Ŭ¶óÀ̾ðÆ®¿¡¼ ¾î¶² Æ÷Æ®¸¦ »ç¿ëÇÒÁö Á¤È®È÷ Á¤ÇØÁöÁö ¾Ê¾Ò±â ¶§¹®¿¡ bind()¸¦
»°´Ù´Â ¸».)
=+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+=
È£ÃâÀ» »ç¿ëÇϱâ À§Çؼ ±â´Ù¸² : listen()
¸»ÇßµíÀÌ ¿ì¸®´Â ¾î¶² Æ÷Æ®ÀÇ ¼¹ö ÇÁ·Î±×·¥À» ¸¸µé±â ¿øÇÑ´Ù. ¿ì¸®´Â ¿ì¸®°¡ ¾ËÁö ¸øÇÏ´Â
¾î¶² ¿¬°áÀÌ µé¾î¿À´Â °ÍÀ» À§ÇØ ´ë±âÇϱâ À§ÇÑ ¾î¶² ¹æ¹ýÀÌ ÇÊ¿äÇÏ´Ù.
±×°ÍÀÌ listen()ÇÔ¼öÀÌ¸ç ¾Æ·¡¿Í °°ÀÌ µ¿ÀÛÇÑ´Ù.(±×°ÍÀº Àß ¾ËÁöµµ ¸ð¸¥´Ù;))
------
#include <sys/types.h>
#include <sys/socket.h>
int listen(int sockfd, int backlog);
------
sockfd´Â ¶Ç ¿ì¸®ÀÇ ¼ÒÄÏ ÆÄÀÏ ±â¼úÀÚÀÌ´Ù.
backlog´Â ¿ì¸®°¡ Çѹø¿¡ ¹ÞÀ»¼ö ÀÖ´Â ¿¬°áÀÇ ¼öÀÌ´Ù.
¶Ç, ÀÏ»óÀûÀ¸·Î , listen()Àº ½ÇÆÐÇϸé -1À» ¸®ÅÏÇÏ°í errno¸¦ ¼ÂÆÃÇÑ´Ù.
ÀÌÁ¦ ÀÌ·± °æ¿ì¿¡ ¿ì¸®´Â listen()À» È£ÃâÇϱâ Àü¿¡ bind()È£ÃâÀÌ ÇÊ¿äÇÒ °ÍÀÌ´Ù.
(¿ì¸®´Â ±×µéÀÌ ÃßÃøÇÒ¼ö ÀÖ°Ô ¸¸µéÁö ¾Ê°í ¿¬°áÇϱâ À§ÇÑ »ç¶÷À» À§ÇØ Æ¯Á¤ÇÑ
Æ÷Æ®¸¦ ¿øÇÑ´Ù.)
¿ì¸®ÀÇ ÇÔ¼ö´Â ¾Æ·¡¿Í °°Àº ¼ø¼¸¦ °¡Áø´Ù.
------
socket(); /* to create out socket file descriptor */
bind(); /* to give our socket a name */
listen(); /* listen for connection */
------
=+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+=
¿¬°áÀ» ¹Þ¾Æ µéÀ̱â À§ÇØ »ç¿ë : accept()
‰ç´Ù, ÀÌ°ÍÀº ¾îµð¿¡.. À½.. ¿ô±â°Ô ½ÃÀÛÇÏÀÚ. ¾î¶² »ç¶÷ÀÌ ´ç½ÅÀÌ ±â´Ù¸®°í ÀÖ´Â
Æ÷Æ®¿¡ ¿¬°áÇϱ⸦ ½ÃµµÇß´Ù¸é, ´ç½ÅÀº Áö±Ý ±× ¿¬°áÀ» ¹Þ¾ÆµéÀÏ ÇÊ¿ä°¡ ÀÖ°í
accept()´Â ±×°ÍÀ» ¼öÇàÇÒ°ÍÀÌ´Ù.(´©±ºÁö ¾Ë¾î? ;))
------
#include <sys/types.h>
#include <sys/socket.h>
int accept(int sockfd, void *addr, int *addrlen);
------
¶Ç, sockfd´Â ¿ì¸®ÀÇ Ä£±ÙÇÑ ÆÄÀÏ ±â¼úÀÚÀÌ´Ù.
addrÀº Á¾Á¾ »ç¿ëµÈ struct sockaddr_inÀÇ ±¸Á¶Ã¼¸¦ °¡¸®Å°´Â Æ÷ÀÎÅÍÀÌ´Ù.
addrlenÀº ¼³Á¤ÇÒ °ÍÀÌ´Ù : sizeof(struct sockaddr_in)
¿¡·¯°¡ ¹ß»ýÇÒ¶§ ¸®ÅϵǴ °ªÀ» ÃßÃøÇÒ¼ö Àְڴ°¡?... ´ç½ÅÀº ±×°ÍÀ» ¾Ë°ÍÀÌ´Ù....
-1À» ¸®ÅÏÇÏ°í errno¸¦ ¼³Á¤ÇÑ´Ù. E.G:
------
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#define MYPORT 1500 /* the port users will be connecting to */
#define BACKLOG 5 /* how many pending connections queue will hold */
main()
{
int sockfd, new_fd; /* listen on sock_fd, new connection on new_fd */
struct sockaddr_in my_addr; /* my address information */
struct sockaddr_in their_addr; /* connector's address information */
int sin_size;
sockfd = socket(AF_INET, SOCK_STREAM, 0); /* do some error checking! */
my_addr.sin_family = AF_INET; /* host byte order */
my_addr.sin_port = htons(MYPORT); /* short, network byte order */
my_addr.sin_addr.s_addr = INADDR_ANY; /* auto-fill with my IP */
bzero(&(my_addr.sin_zero), 8); /* zero the rest of the struct */
/* did you remember your error checking? */
bind(sockfd, (struct sockaddr *)&my_addr, sizeof(struct sockaddr));
listen(sockfd, BACKLOG);
sin_size = sizeof(struct sockaddr_in);
new_fd = accept(sockfd, &their_addr, &sin_size);
------
¿ì¸®´Â ¸ðµç send()¿Í recv() È£ÃâÀ» À§ÇØ new_fd ¼ÒÄÏ ±â¼úÀÚ¸¦ »ç¿ëÇÒ °ÍÀ̶ó´Â °ÍÀ»
¾Ë¾Æ¶ó. ¸¸ÀÏ ´ç½ÅÀÌ ¿ÀÁ÷ ÇÑ ¿¬°á¸¸À» ¹Þ´Â´Ù¸é, ´ç½ÅÀÌ ¿øÇÑ´Ù¸é ´ç½ÅÀº °°Àº Æ÷Æ®¿¡
´õ ÀÌ»ó ¿¬°áµÇ´Â °ÍÀ» ¸·±âÀ§ÇØ ¿øº» sockfd¸¦ close()ÇÒ¼ö ÀÖ´Ù.
=+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+=
¿ì¸®°¡ À̾߱â Çϱâ À§Çؼ ÇÊ¿äÇѰ͵é : send() and recv()
ÀÌÁ¦, ¿ì¸®´Â ¼ÒÄÏÀ» »ý¼ºÇÏ¿´°í, À̸§À» ÁÖ¾ú°í, ¿¬°áÀ» ¹Þ¾ÆµéÀ̱âÀ§ÇØ ±â´Ù·È°í,
send()¿Í recv()·Î½á ¼·Î Á¤º¸¸¦ ±³È¯Çϱâ À§ÇÑ ¸¶Áö¸· ½Ã°£ÀÌ´Ù.
------
#include <sys/types.h>
#include <sys/socket.h>
int send(int sockfd, const void *msg, int len, int flags);
int recv(int sockfd, void *buf, int len, unsigned int flags);
------
send():
sockfd - ¼ÒÄÏ ÆÄÀÏ ±â¼úÀÚ
msg - º¸³»±â À§ÇÑ ¸Þ¼¼Áö
len - º¸³»±â À§ÇÑ ¸Þ¼¼ÁöÀÇ Å©±â
flags - ´õ ¸¹Àº Á¤º¸¸¦ À§Çؼ 'man send'¸¦ ÀоîºÁ¶ó, ±×°ÍÀº Áö±ÝÀ» À§Çؼ 0À¸·Î ¼¼ÆÃÇÑ´Ù. :)
recv():
sockfd - ¼ÒÄÏ ÆÄÀÏ ±â¼úÀÚ
buf - ¹Þ±â À§ÇÑ µ¥ÀÌŸ
len - bufÀÇ Å©±â
flags - send()ÀÇ Ç÷¡±×¿Í °°´Ù.
send() example:
------
char *msg = "Hey there people";
int len, send_msg;
/* code to create(), bind(), listen() and accept() */
len = strlen(msg);
bytes_sent = send(sockfd, msg, len, 0);
------
recv() example:
------
char *buf;
int len, recv_msg;
/* code to create(), bind(), listen() and accept() */
len = strlen(buf);
recv_msg = recv(sockfd, buf, len, 0);
------
±×¸®°í ¶Ç, send()¿Í recv()´Â ¿¡·¯°¡ »ý±â¸é -1À» ¸®ÅÏÇÏ°í errno¸¦ ¼³Á¤ÇÑ´Ù.
¸¸ÀÏ ´ç½ÅÀÌ SOCK_DGRAM ÇüŸ¦ »ç¿ëÇÑ´Ù¸é sending¿Í receiving µ¥ÀÌŸ¸¦ À§Çؼ
sendto()¿Í recvfrom()ÇÔ¼ö¸¦ »ç¿ëÇØ¾ß ÇÑ´Ù.
=+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+=
´ç½Å°ú À̾߱âÇؼ Áñ°Å¿ü´Ù : close() ¿Í shutdown()
Çѹø ´ç½ÅÀº µ¥ÀÌÅÍ Àü¼ÛÀ» ¸¶ÃÆÀ¸¸é, ±×°ÍÀº °£´ÜÈ÷ ¼ÒÄÏÀ» ´ÝÀ½À¸·Î½á ¿¬°áÀ»
³¡³½´Ù.
------
#include <stdio.h>
/* all you code */
close(sockfd);
------
Á¤¸» °£´ÜÇÏÁö ¾ÊÀº°¡? ¸¸ÀÏ ´ç½ÅÀÌ ¿¬°á¿¡ ´ëÇؼ ´õ ¸¹Àº ÅëÁ¦¸¦ ¿øÇÑ´Ù¸é
shutdown()ÇÔ¼ö¸¦ »ç¿ëÇضó.
------
int shutdown(int sockfd, int how)
------
how¸¦ À§Çؼ´Â ¼¼ °³ÀÇ ´Ù¸¥ °ªµéÀÌ ÀÖ´Ù.
1 - no more revc()'s allowed
2 - no more sends are allowed
3 - no more send()'s or recv()'s allowed (same as close())
1 - ´õÀÌ»ó recv()¸¦ Çã¶ôÇÏÁö ¾Ê´Â´Ù.
2 - ´õ ÀÌ»ó send¸¦ Çã¶ôÇÏÁö ¾Ê´Â´Ù.
3 - ´õÀÌ»ó send()¶Ç´Â revc()¸¦ Çã¶ôÇÏÁö ¾Ê´Â´Ù(close()¿Í °°´Ù)
±×°ÍÀº ½±´Ù. ´ç½ÅÀº Áö±Ý ¼ÒÄÏÀ» »ý¼ºÇÏ°í, ±×°Í¿¡ À̸§À» ÁÖ°í, ¿¬°áÀ» À§Çؼ
±â´Ù¸®¸ç, ¿¬°áÀ» ¹Þ¾ÆµéÀÎµÚ ´Ù¸¥ ÄÄÇ»ÅÍ¿Í ¿¬°áÇÏ°í ±×¸®°í ¼ÒÄÏÀ» ´Ý´Â´Ù.
¾î·ÆÁö ¾ÊÁö? ¾û?
=+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+=
³Ê´Â ´©±¸³Ä : getpeerbyname()
±×¸®°í ³ª¼ ´ç½ÅÀº ´ç½Å¿¡°Ô ¿¬°áÇÑ ÀÚ°¡ ´©±¸ÀÎÁö ¾Ë±â¸¦ ¿øÇÏÁö ¾Ê´Â°¡? ±Û½ê
´ç½ÅÀº Çà¿î¾Æ´Ù! ´ÜÁö ±× ¸ñÀûÀ» À§ÇÑ ÇÔ¼ö°¡ ¿©±â¿¡ ÀÖ´Ù.
------
#include <sys/socket.h>
int getpeername(int sockfd, struct sockaddr *addr, int *addrlen);
------
sockfd - ¿ì¸®ÀÇ Ä£±ÙÇÑ ¼ÒÄÏ ÆÄÀÏ ±â¼úÀÚÀÌ´Ù
addr - 'struct sockaddr' ¶Ç´Â 'struct sockaddr_in'À» °¡¸®Å°´Â Æ÷ÀÎÅÍÀÌ´Ù
addrlen - ¸¸µé¾î¾ß ÇÑ´Ù : sizeof(struct sockaddr)
ÀÌ·± ÀÌ·±, getpeerbyname()¶ÇÇÑ ¿¡·¯°¡ ¹ß»ýÇϸé -1À» ¸®ÅÏÇϳ×. ´©±¸³ª ÀÌ°ÍÀ» ÃßÃøÇÒ¼ö
ÀÖ°ÚÁö? ¸¸ÀÏ ÀÌ°ÍÀÌ Àß µ¿ÀÛÇÑ´Ù¸é, ´ç½ÅÀº Áö±Ý ´ç½Å¿¡°Ô ¿¬°áÇÑ »ç¶÷ÀÇ ÁÖ¼Ò¸¦
¾òÀ» ¼ö ÀÖ°í ±×¸®°í inet_ntoa() ¶Ç´Â gethostbyaddr()¸¦ »ç¿ëÇÏ¿© ´õ ¸¹Àº Á¤º¸¸¦
¾òÀ» ¼ö ÀÖ°í, ¿©±â¿¡ ´ëÇؼ´õ ¸¹Àº °ÍÀ» ¾Ë°í ½ÍÀ¸¸é identdÀÌ µ¿ÀÛÇÏÁö ¾Ê´Â´Ù¸é
±×µéÀÇ ·Î±ä ³×ÀÓÀ» ¾Ë¼ö ¾øÀ»°ÍÀÌ´Ù.
ÀÌ°Í¿¡ ´ëÇÑ ´õ ÀÚ¼¼ÇÑ Á¤º¸¸¦ ¾Ë°í½Í´Ù¸é RFC 1413À» ÀоîºÁ¶ó.
=+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+=
³ª´Â ´©±¸Àΰ¡ : gethostname()
‰ç´Ù, getpeerbyname()Àº ½¬¿ü´Ù, ÃæºÐÈ÷, gethostname()´Â ´õ ½±´Ù.
------
#include <unistd.h>
int gethostname(char *hostname, size_t size);
------
hostname - ¸®ÅÏµÉ È£½ºÆ® À̸§À» ÀúÀåÇÒ ¼ö ÀÖ´Â charÇüÅÂÀÇ ¹è¿
size - ¹è¿¿¡ ÀÇÇØ ¾ð±ÞµÈ ÀÌ»óÀÇ Å©±â
ÀÌ°ÍÀº ÄÄÇ»ÅÍÀÇ À̸§À» ¸®ÅÏÇÑ´Ù. ´ç½ÅÀÇ ÇÁ·Î±×·¥ÀÌ µ¹¾Æ°£´Ù¸é ´ç½ÅÀÇ IP address
¸¦ gethostbyname()À» »ç¿ëÇÔÀ¸·Î½á ¾Ë¼ö ÀÖ´Ù. ¶ÇÇÑ ½ÇÆÐÇϸé -1À» ¸®ÅÏÇÑ´Ù.
=+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+=
³ÊÀÇ IP´Â ¹«¾ùÀ̳Ä?
ÃæºÐÈ÷, »ç¿ëÇÒ Á¤º¸¸¦ ¾òÀ¸·Î °¡ÀÚ. ¿ÀÄÉ? ¿ì¸®´Â Àüü ÇÁ·Î±×·¥, DNS program,
À» ¸¸µé±â À§Çؼ óÀ½ÇÒ °ÍÀ» ¸¸µéÀÚ. DNS ¶Ç´Â "Domain Name Service"´Â
±×°ÍÀÇ "human-readbale"ÁÖ¼Ò¸¦ »ç¿ëÇÔÀ¸·Î½á ±â°èÀÇ IP ÁÖ¼Ò¸¦ ¾òÀ» ¼ö ÀÖ´Â ¹æ¹ýÀÌ´Ù.
$ telnet microsoft.com
Trying 206.163.24.176 (not the real address but I'm too lazy to try :))
ÃæºÐÈ÷ ¹«¾ùÀΰ¡¸¦ ÃßÃøÇÑ´Ù, ¸ÕÀú ÅÚ³Ý ÇÁ·Î±×·¥Àº microsoft.comÀÇ DNS¸¦ üũÇÏ°í
±×°ÍÀÇ IP¸¦ ¾ò¾î¿Â´Ù. ÀÌÁ¦, ÀÌ°ÍÀº netdb.h¿¡¼ ãÀ» ¼ö ÀÖ´Â gethostbyname()ÇÔ¼ö¸¦
»ç¿ëÇÑ´Ù.
------
#include <netdb.h>
struct hostent *gethostbyname(const char *name);
------
ÀÌ°ÍÀ» º½À¸·Î½á ´ç½ÅÀº 'struct hostend'¸¦ È£ÃâÇÏ´Â ±¸Á¶Ã¼¸¦ »ç¿ëÇÏ´Â °ÍÀ» º¼¼ö ÀÖ´Ù.
------
struct hostent {
char *h_name;
char **h_aliases;
int h_addrtype;
int h_length;
char **h_addr_list;
};
#define h_addr h_addr_list[0]
------
ÀÌ ±¸Á¶Ã¼´Â ¾Æ·¡¿Í °°Àº Á¶°¢µé·Î µÇ¾îÀÖ´Ù.
h_name - È£½ºÆ®ÀÇ °ø½ÄÀûÀÎ À̸§
h_aliases - È£½ºÆ®¸¦ À§ÇÑ ³Î·Î ³¡³ª´Â ±³´ëÀÇ À̸§ÀÇ ¹è¿.
h_addrtype - ¸®ÅϵǴ ¾îµå·¹½º ŸÀÔ; ÁÖ·Î AF_INET.
h_length - bytes·Î µÈ ÁÖ¼ÒÀÇ ±æÀÌ
h_addr_list - È£½ºÆ®¸¦ À§ÇÑ 0À¸·Î ³¡³ª´Â ³×Æ®¿öÅ© ÁÖ¼ÒÀÇ ¹è¿.
È£½ºÆ® ÁÖ¼Ò´Â Network Byte OrderÀÌ´Ù.
h_addr - h_addr_list¿¡ Àִ ù¹ø° ÁÖ¼Ò
gethostbyname()Àº struct hostent¸¦ ä¿ì±â À§ÇÑ Æ÷ÀÎÅ͸¦ ¸®ÅÏÇÑ´Ù, ±×·¸Áö ¾Ê°í
¿¡·¯°¡ ¹ß»ýÇϸé NULLÀ» ¸®ÅÏÇÑ´Ù.(±×·¯³ª errno´Â ¼³Á¤µÇÁö ¾Ê´Â´Ù-h_errno°¡ ´ë½Å
¼³Á¤µÈ´Ù. ´õ ¸¹Àº µµ¿òÀ» ¾ò±â À§Çؼ± 'man herrno'¸¦ ºÁ¶ó) ÀÌÁ¦ ¿ì¸®ÀÇ DNSÇÁ·Î±×·¥À»
¸¸µé¾î º¸ÀÚ.
------
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <netdb.h>
#include <sys/types.h>
#include <netinet/in.h>
int main(int argc, char *argv[])
{
struct hostent *h;
if (argc != 2) { /* error checking on the command line */
fprintf(stderr,"Usage: getip <host name>\n");
exit(1);
}
if ((h=gethostbyname(argv[1])) == NULL) { /* get the host info */
herror("gethostbyname");
exit(1);
}
printf("Host name : %s\n", h->h_name);
printf("IP Address : %s\n",inet_ntoa(*((struct in_addr *)h->h_addr)));
return 0;
}
------
±×¸®°í ÀÌÁ¦ º¸ÀÚ, ÀÛ°í ½±Áö ¾ÊÀº°¡, ´ÜÁö ¿ì¸®´Â ÀÌ·¸°Ô ¸¸µé°í, ±×°ÍÀ» ´ÙÀ½°ú °°ÀÌ
ÄÄÆÄÀÏ ½ÃÅ°¸é µÈ´Ù
:gcc -o getip getip.c(¿ì¸®´Â Àú°ÍÀ» getip.c·Î ÀúÀåÇß´Ù°í °¡Á¤ÇÑ´Ù :))
=+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+=
Ŭ¸®¾î¾ðÆ® ¿Í ¼¹ö ÇÁ·Î±×·¥
¿ÀÄÉ, ¸¶Áö¸·À¸·Î Àڱ׸¶ÇÑ , ±×¸®°í ´Ù¼Ò ¹«ÀǹÌÇÑ, Ŭ¸®À̾ðÆ®-¼¹ö ¾îÇø®ÄÉÀ̼ǿ¡
´ëÇؼ Åä·ÐÇغ¸ÀÚ. ¿ÀÁ÷ ÀÌ°Í¿¡ ´ëÇÑ ¸ñÀûÀº ¼¹ö¿¡ ¿¬°áÇÏ°í, ÀÌ¹Ì ÁöÁ¤µÈ ½ºÆ®¸µÀ»
¹Þ°í, ±×¸®°í ¿¬°áÀ» ²ö±â À§ÇÑ »ç¿ëÀÚ¸¦ À§Çؼ ÀÌ´Ù.
±×·¯³ª ±×°ÍÀº ¾î¶² Á¡À» ¾òÀ» ¼ö ÀÖÀ¸¸ç, ³ª´Â ´ç½ÅÀÌ ÀÌ°ÍÀ¸·Î ºÎÅÍ ´õ À¯¿ëÇÑ °ÍÀ»
¸¸µé ¼ö ÀÖÀ» °ÍÀÌ´Ù. ..¿À, ´ç½ÅÀº ±×°Í¿¡ ¿¡·¯Ã¼Å·À» ÇÒ¼öµµ ÀÖ´Ù.:)
------
<++> socket/server.c
/* SERVER PROGRAM */
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/wait.h>
#define PORT 1500 /* the port users will be connecting to */
#define BACKLOG 5 /* how many pending connections queue will hold */
main()
{
int sockfd, new_fd; /* listen on sock_fd, new connection on new_fd */
struct sockaddr_in my_addr; /* our address information */
struct sockaddr_in their_addr; /* their address information */
int sin_size;
sockfd = socket(AF_INET, SOCK_STREAM, 0);
/* remember to error check (-1 on error) */
my_addr.sin_family = AF_INET; /* host byte order */
my_addr.sin_port = htons(PORT); /* short, network byte order */
my_addr.sin_addr.s_addr = INADDR_ANY; /* auto-fill with my IP */
bzero(&(my_addr.sin_zero), 8); /* zero the rest of the struct */
bind(sockfd, (struct sockaddr *)&my_addr, sizeof(struct sockaddr));
listen(sockfd, BACKLOG)
while(1) { /* start out accept() loop */
sin_size = sizeof(struct sockaddr_in);
new_fd = accept(sockfd, (struct sockaddr *)&their_addr, &sin_size)
printf("server: got connection from
fork(); /* this is the child process */
send(new_fd, "Hello, world!\n", 14, 0)
close(new_fd);
exit(0);
while(waitpid(-1,NULL,WNOHANG) > 0); /* clean up child processes */
}
}
/* END SERVER PROGRAM, REMEMBER TO DO YOUR ERROR CHECKING */
<--><++> socket/client.c
/* CLIENT PROGRAM */
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <netdb.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <sys/socket.h>
#define PORT 1500 /* the port client will be connecting to */
#define MAXDATASIZE 100 /* max number of bytes we can get at once */
int main(int argc, char *argv[])
{
int sockfd, numbytes;
char buf[MAXDATASIZE];
struct hostent *he;
struct sockaddr_in their_addr; /* connector's address information */
if (argc != 2) {
fprintf(stderr,"Usage: client <host name>\n");
exit(1);
}
he = gethostbyname(argv[1]); /* get the host info */
/* did you check for errors? */
sockfd = socket(AF_INET, SOCK_STREAM, 0);
their_addr.sin_family = AF_INET; /* host byte order */
their_addr.sin_port = htons(PORT); /* short, network byte order */
their_addr.sin_addr = *((struct in_addr *)he->h_addr);
bzero(&(their_addr.sin_zero), 8); /* zero the rest of the struct */
connect(sockfd, (struct sockaddr *)&their_addr, sizeof(struct sockaddr));
numbytes = recv(sockfd, buf, MAXDATASIZE, 0);
buf[numbytes] = '\0';
printf("Received:
close(sockfd);
return 0;
}
/* END CLIENT...YOU CHECKED FOR ERRORS RIGHT? :) */
<-->
=+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+=
ÃæºÐÈ÷, ³ª´Â ±×°ÍÀÌ Áö±Ý ´õ ¸¹ÀÌ ³ª¾ÆÁ³À¸¸®¶ó »ý°¢ÇÑ´Ù. ÀÌ°ÍÀº ¼ÒÄÏ ÇÁ·Î±×·¡¹ÖÀ»
À§ÇÑ ¿Ïº®ÇÑ °¡À̵å¶ó°í »ý°¢ÇÏÁö ¾Ê´Â´Ù, ½ÇÁ¦ÀûÀ¸·Î, ±×°ÍÀº ½ÃÀÛÇÏ´Â °ÍÀ¸·Î ºÎÅÍ
¸Å¿ì ¸Ö¾îÁ®ÀÖ°í °íÀÇ·Î ¾î´ø ¹®Á¦µµ ¾øÁö ¾Ê´Ù. ÀÌ ÁÖÁ¦¿¡ ´ëÇؼ ´õ ¸¹ÀÌ ¾Ë°í½ÍÀº
»ç¶÷µéÀ» À§ÇØ ¾Æ·¡ ¸Ç ÆäÀÌÁö¸¦ º¼ °ÍÀ» Á¦¾ÈÇÑ´Ù.
socket, bind, connect, perror, herror, listen, accept, send, recv, close,
shutdown, getpeername, getsockname, gethostbyname, gethostbyaddr and
getprotobyname.
´ç½ÅÀº ¶ÇÇÑ ¾Æ·¡¿Í °°Àº ÁÁÀº Ã¥µéÀ» ÀÐ¾î ºÁµµ ÁÁ´Ù.
------
Internetworking with TCP/IP, volumes I-III by Douglas E. Comer and David
L. Stevens. Published by Prentice Hall. Second edition ISBNs: 0-13-468505-9,
0-13-472242-6, 0-13-474222-2. There is a third edition of this set which
covers IPv6 and IP over ATM.
Using C on the UNIX System by David A. Curry. Published by O'Reilly &
Associates, Inc. ISBN 0-937175-23-4.
TCP/IP Network Administration by Craig Hunt. Published by O'Reilly &
Associates, Inc. ISBN 0-937175-82-X.
TCP/IP Illustrated, volumes 1-3 by W. Richard Stevens and Gary R. Wright.
Published by Addison Wesley. ISBNs: 0-201-63346-9, 0-201-63354-X,
0-201-63495-3.
UNIX Network Programming by W. Richard Stevens/ Published by Prentice
Hall. ISBN 0-13-949876-1.
-------
ÀÌ°Í¿¡ ´ëÇÑ ¿Ïº®ÇÑ ½ÇÁ¤À» ¾Ë°í ½ÍÀº°¡? ¾Æ·¡ÀÇ RFCµéÀ» ºÁ¶ó:
------
RFC-768 -- The User Datagram Protocol (UDP)
(ftp://nic.ddn.mil/rfc/rfc768.txt)
RFC-791 -- The Internet Protocol (IP)
(ftp://nic.ddn.mil/rfc/rfc791.txt)
RFC-793 -- The Transmission Control Protocol (TCP)
(ftp://nic.ddn.mil/rfc/rfc793.txt)
RFC-854 -- The Telnet Protocol
(ftp://nic.ddn.mil/rfc/rfc854.txt)
RFC-951 -- The Bootstrap Protocol (BOOTP)
(ftp://nic.ddn.mil/rfc/rfc951.txt)
RFC-1350 -- The Trivial File Transfer Protocol (TFTP)
(ftp://nic.ddn.mil/rfc/rfc1350.txt)
------
ÃæºÐÈ÷, ³ª´Â ÀÌ°ÍÀÌ ÀλçÇϱâ À§ÇÑ ½Ã°£°ú ¼ÒÄÏ ÇÁ·Î±×·¡¹Ö¾ÈÀ¸·Î ÇູÇÑ ¿©ÇàÀ»
ÇÒ °ÍÀ̶ó ÃßÃøÇÑ´Ù. ³»°¡ ¸»Çϱâ Àü¿¡, ÀÌ°ÍÀº ¿Ïº®ÇÑ ¸Å´º¾óÀº *¾Æ´Ï´Ù*
±×°ÍÀº ¿ÀÁ÷ ÀÛÀº ÀÔ¹®¼ ÀÏ»ÓÀÌ´Ù. ¾Æ¸¶µµ ¿©±â¿¡ ³»°¡ ½Ç¼öÇÑ ¸¹Àº ¿¡·¯µµ ÀÖÀ»
°ÍÀÌ´Ù. ¿À ÃæºÐÈ÷, ±×°ÍÀº Àλý°ú °°´Ù, ³ª´Â °áÄÚ ¾î¶² ´ë°¡¸¦ ¹Ù¶óÁö ¾Ê´Â´Ù.
¾Æ¸¶µµ °ð ³ª´Â SOCK_DGRAM ŸÀÔÀÇ ¹®¼¸¦ ¸¸µé °ÍÀÌ°í, ´Ù¸¥ ±âÀÌÇÑ ¼ÒÄÏ°ú °°´Ù.
"±×°ÍÀ» ÇÔ²², Áñ°Ü¶ó.
~xphantom
//¿ªÀÚÈıâ
¹ø¿ªÀº ²Ï ¿À·¡Àü¿¡ Çسõ¾ÒÀ¸³ª ¹ø¿ªÀÌ ³Ê¹« ÀÌ»óÇÑ µíÇØ µÎ°íÀÖ¾úÁö¸¸
±×·¡µµ ´Ù¸¥ »ç¶÷À» À§Çؼ(¿µ¾î¸¦ º¸±â¸¸ Çصµ ´ß»ìÀÌ µ¸´Â »ç¶÷µé)À» À§ÇØ
ÀÌ·¸°Ô ¿Ã¸³´Ï´Ù:)
|
Hit : 17450 Date : 2003/09/11 05:41
|