모듈화 분할. 컴파일 시 too few arguments to functon 오류..
글쓴이: domiisa / 작성시간: 목, 2011/04/28 - 2:43오후
daemon.c 한파일에 있던걸 모듈화로 분할 했는데 컴파일 오류가 납니다.
daemon.c:18:too few arguments to functon 'socket'
이 오류가 뜨는데 검색해보니 인자의 수가 적거나 맞지 않다라고 나오는데 인자가 없는데 왜 뜨는지 모르겠네요
daemon.c 파일
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stddef.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <arpa/inet.h>
#include <sys/types.h>
#include <stdlib.h>
#include "uds.h"
int main(int argc, char** argv)
{
int fd;
fd=socket();
char buf[] = "aaaaaaaaaaaaaa";
write(fd, buf, strlen(buf));
char buff[1024];
memset(buff,0,1024);
read(fd,buff,sizeof(buff));
printf("server : %s\n",buff);
bail:
close(fd);
return 0;
}socket.c 파일
#include "uds.h"
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stddef.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <arpa/inet.h>
#include <sys/types.h>
#include <stdlib.h>
//extern struct sockaddr_un sockAddr;
//extern socklen_t sockLen;
int makeAddr(const char* name, struct sockaddr_un* pAddr, socklen_t* pSockLen)
{
int nameLen = strlen(name);
if (nameLen >= (int) sizeof(pAddr->sun_path) -1)
return -1;
pAddr->sun_path[0] = '\0';
strcpy(pAddr->sun_path+1, name);
pAddr->sun_family = AF_UNIX;
*pSockLen = 1 + nameLen + offsetof(struct sockaddr_un, sun_path);
return 0;
}
int socket()
{
struct sockaddr_un sockAddr;
socklen_t sockLen;
int fd = socket(PF_UNIX, SOCK_STREAM, 0);
/* 소켓생성실패 */
if (fd < 0) {
perror("client socket() error");
return 1;
}
if (makeAddr("com.extrus.test.uds", &sockAddr, &sockLen) < 0)
return 1;
if (connect(fd,(const struct sockaddr*) &sockAddr,sockLen) <0 )
{
perror("connect error");
goto bail;
}
return fd;
}uds.h 파일
#ifndef __UDS_H #define __UDS_H int socket(); int makeAddr(const char* name, struct sockaddr_un* pAddr, socklen_t* pSockLen); #endif
Forums:


#include 에 int socket(int
#include <sys/socket.h> 에
int socket(int domain, int type, int protocol);
라고 정의된게 있어서 그런가 보네요. 함수 이름을 바꿔보세요.
$ whatis socket
Socket (3pm) - load the C socket.h defines and structure manipulators
socket (2) - create an endpoint for communication
socket (3p) - create an endpoint for communication
socket (7) - Linux socket interface
socket (n) - Open a TCP network connection
socket [] (2) - create an endpoint for communication
socket [] (7) - Linux socket interface
socket [] (n) - Open a TCP network connection
$ man 3p socket
c는 함수 이름이 같으면 안됩니다.
Gentoo Rules!
아하~
아 ㄳ합니다 해결 댓네요^^;
댓글 달기