请问如果用linux做dhcp和pdc服务器,不开启dns服务。。。。?

由 sunheart 在 05-31-2004 15:07 发表:

uclinux(多线程和多进程问题)

哪位做过嵌入式uclinux??给帮个忙!!

我用arm+uclinux想实现一个服务器,实现多个客户端,当客户端连接时能给客户端发送数据,我想做成能同时给多个客户发送数据,但是我用多进程(用vfork()函数)和多线程(用pthread_create()函数)编程都不能实现,在uclinux中,由于vfork函数执行后创建子进程,此时,执行子进程,而父进程被系统锁定,所以用进程编程时不能实现的。

我用线程编写的程序在生成image时出现如下错误,谁能给我看看,我该怎么做!!

arm-elf-gcc -Os -Dlinux -D__linux__ -Dunix -D__uClinux__ -DEMBED -I/home/sumy/uClinux-Samsung/lib/libc/include -I/home/sumy/uClinux-Samsung/lib/libm -I/home/sumy/uClinux-Samsung -fno-builtin -nostartfiles -I/home/sumy/uClinux-Samsung/linux-2.4.x/include -c -o server.o server.c

server.c:11: pthread.h: ?????????

make[2]: *** [server.o] Error 1

make[2]: Leaving directory `/home/sumy/uClinux-Samsung/user/myapp'

make[1]: *** [all] Error 2

make[1]: Leaving directory `/home/sumy/uClinux-Samsung/user'

make: *** [subdirs] Error 1

救救我呀!!

谢谢先!!


sunheart

┳┻┳┻┳┻┳┻┳┻┳┻┳┻┳┻┳

┻┳┻┳我要去撞墙清醒一下┳┻┳┻

┳┻┳┻┳┻┳┻┳┻┳┻┳┻┳┻┳

┻┳┻┳┻┳┻┳┻┳┻┳┻┳┻┳┻


由 renbagshoes 在 05-31-2004 22:22 发表:

看一下置顶推荐的那本书的嵌入式Linux网络功能实现部分

说明在书上,源码在这:

client.c

> PHP源码: > > * * * > >
>
> /*
> * A simple C/S mode communication example demo
> *
> * client.c
> *
> */
> #include

  1<stdio.h>   
  2&gt;  #include <stdlib.h>   
  3&gt;  #include <errno.h>   
  4&gt;  #include <string.h>   
  5&gt;  #include <netdb.h>   
  6&gt;  #include <sys types.h="">   
  7&gt;  #include <netinet in.h="">   
  8&gt;  #include <sys socket.h="">   
  9&gt;    
 10&gt;  #define PORT 2000   
 11&gt;  #define MAXDATASIZE 100   
 12&gt;    
 13&gt;  int main  (  int aront&gt; ,  char  *  argv  [])   
 14&gt;  {   
 15&gt;  int sockfd  ,  numbytes  ;   
 16&gt;  char buf  [  MAXDATASIZE  ];   
 17&gt;  struct hostent he  ;   
 18&gt;  struct sockaddr_in their_addr  ;   
 19&gt;    
 20&gt;  if(  argc  !=  2  ){   
 21&gt;  fprintf  (  stderr  ,  "usage: client hostname\n"  );   
 22&gt;  exit(  1  );   
 23&gt;  }   
 24&gt;    
 25&gt;  if((  he  =  gethostbyname  (  argv  [  1  ])) ==  NULL  ){   
 26&gt;  herror  (  "gethostbyname"  );   
 27&gt;  exit(  1  );   
 28&gt;  }   
 29&gt;    
 30&gt;  if((  sockfd  =  socket  (  AF_INET  ,  SOCK_STREAM  ,  0  )) == -  1  ){   
 31&gt;  perror  (  "sockfd"  );   
 32&gt;  exit(  1  );   
 33&gt;  }   
 34&gt;    
 35&gt;  their_addr  .  sin_family  =  AF_INET  ;   
 36&gt;  their_addr  .  sin_port  =  htons  (  PORT  );   
 37&gt;  their_addr  .  sin_addr  = *((  struct in_addr  *)  he  .  h_addr  );   
 38&gt;  bzero  (&amp;(  their_addr  .  sin_zero  ),  8  );   
 39&gt;    
 40&gt;  if(  connect  (  sockfd  , (  struct sockaddr  *)&amp; their_addr  ,  sizeof  (  struct sockaddr  )) == -  1  ){   
 41&gt;  perror  (  "connect"  );   
 42&gt;  exit(  1  );   
 43&gt;  }   
 44&gt;    
 45&gt;  if((  numbytes  =  recv  (  sockfd  ,  buf  ,  MAXDATASIZE  ,  0  )) == -  1  ){   
 46&gt;  perror  (  "recv"  );   
 47&gt;  exit(  1  );   
 48&gt;  }   
 49&gt;    
 50&gt;  buf  [  numbytes  ] =  ''  ;   
 51&gt;  printf  (  "Received: %S"  ,  buf  );   
 52&gt;  close  (  sockfd  );   
 53&gt;    
 54&gt;  return  0  ;   
 55&gt;  }   
 56&gt;  ?&gt;   
 57&gt;    
 58&gt;  `
 59&gt; 
 60&gt; * * *
 61&gt; 
 62&gt; `
 63
 64  
 65  
 66  
 67  
 68servise.c   
 69  
 70
 71
 72&gt; ` PHP源码: 
 73&gt; 
 74&gt; * * *
 75&gt; 
 76&gt; `   
 77&gt;    
 78&gt;  /*   
 79&gt;  *   
 80&gt;  *   
 81&gt;  *   
 82&gt;  *   
 83&gt;  */   
 84&gt;    
 85&gt;  #include <stdio.h>   
 86&gt;  #include <stdlib.h>   
 87&gt;  #include <errno.h>   
 88&gt;  #include <string.h>   
 89&gt;  #include <sys types.h="">   
 90&gt;  #include <netinet in.h="">   
 91&gt;  #include <sys wait.h="">   
 92&gt;  #include <sys socket.h="">   
 93&gt;    
 94&gt;  #define MYPORT 2000   
 95&gt;  #define BACKLOG 10   
 96&gt;    
 97&gt;  main  ()   
 98&gt;  {   
 99&gt;  int sock_fd  ,  new_fd  ;   
100&gt;  struct sockaddr_in my_addr  ;   
101&gt;  struct sockaddr_in their_addr  ;   
102&gt;  int sin_size  ;   
103&gt;    
104&gt;  if((  sock_fd  =  socket  (  AF_INET  ,  SOCK_STREAM  ,  0  )) == -  1  ){   
105&gt;  perror  (  "socket"  );   
106&gt;  exit(  1  );   
107&gt;  }   
108&gt;    
109&gt;  my_addr  .  sin_family  =  AF_INET  ;   
110&gt;  my_addr  .  sin_port  =  htons  (  MYPORT  );   
111&gt;  my_addr  .  sin_addr  .  s_addr  =  INADDR_ANY  ;   
112&gt;  bzero  (&amp;(  my_addr  .  sin_zero  ),  8  );   
113&gt;    
114&gt;  if(  bind  (  sock_fd  , (  struct sockaddr  *)&amp; my_addr  ,  sizeof  (  struct sockaddr  )) == -  1  ){   
115&gt;  perror  (  "bind"  );   
116&gt;  exit(  1  );   
117&gt;  }   
118&gt;    
119&gt;  if(  listen  (  sock_fd  ,  BACKLOG  ) == -  1  ){   
120&gt;  perror  (  "listen"  );   
121&gt;  exit(  1  );   
122&gt;  }   
123&gt;    
124&gt;  while(  1  ){   
125&gt;  sin_size  =  sizeof  (  struct sockaddr_in  );   
126&gt;    
127&gt;  if((  new_fd  =  accept  (  sock_fd  , (  struct sockaddr  *)&amp; their_addr  , &amp; sin_size  )) == -  1  ){   
128&gt;  perror  (  "accept"  );   
129&gt;  continue;   
130&gt;  }   
131&gt;  &amp;nb  ` `</sys></sys></netinet></sys></string.h></errno.h></stdlib.h></stdio.h></sys></netinet></sys></netdb.h></string.h></errno.h></stdlib.h></stdio.h>
Published At
Categories with 服务器类
Tagged with
comments powered by Disqus