안녕하세요.. 갑자기 안되어서..질문을 올립니다...
if((s_fd = accept(server_fd,(struct sockaddr *)&s_addr, &s_len)) < 0) 여기에서 억셉트된 상대방 주소와 포트를 어떻게 뽑아내죠??
/******************************************************************************/ /* Wait Client Connection */ /* Prototype int WaitConnect(fd, buff) */ /* Arguments int fd; int socket discriptor */ /* char *buff; Client address buffer */ /* Return new socket fd */ /******************************************************************************/ int WaitConnect(fd, buff) int fd; char *buff; { int newfd, clilen; struct sockaddr_in cli_addr; unsigned char *p; clilen = sizeof(cli_addr); newfd=accept(fd, (struct sockaddr *)&cli_addr, &clilen); if(!buff) return newfd;
p = (unsigned char *)&cli_addr.sin_addr; sprintf(buff, "%3d.%3d.%3d.%3d", *p, *(p+1), *(p+2), *(p+3)); return newfd; }
텍스트 포맷에 대한 자세한 정보
<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]
Re: accept된 상대방 주소를 어떻게 뽑아내죠?
/******************************************************************************/
/* Wait Client Connection */
/* Prototype int WaitConnect(fd, buff) */
/* Arguments int fd; int socket discriptor */
/* char *buff; Client address buffer */
/* Return new socket fd */
/******************************************************************************/
int WaitConnect(fd, buff)
int fd;
char *buff;
{
int newfd, clilen;
struct sockaddr_in cli_addr;
unsigned char *p;
clilen = sizeof(cli_addr);
newfd=accept(fd,
(struct sockaddr *)&cli_addr,
&clilen);
if(!buff) return newfd;
p = (unsigned char *)&cli_addr.sin_addr;
sprintf(buff, "%3d.%3d.%3d.%3d", *p, *(p+1), *(p+2), *(p+3));
return newfd;
}
댓글 달기