1598, 1/80 ȸ¿ø°¡ÀÔ  ·Î±×ÀΠ 
   ruka270
   [ÀÚÀÛ] sbcl tcp Ŭ¶óÀ̾ðÆ® ¿¹Á¦

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


¼­¹öÄÚµå
#include <stdio.h>
#include <netinet/in.h>
#include <sys/socket.h>

#define PORT 9000
#define BSIZE 30

char buffer[BSIZE]="Hello,World!\n";
char rBuffer[BSIZE];

int main(){
        int len,n,length;
        int c_sock,s_sock;
        char *temp;
        struct sockaddr_in s_addr,c_addr;
        s_sock=socket(PF_INET,SOCK_STREAM,0);
        memset(&s_addr,0,sizeof(s_addr));
        s_addr.sin_addr.s_addr=htonl(INADDR_ANY);
        s_addr.sin_family=AF_INET;
        s_addr.sin_port=htons(PORT);
        if(bind(s_sock,(struct sockaddr*)&s_addr,sizeof(s_addr))==-1){
                printf("Can Not Bind\n");
                return -1;
        }
        if(listen(s_sock,5)==-1){
                printf("Listen Fail\n");
                return -1;
        }
        while(1){
                len=sizeof(c_addr);
                c_sock=accept(s_sock,(struct sockaddr*)&c_addr,&len);
                length=0;
                temp=rBuffer;
                while((n=read(c_sock,temp,1))>0){
                        if(*temp=='\r') continue;
                        if(*temp=='\n') break;
                        if(*temp=='\0') break;
                        if(length==BSIZE) break;
                        temp++;
                        length++;
                }
                rBuffer[length]='\0';
                printf("receive: %s\n",rBuffer);
                if(!strcmp(rBuffer,"printf")){
                        n=strlen(buffer);
                        write(c_sock,buffer,n);
                }
                close(c_sock);
        }
        close(s_sock);
        return 0;
}

Ŭ¶óÀ̾ðÆ® ÄÚµå
(require :asdf)
(asdf:operate 'asdf:load-op 'sb-bsd-sockets)
(defparameter @sock-s
  (make-instance 'sb-bsd-sockets:inet-socket :type :stream :protocol :tcp))
(defparameter @host
  (sb-bsd-sockets:host-ent-address
    (sb-bsd-sockets:get-host-by-name "localhost")))
(defparameter @port 9000)
(defparameter @foo nil)
(sb-bsd-sockets:socket-connect @sock-s @host @port)
(sb-bsd-sockets:socket-send @sock-s "printf" 10)
(setf @foo(sb-bsd-sockets:socket-receive @sock-s nil 30))
(sb-bsd-sockets:socket-close @sock-s)
(format t "*result: ~a~%" @foo)


¼­¹öÄÚµå´Â ¿­Ç÷°­ÀÇ TCP/IP ¼ÒÄÏ ÇÁ·Î±×·¡¹Ö¿¡¼­ ³ª¿À´Â helloserver ÄÚµåÀÔ´Ï´Ù.
printf¶ó´Â ¸í·ÉÀ» ¹Þ¾ÒÀ» °æ¿ì, Hello,World!¶ó´Â ¹®ÀÚ¿­À» Àü¼ÛÇØÁÖ´Â ÇÁ·Î±×·¥ÀÌ°í,
ÀÌ ¼­¹ö¸¦ »ç¿ëÇÒ¼ö ÀÖµµ·Ï sbcl¿¡¼­ ±âº»ÀûÀ¸·Î Á¦°øÇÏ´Â sb-bsd-socketsÆÐÅ°Áö¸¦ »ç¿ëÇÏ´Â ¹æ¹ýÀ» Å×½ºÆ®ÇغýÀ´Ï´Ù.
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

host-ent-address[sb-bsd-sockets] host-end-point
ÁöÁ¤µÈ È£½ºÆ®¿¡ ´ëÇÑ Á¢±Ù°ü·Ã Á¤º¸¸¦ ¹ÝȯÇÕ´Ï´Ù.
EndPoint¸¦ »ý¼ºÇϴµ¥¿¡´Â ¾ÆÀÌÇÇ ¶Ç´Â ÇØ´ç ¼­¹ö¸¦ ³ªÅ¸³¾¼ö ÀÖ´Â ¹®ÀÚ¿­À» EndPointÇü °´Ã¼·Î º¯È¯ÇÏ´Â ÇÔ¼ö
get-host-by-nameÀÌ »ç¿ëµË´Ï´Ù.

(make-instance 'sb-bsd-sockets:inet-socket :type :stream :protocol :tcp))
¼ÒÄÏÀ» »ç¿ëÇϱâ À§Çؼ­´Â sb-bsd-socketsÆÐÅ°Áö ³»ºÎ¿¡ Á¤ÀǵǾî ÀÖ´Â inet-socket Ŭ·¡½º¸¦ ÀνºÅϽº ÇÒ ÇÊ¿ä°¡ ÀÖ½À´Ï´Ù.
À§ Äڵ忡¼­´Â tcp ¼ÒÄÏ ÀνºÅϽº¸¦ »ý¼ºÇÏ°í ÀÖ½À´Ï´Ù.

socket-connect[sb-bsd-sockets] socket host port
À§¿¡¼­ »ý¼ºµÈ ¼ÒÄÏ, È£½ºÆ®Á¤º¸,Æ÷Æ®¹øÈ£·Î ½ÇÁ¦·Î ¼­¹ö¿¡ Á¢¼ÓÇÏ´Â µ¿ÀÛÀ» ¼öÇàÇÕ´Ï´Ù.

socket-send[sb-bsd-sockets] socket buffer length
bufferÀÇ ³»¿ëÀ» ¼ÒÄÏÀ» ÅëÇØ Àü¼ÛÇÕ´Ï´Ù.

sock-receive[sb-bsd-sockets] socket buffer length
socketÀ» ÅëÇØ Àü¼ÛµÇ¾î¿Â µ¥ÀÌÅ͸¦ ¹ÝȯÇÕ´Ï´Ù.
ÀÌ ÇÔ¼ö¿¡¼­´Â buffer ¶Ç´Â lengthÁß Çϳª¸¸ ÁöÁ¤ÇØ ÁÖ¸é µÇ´Âµ¥,
±× ÀÌÀ¯´Â length°¡ ÁöÁ¤µÉ °æ¿ì buffer ÁöÁ¤Àº ¹«½ÃµÇ°í, ÁöÁ¤µÈ Å©±â ¸¸Å­ÀÇ »õ·Î¿î ¹öÆÛ¸¦ ¸¸µé¾î ÇÔ¼ö Á¾·áÈÄ
¼ö½Å °á°ú¸¦ ¹Ýȯ°ªÀ¸·Î¼­ ´øÁ®ÁÖ°Ô µË´Ï´Ù.
¸¸¾à, buffer¸¦ ÁöÁ¤ÇØÁÖ°í length¸¦ ÁöÁ¤ÇØ ÁÖÁö ¾Ê¾ÒÀ» °æ¿ì¿¡´Â buffer°¡ Â÷ÁöÇÏ°í ÀÖ´Â ¿µ¿ªÀ§¿¡ ¼ö½Å µ¥ÀÌÅ͸¦
µ¤¾î¾²°Ô µË´Ï´Ù.
´ëºÎºÐ ÀÌ·¯ÇÑ Ã³¸®´Â ¿øÄ¡ ¾Ê±â ¶§¹®¿¡ buffer ¿µ¿ªÀ» ºñ¿öµÎ°í, length°ªÀ» ÁöÁ¤ÇÏ´Â ÇüÅ·Π»ç¿ëµË´Ï´Ù.

sock-close[sb-bsd-sockets] socket
¿­·Á ÀÖ´Â ¼ÒÄÏÀ» ´Ý½À´Ï´Ù.
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

¿Ïº®ÇÑ ³×Æ®¿öÅ© ÇÁ·Î±×·¥ÀÌ µÇ±â À§Çؼ­´Â Ŭ¶óÀ̾ðÆ® Äڵ忡µµ ŸÀӾƿô 󸮵îÀÌ µé¾î°¡¾ß ÇÏÁö¸¸,
ÀÌ ¿¹Á¦´Â ³×Æ®¿öÅ© Á¢¼ÓÀ» À§ÇÑ ÃÖ¼ÒÇÑÀÇ ÇÔ¼öÀÇ »ç¿ë¿¹¸¦ º¸¿©ÁÖ±â À§ÇÑ°«ÀÌ´Ï ³Ñ¾î°¡µµ·Ï ÇÏ°Ú½À´Ï´Ù.

  Hit : 6468     Date : 2010/12/27 10:36



    
     [°øÁö] °­Á¸¦ ¿Ã¸®½Ç ¶§´Â ¸»¸Ó¸®¸¦ ´Þ¾ÆÁÖ¼¼¿ä^¤Ñ^ [29] ¸Û¸Û 02/27 19513
1597   [Write Up] Crypto Cat's CTF 2024 - BabyFlow     ÇØÅ·ÀßÇÏ°í½Í´Ù
12/29 47
1596   [pwnable.kr] bof     ÇØÅ·ÀßÇÏ°í½Í´Ù
12/25 58
1595   [pwnable.kr] Shellshock[1]     ÇØÅ·ÀßÇÏ°í½Í´Ù
11/23 171
1594   ShellshockÀÇ ±âº» ¿ä¾à     ÇØÅ·ÀßÇÏ°í½Í´Ù
11/23 144
1593   [pwnable.kr] fd     ÇØÅ·ÀßÇÏ°í½Í´Ù
11/23 146
1592   VPNÀÌ ¿¬°áµÇ¾ú´Ù°¡ µµÁß¿¡ ²¨µµ À¥ ºê¶ó¿ìÀú»ó¿¡¼­ À¯ÁöµÇ´Â ÀÌÀ¯     ÇØÅ·ÀßÇÏ°í½Í´Ù
11/22 142
1591   ÇØÄ¿µéÀÌ ÇØÅ·½Ã »ç¿ëÇÏ´Â µð·ºÅ丮 °ø°£[1]     ÇØÅ·ÀßÇÏ°í½Í´Ù
11/22 182
1590   Keyboard Hooking -part2 - (Python3 ver)     ÇØÅ·ÀßÇÏ°í½Í´Ù
11/20 159
1589   [Windows API] Keyboard Hooking     ÇØÅ·ÀßÇÏ°í½Í´Ù
11/20 134
1588   [pwnable.kr] cmd1 °ø·«     ÇØÅ·ÀßÇÏ°í½Í´Ù
10/23 313
1587   netdiscover ÆÄÀ̽ãÀ¸·Î ±¸ÇöÇϱ⠠   ÇØÅ·ÀßÇÏ°í½Í´Ù
08/13 580
1586   ÆÄÀ̽ãÀ» ÀÌ¿ëÇÑ ½ÉÇà À¥ Å©·Ñ·¯     ÇØÅ·ÀßÇÏ°í½Í´Ù
08/13 462
1585   ÆÄÀ̽ã random¸ðµâÀ» ÀÌ¿ëÇÑ ¼ýÀÚ¸ÂÃ߱⠰ÔÀÓ ±¸Çö     ÇØÅ·ÀßÇÏ°í½Í´Ù
05/30 1015
1584   ÆÄÀ̽ã äÆà ÇÁ·Î±×·¥ ±¸Çö     ÇØÅ·ÀßÇÏ°í½Í´Ù
05/28 891
1583   ÆÄÀ̽㠼ÒÄÏ ÇÁ·Î±×·¡¹ÖÀÇ ±âÃÊ     ÇØÅ·ÀßÇÏ°í½Í´Ù
05/26 1055
1582   ¸®´ª½º À¥ ·Î±× ºÐ¼®     ÇØÅ·ÀßÇÏ°í½Í´Ù
05/20 704
1581   ¸®´ª½º/À©µµ¿ì º¸¾È Àåºñ ·Î±×     ÇØÅ·ÀßÇÏ°í½Í´Ù
05/20 849
1580   °í¼ö´ÔµéÀÇ µµ¿òÀ» ¹Þ°í ½Í½À´Ï´Ù     vbnm111
02/11 943
1579   ¸®´ª½º Ä¿³Î 2.6 ¹öÀü ÀÌÈÄÀÇ LKM     jdo
07/25 1458
1 [2][3][4][5][6][7][8][9][10]..[80]

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