LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 836|回复: 6

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

[复制链接]
发表于 2004-5-31 15:07:10 | 显示全部楼层 |阅读模式
哪位做过嵌入式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
救救我呀!!
谢谢先!!
发表于 2004-6-14 10:50:23 | 显示全部楼层

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

内网的pc(win2000)是否可以共享文件和打印服务?谢谢。
dhcp直接指定为dns为isp的服务器。
发表于 2004-6-14 13:00:14 | 显示全部楼层
dhcp自己添的设置,不写dns项就ok
发表于 2004-5-31 22:22:07 | 显示全部楼层

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

说明在书上,源码在这:
client.c
[php]
/*
* A simple C/S mode communication example demo
*
* client.c
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <netdb.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <sys/socket.h>

#define PORT 2000
#define MAXDATASIZE 100

int main(int argc, char *argv[])
{
  int sockfd, numbytes;
  char buf[MAXDATASIZE];
  struct hostent he;
  struct sockaddr_in their_addr;

  if(argc != 2){
    fprintf(stderr, "usage: client hostname\n");
    exit(1);
  }

  if((he = gethostbyname(argv[1])) == NULL){
    herror("gethostbyname");
    exit(1);
  }

  if((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1){
    perror("sockfd");
    exit(1);
  }

  their_addr.sin_family = AF_INET;
  their_addr.sin_port = htons(PORT);
  their_addr.sin_addr = *((struct in_addr *)he.h_addr);
  bzero(&(their_addr.sin_zero), 8);

  if(connect(sockfd, (struct sockaddr *)&their_addr, sizeof(struct sockaddr)) == -1){
    perror("connect");
    exit(1);
  }

  if((numbytes = recv(sockfd, buf, MAXDATASIZE, 0)) == -1){
    perror("recv");
    exit(1);
  }

  buf[numbytes] = '\0';
  printf("Received: %S", buf);
  close(sockfd);

  return 0;
}

[/php]

servise.c
[php]
/*
*
*
*
*
*/

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <sys/wait.h>
#include <sys/socket.h>

#define MYPORT 2000
#define BACKLOG 10

main()
{
        int sock_fd, new_fd;
        struct sockaddr_in my_addr;
        struct sockaddr_in their_addr;
        int sin_size;

        if((sock_fd = socket(AF_INET, SOCK_STREAM, 0)) == -1){
                perror("socket");
                exit(1);
        }

        my_addr.sin_family = AF_INET;
        my_addr.sin_port = htons(MYPORT);
        my_addr.sin_addr.s_addr = INADDR_ANY;
        bzero(&(my_addr.sin_zero),8);

        if(bind(sock_fd, (struct sockaddr *)&my_addr, sizeof(struct sockaddr)) == -1){
                perror("bind");
                exit(1);
        }

        if(listen(sock_fd, BACKLOG) == -1){
                perror("listen");
                exit(1);
        }

        while(1){
                sin_size = sizeof(struct sockaddr_in);

                if((new_fd = accept(sock_fd, (struct sockaddr *)&their_addr, &sin_size)) == -1){
                        perror("accept");
                        continue;
                }
                printf("server: got connection from %s\n",inet_ntoa(their_addr.sin_addr));

                if(!fork()){
                        if(send(new_fd, "Hello,World!\n",14,0) == -1){
                                perror("send");
                                close(new_fd);
                                exit(1);
                        }
                        close(new_fd);
                }
        }

        while(waitpid(-1, NULL, WNOHANG) > 0);

}

[/php]

兄弟得自己调试了,这段时间比较紧张啊
发表于 2004-5-31 22:29:52 | 显示全部楼层
合并了兄弟的贴子,见谅!
 楼主| 发表于 2004-6-10 09:24:12 | 显示全部楼层
呵呵,支持renbagshoes版★主的工作!!
发表于 2004-6-12 00:56:30 | 显示全部楼层
uClinux没有mmu管理存储器,在实现多个进程时(fork调用生成子进程)需要实现数据保护。
uClinux的fork和vfork:uClinux的fork等于vfork。实际上uClinux的多进程管理通过vfork来实现。这意味着uClinux系统fork调用完程后,要么子进程代替父进程执行(此时父进程已经sleep)直到子进程调用exit退出,要么调用exec执行一个新的进程,这个时候将产生可执行文件的加载,即使这个进程只是父进程的拷贝,这个过程也不能避免。当子进程执行exit或exec后,子进程使用wakeup把父进程唤醒,父进程继续往下执行。
uClinux的这种多进程实现机制同它的内存管理紧密相关。uClinux针对nommu处理器开发,所以被迫使用一种flat方式的内存管理模式,启动新的应用程序时系统必须为应用程序分配存储空间,并立即把应用程序加载到内存。缺少了MMU的内存重映射机制,uClinux必须在可执行文件加载阶段对可执行文件reloc处理,使得程序执行时能够直接使用物理内存。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表