netlink socket 을 이용하는 코드 컴파일.

russell의 이미지

netlink socket 을 이용하는 코드를 컴파일 하고 싶습니다만, 이게 잘 되지 않네요. 우분투 9.04 이며, 커널버전은 2.6.28-15-generic 입니다.

뭔가 문제가 있는거 같은데...아마도 gcc 컴파일 할 때 문제인거 같습니다. 컴파일시에 다음과 같은 에러가 납니다. ;;

~/work/stuff-code/netlink$ gcc -I/lib/modules/2.6.28-15-generic/build/include -o mon_routing_table mon_routing_table.c
In file included from /lib/modules/2.6.28-15-generic/build/include/linux/socket.h:23,
from /lib/modules/2.6.28-15-generic/build/include/linux/netlink.h:4,
from /lib/modules/2.6.28-15-generic/build/include/linux/rtnetlink.h:4,
from mon_routing_table.c:5:
/lib/modules/2.6.28-15-generic/build/include/linux/uio.h:45: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘iov_length’
/lib/modules/2.6.28-15-generic/build/include/linux/uio.h:55: error: expected declaration specifiers or ‘...’ before ‘size_t’
In file included from /usr/include/sys/uio.h:29,
from /usr/include/sys/socket.h:28,
from mon_routing_table.c:7:
/usr/include/bits/uio.h:45: error: redefinition of ‘struct iovec’
In file included from /usr/include/sys/socket.h:40,
from mon_routing_table.c:7:
/usr/include/bits/socket.h:163: error: redefinition of ‘struct sockaddr’
/usr/include/bits/socket.h:176: error: redefinition of ‘struct __kernel_sockaddr_storage’
/usr/include/bits/socket.h:186: error: expected identifier before numeric constant
/usr/include/bits/socket.h:234: error: redefinition of ‘struct msghdr’
/usr/include/bits/socket.h:252: error: redefinition of ‘struct cmsghdr’
/usr/include/bits/socket.h:281: error: conflicting types for ‘__cmsg_nxthdr’
/lib/modules/2.6.28-15-generic/build/include/linux/socket.h:131: error: previous definition of ‘__cmsg_nxthdr’ was here
/usr/include/bits/socket.h:310: error: expected identifier before numeric constant
/usr/include/bits/socket.h:389: error: redefinition of ‘struct linger’

그래서 혹시나 해서 -I 옵션을 제거 하고 컴파일 해도 비슷한 증상입니다.

~/work/stuff-code/netlink$ gcc -o mon_routing_table mon_routing_table.c
In file included from /usr/include/linux/socket.h:23,
from /usr/include/linux/netlink.h:4,
from /usr/include/linux/rtnetlink.h:4,
from mon_routing_table.c:5:
/usr/include/linux/uio.h:37: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘iov_length’
/usr/include/linux/uio.h:47: error: expected declaration specifiers or ‘...’ before ‘size_t’
In file included from /usr/include/sys/uio.h:29,
from /usr/include/sys/socket.h:28,
from mon_routing_table.c:7:
/usr/include/bits/uio.h:45: error: redefinition of ‘struct iovec’
In file included from /usr/include/sys/socket.h:40,
from mon_routing_table.c:7:
/usr/include/bits/socket.h:163: error: redefinition of ‘struct sockaddr’
/usr/include/bits/socket.h:176: error: redefinition of ‘struct __kernel_sockaddr_storage’
/usr/include/bits/socket.h:186: error: expected identifier before numeric constant
/usr/include/bits/socket.h:234: error: redefinition of ‘struct msghdr’
/usr/include/bits/socket.h:252: error: redefinition of ‘struct cmsghdr’
/usr/include/bits/socket.h:281: error: conflicting types for ‘__cmsg_nxthdr’
/usr/include/linux/socket.h:129: error: previous definition of ‘__cmsg_nxthdr’ was here
/usr/include/bits/socket.h:310: error: expected identifier before numeric constant
/usr/include/bits/socket.h:389: error: redefinition of ‘struct linger’

으흠. 문제네요. ㅠㅠ

russell의 이미지

으흠. 컴파일이 되네요. 단지, 헤더 파일의 인클루딩 순서를 변경 했습니다.

본래...것.

#include <linux/rtnetlink.h>
#include <bits/sockaddr.h>
#include <sys/socket.h>
#include <asm/types.h>
#include <string.h>
#include <stdio.h>

변경...한 것.

#include <bits/sockaddr.h>
#include <stdio.h>
#include <string.h>
#include <asm/types.h>
#include <linux/netlink.h>
#include <linux/rtnetlink.h>
#include <sys/socket.h>

으흠. 왜 이런거죠? 대략, 감은 오는데...(사실, 예전에도 이런적이 있었습니다...) 정확히...왜 이런 문제가 생기는지요? 혹은 이런 문제를 미연에 방지 할 수 있는 뭔가가 있나요?

댓글 달기

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