accept 시 14번오류(EFAULT) 원인이 뭐죠?

myduck의 이미지

네트워크 프로그램을 만들고 있습니다.

서버측 프로그램으로 데몬 형태로 만들고 있는데요.

똑같은 소스로 다른 플랫폼에서는(linux, hp, 다른SUN)에서는 아무 문제 없이 실행이 되는데요.

특정 서버(SunOS 5.8 sun4u sparc SUNW,Ultra-5_10)에서 accept 함수에서 14번 오류가 발생합니다.

도저히 원인을 못 찾겠습니다.

main(argc, argv)
int		argc;
char	*argv[];
{
        switch( fork() )
        {
                case -1:
                        exit(1);
                case 0:
                        setsid();
                        break;
                default:
                        exit(0);
        }
	while(1)
	{
		demon();
	}
}

demon()
{
  	pid_t   childpid;
	int     addrlen, backlog;
	int		rtn=1;
	char	*ptr;
	char	curtime[128];
	int	accept_count = 0;	
	char	aHostName[32];		/* 서버의 이름 */
	
	_SetUp_SigKill(SigKill_Handler);
	_SetUp_Signal(SIGTERM, SigTerm_Handler);

	Read_Config(); /* 환경변수 읽기 */

	memset(aHostName, 0x00, sizeof(aHostName));
	memcpy(aHostName,  "localhost",   9);

	Sam_file_mon();		/* 모니터 로그파일 생성 */

	memset ( curtime, 0x00, sizeof(curtime));
	_get_curtime( curtime);
	fprintf ( mon, "demon start(PORT:%06d, TIME:%s)\n", demon_PORT, curtime);
	fflush (mon);
	
	/* TCP/IP Socket 생성 */
	listenfd = Create_Multi_TcpPort(demon_PORT, sPcAddr);
	if ((ptr =  (char *)getenv("LISTENQ")) != NULL) 
		backlog = atoi(ptr);

	if ( listen(listenfd, backlog) < 0 )  {      /* 서버로 설정 */
		Error_Handler(errno, errno, "create.. listen failed");
	}
	while(1){
		sleep(1);
		/* Client의 접속을 기다림 */
		if ( (nToDsP = accept(listenfd, (struct sockaddr *)&skaddr, &addrlen)) < 0 ) {
			if (errno == EINTR)
				continue;
			else
				ErrorMsg_Print("accept error");
		}
....
Create_Multi_TcpPort 는 socket 에서 bind 까지의 라이브러리 입니다.
Error_Handler 는 에러 발생시 화면이나 파일에 write하는 함수 입니다.
여기서 오류가 나는 부분은 accept 다음의 ErrorMsg_Print 입니다.
stoneshim의 이미지

      if ( (nToDsP = accept(listenfd, (struct sockaddr *)&skaddr, &addrlen)) < 0 ) { 
         if (errno == EINTR) 
            continue; 
         else 
            ErrorMsg_Print("accept error"); 
      } 

첫번째는 accept의 두번째 파라미터인 skaddr의 선언부분이 안보이네요... 이부분이 적절하게 선언되어 있어서 writable한 영역인지 확인해보시구요...

두번째는 addrlen은 선언만 되어있고, 값은 assign하지 않으셨는데... AF_INET계열이라면 sizeof( struct sockaddr_in ) 값으로 설정하셔야 합니다.
(accept(2)의 세번째 파라미터는 value-result 파라미터입니다.)

우리 모두 리얼리스트가 되자. 그러나 가슴에 이룰 수 없는 꿈을 가지자

myduck의 이미지

addrlen = sizeof(struct sockaddr_in);

한줄 추가로 해결 되었습니다.

감사합니다.

댓글 달기

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