소켓 프로그램중 sendto 에 관하여 질문드립니다.

hahasogang의 이미지

이더넷 포트 0에서 바인드를 시켜서 들어오는 프레임들을 받고 이더넷 코트 1로 보내는 프로그램입니다.
테스트해보니... 보내지를 못하는것 같아서 질문드립니다.많은 고수님들의 답변 부탁드립니다

#include <sys/time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <net/ethernet.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
//#include <netinet/ip.h>
//#include <netinet/tcp.h>
//#include <netinet/udp.h>
//#include <netinet/ip_icmp.h>
#include <netinet/ether.h>
#include <netinet/if_ether.h>
#include <linux/if_packet.h>


int
main (int argc, char **argv)
{
 int sock, n;
 char buffer[2048];
 unsigned char *iphead, *ethhead, *ether_addr;
 int str_len;
 struct sockaddr_ll sll;
 //struct sockaddr_in sin;
 struct sockaddr_ll dest_sll, test_sll;
 int state;

 struct ether_addr * test, *dtest;
 
 if ((sock = socket (PF_PACKET, SOCK_RAW, htons (ETH_P_ALL))) < 0)
   {
     perror ("socket error");
     exit (1);
   }

 	
 test = ether_aton("00:09:30:28:12:22");
 memcpy(sll.sll_addr, test->ether_addr_octet, ETH_ALEN);
   sll.sll_family =  AF_PACKET;
   //sll.sll_addr[8] =  ether_aton ("00:09:30:28:12:22");
   //sin.sin_family = AF_INET;
   //sin.sin_addr.s_addr = inet_addr ("192.168.0.1");
   dest_sll.sll_family = AF_PACKET;
 //  dest_sll.sll_addr[8] = ether_aton ("00:01:30:28:12:24");	   
  dtest =  ether_aton("00:01:30:28:12:24");
  memcpy(dest_sll.sll_addr, dtest->ether_addr_octet, ETH_ALEN);

   state = bind(sock,(struct sockaddr *)&sll, sizeof(sll));
   if (state <0)
   {
	   perror ("bind error ");
	   exit (0);
   }

   
 while (1)
   {
     printf ("----------\n");
     n = recvfrom (sock, buffer, 2048, 0,NULL, NULL);
     
     sendto(sock, buffer, str_len, 0, (struct sockaddr *)&dest_sll, sizeof(dest_sll));
     printf ("%d bytes read\n", n);

     /* Check to see if the packet contains at least
        * complete Ethernet (14), IP (20) and TCP/UDP
        * (8) headers.
        */
     if (n < 42)
       {
         perror ("recvfrom():");
         printf ("Incomplete packet (errno is %d)\n", errno);
         close (sock);
         exit (0);
       }

     ethhead = buffer;
     printf ("Source MAC address: "
             "%02x:%02x:%02x:%02x:%02x:%02x\n",
             ethhead[0], ethhead[1], ethhead[2],
             ethhead[3], ethhead[4], ethhead[5]);
     printf ("Destination MAC address: "
             "%02x:%02x:%02x:%02x:%02x:%02x\n",
             ethhead[6], ethhead[7], ethhead[8],
             ethhead[9], ethhead[10], ethhead[11]);

     iphead = buffer + 14;        /* Skip Ethernet header */
     if (*iphead == 0x45)
       {                        /* Double check for IPv4
                                  *                                                                              
                                                      * and no options present */
         printf ("Source host %d.%d.%d.%d\n",
                 iphead[12], iphead[13], iphead[14], iphead[15]);
         printf ("Dest host %d.%d.%d.%d\n",
                 iphead[16], iphead[17], iphead[18], iphead[19]);
         printf ("Source,Dest ports %d,%d\n",
                 (iphead[20] << 8) + iphead[21],
                 (iphead[22] << 8) + iphead[23]);
       }
   }

}

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.