[질문][네트워크 프로그래밍] arm으로 컴파일후 connect()에서 i

mon12key의 이미지

안녕하세요.
초보 리눅서 멍12키 입니다.

또 네트워크 프로그래밍쪽에 질문입니다.

x86에서는 잘 되던 connect()이 arm으로 컴파일한 후에는 invaild argument 에러가 나오면서 다운되네요.

zero( (char*)&serverAddr, sizeof(serverAddr));
	serverAddr.sin_family = AF_INET;	
	serverAddr.sin_addr.s_addr = htonl(INADDR_ANY);
	serverAddr.sin_port = htons(ToolPort);
                printf("\ntarget tool connect %s \n", inet_ntoa(serverAddr.sin_addr));
               if (-1 == connect(mTempStr.nSocketDesc, (struct sockaddr *)&serverAddr, sizeof(serverAddr)))
                  perror(errno);

에러나는 부분은 간략히 위와 같이 진행됩니다.
왜 이런 에러가 나오는지 이해가 안갑니다. x86에서는 정상적으로 되는데요.
아무래도 라이브러리가 틀려서 그런거지. -_-;
아니면 네트워크 바이트로 재정렬하는 매크로가 arm에서 문제가 되는건지?
주로 socket 프로그래밍이어서 architecture에 의존성이 없다고 생각했는데...
쩝.

그럼 고견들을 남겨주세요

송지석의 이미지

제가 짰던 코드 snippet입니다. x86과 별로 다를 바가 없습니다. 작년에 짰던 거라 기억이 가물가물하네요 -_-

#define DEST_ADDR                   Server_IP_Addr.s_addr
........
    dest_addr0.sin_family = AF_INET;
    dest_addr0.sin_port = htons(DEST_PACKET_PORT);
    dest_addr0.sin_addr.s_addr = DEST_ADDR;
............

// ip는 이렇게 설정합니다. ipstr에 192.168.1.44 식으로 들어있을 때였을 겁니다.
int set_sv_ip(const char *ipstr)
{
    struct in_addr inp;
    if(!inet_aton(ipstr, &inp)) // convert ip
    {
#ifdef DEBUG
        printf("[set_sv_ip] conversion failed\n");
#endif
        return FAILED;
    }
    Server_IP_Addr.s_addr= inp.s_addr;
#ifdef DEBUG
    printf("%lu=%s\n",(unsigned long)inp.s_addr,  inet_ntoa(inp));
#endif
    return SUCCESS;
}

제가 보기엔 serverAddr.sin_addr.s_addr = htonl(INADDR_ANY); 이 잘못된 것 같네요.. 접속할 서버 주소를 주셔야죠
mon12key의 이미지

답변 감사합니다.

그런데, 특정 아이피로 선택해도
Invaild argument 라는 에러가 나옵니다.

-_-;

송지석의 이미지

result = connect ( *sock, (struct sockaddr *) &dest_addr0, sizeof (struct sockaddr));
음 이상한데요.. 저는 위 코드로 접속했습니다만 이상 없었는데요.

그렇다면 bind로 자기 주소 정보를 넣고 해보세요..

*sock= socket(AF_INET, SOCK_STREAM, 0);     /*make socket descriptor*/

/* bind My socket address information */
my_addr0.sin_family = AF_INET;
my_addr0.sin_port = htons(MY_PORT); //short network byte order
my_addr0.sin_addr.s_addr = htonl(INADDR_ANY);// Use my ip address
memset(&(my_addr0.sin_zero), 0, 8);
result = bind(*sock, (struct sockaddr *)&my_addr0, sizeof(struct sockaddr));
...................
dest_addr0.sin_family = AF_INET;
dest_addr0.sin_port = htons(DEST_PACKET_PORT);
dest_addr0.sin_addr.s_addr = DEST_ADDR;    //또는dest_addr0.sin_addr.s_addr = inet_addr(DEST_IP);

memset(&(dest_addr0.sin_zero), 0, 8);
result = connect ( *sock, (struct sockaddr *) &dest_addr0, sizeof (struct sockaddr));

lunarainbow의 이미지

mTempStr.nSocketDesc 이 구조체의 모양을 볼 수 있을까요?

mon12key의 이미지

그 구조체는 다음과 같이 정의되어 있습니다.

typedef struct
{
	SocketType nSockType;
	int nToolType;
	int nSocketDesc;	
} SockElement;	

nSocketDesc는 소켓을 위해 사용됩니다. ^^.

lunarainbow의 이미지

으휴.. 정말 모르겠네요.. 설마 이런것은 아니겠지만... 그냥 혹시나 싶어서. ^^;

mTempStr.nSocketDesc = socket(AF_INET, SOCK_STREAM, 0);

코드내에 보이지 않아서 그냥 써보긴 했지만..

이것때문은 아니겠죠...;;;

도움도 못드리고 귀찮게 해드려 죄송합니다.

mon12key의 이미지

관심 가져주셔서 고맙습니다.
소켓은 물런 생성했는데 안되는 경우입니다.

-_-. 작은 테스트용은 되는데.. 대체 멀 잘못했길래.
컴퓨터가 거짓말 하지 않을테니 저의 잘못이겠죠.

디버깅~

mon12key의 이미지

strace로 system call을 출력했습니다. 같은 코드를 arm과 x86에서 찍어 보았습니다.

arm에서는 에러가 나는군요. -_-;

arm에서

 connect(5, {sin_family=AF_INET, sin_port=htons(21), sin_addr=inet_addr("168.219.193.52")}}, 16) = -1 EINVAL (Invalid argument)
 

x86에서

connect(5, {sa_family=AF_INET, sin_port=htons(21), sin_addr=inet_addr("127.0.0.1")}, 16) = 0
write(2, "Error (0) Success: \n", 20Error (0) Success:
mon12key의 이미지

구글에서 검색해보니. 다음과 같은 얘기가 있더군요.

구글 wrote:

구글을 찾다보니 다음과 같은 얘기가 있더군요. 결국 프로그램 버그가 아닐지도 모르겠다는...

질문)
problem with connect()

Igor Trevisan igor.trevisan@bluewind.it
Tue, 18 Feb 2003 10:18:07 +0100

Previous message: Kernel panic while trying to mount jffs2 to root
Next message: problem with connect()
Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

& _____ &

Hi all!

I've a strange problem with TCP connections...
I'm developing some applications on a custom board derived
from EDB7312, running linux 2.4.19-rmk4.
When I the execution of some little applications I'm writing for test
reach a connect() call, my programm exit with an
"Invalid argument" error.
This also happen If I try to ping to my board from the same board
console or if I try to telnet to the echo port of my board from inside...
Do I miss something in kernel configuration?
Or are there any configuration file I miss?
Any suggestion will be VERY appreciated...
Thanks in advance,
Igor.

답변)
problem with connect()

Igor Trevisan igor.trevisan@bluewind.it
Tue, 18 Feb 2003 14:42:02 +0100

Previous message: problem with connect()
Next message: Custom serial driver and Low level serial API
Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

& _____ &

> On Tue, Feb 18, 2003 at 10:18:07AM +0100, Igor Trevisan wrote:
> > Do I miss something in kernel configuration?
>
> No idea - you haven't sent a copy of the configuration.

Don't waste your time!
It was due to hosts file missing localhost line
and to the loopback network interface not activated.
Igor.

그래서 타겟의 네트워크 설정을 다시하고 정상적으로 작동합니다. ㅠ.ㅠ;

댓글 달기

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