커널의 arp테이블과 라우팅 테이블을 참조 하기위한 ioctl사용법

yhlvyp의 이미지

라우팅 프로토콜을 짜고있습니다.

커널과 연동이 되기 위해 arp테이블과 라우팅 테이블을 참조 하기위해 ioctl을 이용하려 합니다.

우선 arp테이블을 초기화 하기 위해 arp테이블을 지우는 ioctl명령을 아래와 같이 했습니다.

    sockfd = socket( AF_INET, SOCK_DGRAM, 0 );
    memset(&ld->ifr, 0, sizeof(ld->ifr));
    strcpy( ld->ifr.ifr_name, device );

    struct sockaddr_in *sin = (void *) &ld->ifr.ifr_ifru.ifru_addr;
    sin->sin_family = AF_INET;
    sin->sin_addr.s_addr = ld->gen_addr;
    sin->sin_port = 0;

    if( ioctl(sockfd, SIOCDARP, &ld->ifr )<0 ) {
        ERR("delete arp table ioctl(SIOCDARP)");
    }

결과는 Protocol family not supported라는 에러 메시지가 뜹니다.

이와 같은 명령어들을 수행하기 위해 ioctl함수의 첫번째와 세번째 인자가

어떤 의미를 가지며 어떻게 써야하는지를 알고 싶습니다.

그리고 이명령어 외에

/* ARP cache control calls. */
            /*  0x8950 - 0x8952  * obsolete calls, don't re-use */
#define SIOCDARP    0x8953      /* delete ARP table entry   */
#define SIOCGARP    0x8954      /* get ARP table entry      */
#define
/* Routing table calls. */
#define SIOCADDRT   0x890B      /* add routing table entry  */
#define SIOCDELRT   0x890C      /* delete routing table entry   */
#define SIOCRTMSG   0x890D      /* call to routing system   */
SIOCSARP    0x8955      /* set ARP table entry   */

등의 명령어들이 있는데 이중 get ARP table entry같은 경우는

어떻게 참조가 가능한지 알고싶습니다. ifr구조체에 관련 포인터 변수는 없는듯 한데..

call to routing system도 무슨의미인지 모르겐네요=_=

고수님들의 답변 부탁드립니다.

albamc의 이미지

SIOCGARP, SIOCDARP 의 경우

/usr/include/linux/if_arp.h 에 선언되어 있는

struct arpreq 형 자료를 사용합니다.

struct ifreq 형의 자료를 사용하시면 안됩니다.

Protocol family not supported 에러는

커널 코드에 보면 ...

    if (r.arp_pa.sa_family != AF_INET)
        return -EPFNOSUPPORT;

이렇게 되어 있더군요.

ifreq 말고 arpreq 형으로 넣어서 해보시지요.

^^*

yhlvyp의 이미지

아래와 같이 했는데 여전히 같은 에러입니다.; 어떻게 해야할까요?

int
main( )
{
    int sockfd;
    struct arpreq arpt;
    if( (sockfd=socket( AF_INET, SOCK_DGRAM, 0 ))<0 ) {
        perror("socket error : ");
        exit(0);
    }
    if( ioctl( sockfd, SIOCGARP, &arpt )<0 ) {
       perror( "실패" );
    }
}

::peha::

albamc의 이미지

struct arpreq를 초기화시켜 주시고 필요한 값들을 넣어야 합니다.

    memset(&arpreq, 0, sizeof(struct arpreq));
    sin = (struct sockaddr_in*)&arpreq.arp_pa;
    sin->sin_family = AF_INET;
    sin->sin_addr.s_addr = inet_addr("<ip address>");
    sprintf(arpreq.arp_dev, "<device name>");

^^*

댓글 달기

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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.