开发者

Kernel land socket connect timeout

once again, i need your help to my kernel module. I have implemented an client module, but each time, connect function return errno=110 (Timeout). I don't understand why ? To test this module, i've started netcat in listen mode (nc -vl -p4242). Do you have any suggestion about this mystical bug

int             init_module(void)
{
  struct socket*        sock = NULL;
  struct sockaddr_in*   dest = {0};
  int                   retVal = 0;

  dest = (struct sockaddr_in*)kmalloc(sizeof(struct sockaddr_in), GFP_KERNEL);
  sock_create(PF_INET, SOCK_STREAM, IPPROTO_TCP, &sock);
  dest->sin_family = AF_INET;
  dest->sin_addr.s_addr = htonl(in_aton("127.0.0.1"));
  dest->sin_port = htons(4242);
  printk(KERN_EMERG "Connect to %X:%u\n", dest->sin_addr.s_addr, 4242);

  retVal = sock->ops->connect(sock, (struct sockaddr*)dest, sizeof(struct sockaddr_in), !O_NONBLOCK);
  if (retVal >= 0) {
    printk(KERN_EMERG "Connected\n");
    sock_release(sock);
  }
  else
    printk(KERN_EMERG "Error %d\n", -retVal);

  return (0);
}

Debug output (dmesg)

Message from syslogd@century at Sun Ju开发者_开发百科n 19 08:41:33 2011 ...
century kernel: Connect to 7F000001:4242

Message from syslogd@century at Sun Jun 19 08:41:54 2011 ...
century kernel: Error 110

Error code 110 is "Timeout".


in_aton("127.0.0.1"); already gives the address in network byte order.

By doing htonl(in_aton("127.0.0.1")); you're actually trying to connect to 1.0.0.127

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜