Chinaunix

标题: shell程序怎么读取c语言中的返回。 [打印本页]

作者: 阿徐    时间: 2006-02-22 16:48
标题: shell程序怎么读取c语言中的返回。
shell 如下:
echo "\033[3;10H远程主机名[或IP]:\c"
read host
  if [ "$host" = "" ];then
   exit
  fi
echo "\033[4;10H远程机用户名:\c"
read user
echo "\033[5;10H远地用户口令:\c"
echo "\033[2;8;8m\c"
read password


因为想得到telnet上来的机器ip,然后通过shell 自动ftp回去,写大个程序得到客户端ip,不知道
该如何把c语言中得到的ip付给shell中,有谁知道吗
#include <sys/types.h>;
#include <utmpx.h>;
#include <pwd.h>;
#include <stdio.h>;

//char * getclientaddr(void)
main()
{
        static char ClientAddr[255],getaddr[35];
        struct utmpx * entry=NULL;
        char * mytty;
        mytty=ttyname(0)+(unsigned char *)strlen("/dev/");
        
        setutxent();
        while(entry=getutxent())
        {
                strcpy(getaddr,entry->ut_line);
                if(!strcmp(entry->ut_line,mytty))
                {
                        strcpy(ClientAddr,entry->ut_host);
                        break;
                }
        }
        endutxent();
        printf("%s\n",ClientAddr);
        return ClientAddr;
}
作者: wmjie    时间: 2006-02-22 22:26
ip=`getclientaddr`  ??




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2