LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
12
返回列表 发新帖
楼主: xiachongbaogc

请问: printf 如何把打印信息输出到别人telnet登陆的终端上。

[复制链接]
 楼主| 发表于 2007-10-30 16:04:03 | 显示全部楼层
printf("\n--- ttyp: %s\n", ttyname(1));
回复 支持 反对

使用道具 举报

 楼主| 发表于 2008-7-24 15:25:02 | 显示全部楼层
自己整理.
当用户telnet登录后 用户通过ttyname(1); 来获得terminated pathname of the terminal device that is open on the file . sprintf(strbuf, "%s", ttyname(1));
然后用ttyId = atoi(strbuf); 获得 Id,  if(ttyId== 0 &&  strchr(strbuf, '0') == NULL)  则说明这是console, 则 ttyId 设为 0xff ; 然后把ttyId 发送给server.

server:
if(ttyId == 0xFF)
   strcpy(file, "/dev/console");
else
   sprintf(file, "/dev/ttyp%d", ttyId);

fd = open(file, O_RDWR);
dup2(fd,  1);
printf("\n test \n");
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

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