172, 1/9 ȸ¿ø°¡ÀÔ  ·Î±×ÀΠ 
   han7685
   ¼ÒÄÏÇÁ·Î±×·¡¹Ö ¿À·ùÁ»Ã£¾ÆÁÖ¼¼¿ä~¤Ð

http://www.hackerschool.org/HS_Boards/zboard.php?id=QNA_Network&no=100 [º¹»ç]



#include<sys/socket.h>
#include<sys/stat.h>
#include<arpa/inet.h>
#include<stdio.h>
#include<string.h>
#define MAXBUF 1024

int main(int argc, char **argv)
{
int server_sockfd, client_sockfd;
int client_len, n;
char buf[MAXBUF];
struct sockaddr_in clientaddr, serveraddr;

client_len = sizeof(clientaddr);
if((server_sockfd = socket (AF_INET,SOCK_STREAM, IPPROTO_TCP)) == -1)
{
perror("socket error :");
exit(0);
}


}
bzero(&serveraddr, sizeof(serveraddr));
serveraddr.sin_family = AF_INET;
serveraddr.sin_addr.s_addr = htonl(INADDR_ANY);
serveraddr.sin_port= htons(atoi(argv[1]));
bind (server_sockfd, (struct sockaddr *)&serveraddr, sizeof(serveraddr));
listen(server_sockfd, 5);

while(1)
{
memset(buf,0x00,MAXBUF);
client_sockfd = accept(server_sockfd,
(struct sockaddr *)&clientaddr, &client_len);
printf("NEW Client connect : %s\n", inet_ntoa(clientaddr.sin_addr));
if((n=read(client_sockfd,buf,MAXBUF) <=0))
{
close(client_sockfd);
continue;
}
if(write(client_sockfd,buf,MAXBUF)<=0)
{
perror("write error:");
close(client_sockfd);
}
close(server_sockfd);
return 0;
}
main °ú
19¹ø¤Š¶óÀΠ exit(0)
45¹ø°¶óÀο¡¼­ ¿¡·¯°¡³­µ¥¿ä...
¾Æ¹«¸®ºÁµµ Àú´Â¸øã°Ú³×¿©...


  Hit : 3353     Date : 2012/11/19 10:55



    
º¸¾È¿Õ Ŭ¶óÀ̾ðÆ® sockÀ» Á¤ÇØÁÖ´Â clientlenÀ» intŸÀÔÀÌ ¾Æ´Ï¶ó socklen_t ÀÌ°Å¿´³ª ÀÌ Å¸ÀÔÀ¸·Î ÇØÁÖ¼¼¿ä. Ã¥¿¡ ±× ºÎºÐ º¸½Ã¸é µÉ°Å¿¡¿ä. 2012/11/21  
cd80 mainÇÔ¼ö¿¡¼­ »ç¿ëµÈ if¹®À» º¸½Ã¸é
if((server_sockfd = socket (AF_INET,SOCK_STREAM, IPPROTO_TCP)) == -1)
{
perror("socket error :");
exit(0);
}


}

ÀÌ·¸°Ô µÅÀִµ¥
if¹®À» ³¡³½ } ´ÙÀ½¿¡ ÀÖ´Â } ¶§¹®¿¡ ¿¡·¯°¡ ³³´Ï´Ù
2012/11/21  
172   ³×Æ®¿öÅ© Àåºñ(¶ó¿ìÅÍ, ½ºÀ§Ä¡, Çãºê, °øÀ¯±âµîµî)¿¡¼­µµ ÈçÀûÀÌ ³²³ª¿ä?[1]     ÇØÅ·ÀßÇÏ°í½Í´Ù
05/20 703
171   osi7°èÃþ ±â´ÉÀÌ ¼³¸íµÇ¾îÀÖ°í..[2]     thsrhkdwns
01/07 2076
170   ½º´ÏÇÎÀÌ ip,mac ÇÊÅ͸µ ÇÏ´Â°É ÇÊÅ͸µ ¾ÈÇÏ°Ô ÇØÁÖ°í ·£Ä«µå·Î µé¾î ¿À´Â°É turttle2s´Ô[1]     thsrhkdwns
12/26 2118
169   Turtle2s ´Ô     thsrhkdwns
12/23 2017
168   ¿î¿µÃ¼Á¦´Â C¾ð¾î·Î ÀÌ·ç¾îÁ®¼­[5]     thsrhkdwns
12/13 2332
167   ¼­¹ö¸¦ ÀÌ¿ëÁßÀε¥ DDos ¹æ¾î¸¦ ¾î¶»°Ô ÇÏ´Â°Ô ÁÁÀ»±î¿ä?[1]     julic123
12/05 2146
166   ȸ¼±±³È¯¹æ½Ä Áú¹®ÀÔ´Ï´Ù..[1]     turttle2s
09/10 2167
165   Åë½ÅÂ÷´Ü.. ¾î¶² ¿ø¸®·Î °¡´ÉÇÑÁö ±Ã±ÝÇÕ´Ï´Ù.[1]     ³«Á¶
04/17 2066
164   IPv6 ÁÖ¼Ò Ç¥Çö ¹æ½ÄÀÌ ÀÌÇØ°¡ ¾ÈµË´Ï´Ù ¤Ð[1]     akffoddl5
03/24 2140
163   °°Àº ³×Æ®¿öÅ© »ó¿¡¼­ pcÇØÅ·Àº ¾î¶»°Ô Çϳª¿ä??[2]     h0j8p9
06/30 4242
162   ¼ÒÄÏ ÇÁ·Î±×·¡¹Ö ÀÚ½Ä ÇÁ·Î¼¼½º Áú¹®[3]     ka0r1
02/01 2611
161   ÅÚ³Ý Åë½Å°£¿¡ ÆÐŶ¸¸µé¾î º¸³»´Â°Ô ±Ã±ÝÇÕ´Ï´Ù.     teletubbies
01/30 2615
160   ARP_TABLE macÁÖ¼Ò Áߺ¹ °ü·Ã     you88311
12/07 2865
159   Áú¹® Çϳª µé¸³´Ï´Ù... ¤Ì[1]     a484008
09/04 2753
158   ITºÐ¾ß·Î Áø·Î°í¹ÎÀ̳ª,Ãë¾÷,ÀÌÁ÷°í¹ÎÀ¸·Î ±Ã±ÝÇÑÁ¡µéÀÌ ¸¹À¸½ÃÁÒ~?     koreais0
08/08 2859
157   ¿ÍÀ̾î»þÅ©·Î ĸÃÄÇÒ ¼ö ÀÖ´Â ¹«¼±·£ÀÇ ¹üÀ§´Â ¾îµð±îÁöÀΰ¡¿ä?[1]     jonah2000
07/11 3614
156   ÇØÅ· °øºÎ¹ý¿¡ ´ëÇؼ­ Áú¹®µå¸³´Ï´Ù.[2]     choboKing
12/16 4863
155   ¿ä¹ø¿¡ ÇØÅ· ´çÇÑ »çÀ̹ö»ç·ÉºÎ »çÅ¿¡ ´ëÇØ ¾î¶»°Ô »ý°¢Çϳª¿ä?[13]     nis111
12/14 3783
154   °øÀÎ ip°ü·Ã Áú¹®[1]     wlgns5721
08/19 3659
153   ÇØÄ¿½ºÄð[2]     ks610126
07/17 3594
1 [2][3][4][5][6][7][8][9]

Copyright 1999-2024 Zeroboard / skin by Hackerschool.org / Secure Patch by Hackerschool.org