실행파일은 만들어지는데 컴파일에러가 생깁니다. 도움좀..

kimyh의 이미지

C를 공부하고 있는중입니다.
자신의 아이피를 구하는 프로그램인데 컴파일하면 아래와 같은 에러가 생깁니다.
그런데 실행파일은 만들어 지고 동작도 잘 됩니다.

어디를 수정해야 컴파일에러가 없어지나요?
초보라서인지 에러찾기가 무척 난감한 일이군요. 도움좀...

에러내용;
ipset.c: In function `myip':
ipset.c:59: warning: passing arg 2 of `strcpy' makes pointer from integer without a cast
 
관련부분 소스;
//	Client IP확인을 위한 프로세스
	const char * myip()
		{
        const int MAX_NIC = 10;
        struct ifconf ifc;
        struct ifreq ifr[MAX_NIC];
 
        int s;
        static char ip[256];
        int cmd = SIOCGIFCONF;
        ifc.ifc_len = sizeof ifr;
        ifc.ifc_ifcu.ifcu_req = ifr;
 
//      연결수락후 클라이언트 소켓(1)을 얻는다.
        if( (s=socket(AF_INET,SOCK_STREAM,0)) < 0)
        {
                perror("socket"); 
                exit(1);
        }
 
        if( ioctl(s, cmd, &ifc) < 0)
        {
                perror("ioctl");
                exit(1);
        }
        close(s); 
                struct in_addr addr;
                addr = ((struct sockaddr_in *) & ifc.ifc_ifcu.ifcu_req [1].ifr_ifru.ifru_addr)->sin_addr;
                addr.s_addr == htonl( 0x7f000001 );                
                strcpy( ip, inet_ntoa(addr)); //이부분에서 에러가 발생합니다.
        return ip;
}
ssehoony의 이미지

흠 이상한 현상이군요.
혹시 inet_ntoa() 가 선언된 헤더를 include 하지 않은건 아닌지요?

그리고

The  inet_ntoa()  function converts the Internet host address
in given in network byte order to a string in standard numbers-and-dots notation.
The string is returned in a statically allocated buffer, which subsequent
calls will overwrite.

에서 보시면 아시겠지만, inet_ntoa()는 내부에서 statically allocated buffer 의 포인터를 리턴합니다.
그러므로 이걸 다시 myip() 의 statically allocated buffer로 복사한 후, 그 주소를 리턴하는 불필요한 작업을 할 필요가 없을 듯 하네요.
그냥 myip의 static buffer 은 제거하고, inet_ntoa() 가 리턴한 주소를 곧 바로 return 하셔도 될 듯 하네요.
kimyh의 이미지

답변 고맙습니다.
역시 헤더를 하나 빼 먹어서 생긴일이더군요.

#include <arpa/inet.h>

를 추가 하니까 에러가 없어지더군요.
감사합니다.

살며 그리고 사랑하며...
정보는 공유할때 그 가치가 있는것.....
나의 조그만 지식공유는 남에게 엄청난 기쁨을 안겨 준다.

살며 그리고 사랑하며...
정보는 공유할때 그 가치가 있는것.....
나의 조그만 지식공유는 남에게 엄청난 기쁨을 안겨 준다.

ssehoony의 이미지

원인이 제가 예상한 문제였군요.
첨언을 하자면, C의 경우는 함수원형이 없으면 int를 리턴하는 함수로 간주합니다.
그래서 컴파일러가 int 를 다른 것으로 cast 없이 사용했다는 경고를 주는 것이지요.
C++의 경우는 저건 경고가 아니고 에러입니다.

댓글 달기

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