免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1488 | 回复: 0
打印 上一主题 下一主题

tow or more data types in declaration 错误 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-04-07 14:22 |只看该作者 |倒序浏览
我在CU看到这个程序,自己调试的时候,总是有"tow or more  data types
in declaration of  'Open_Raw_Socket' " 请问这是什么问题?谢谢。我用的是redflag4.0。

另外问一下,用gcc编译程序时,如果错误比较多,满屏显示不完,用什么命令可以分屏显示?谢谢。

  1. #include <stdio.h>;
  2. #include <sys/socket.h>;
  3. #include <sys/types.h>;
  4. /*#include <socketbits.h>;*/
  5. #include <sys/ioctl.h>;
  6. #include <net/if.h>;
  7. #include <netinet/in.h>;
  8. #include <arpa/inet.h>;
  9. #include <unistd.h>;
  10. #include "headers.h"

  11. #define INTERFACE "eth0"

  12. /* Prototype area */
  13. int Open_Raw_Socket(void);
  14. int Set_Promisc(char *interface,int sock);

  15. int main()
  16. {
  17.         int sock,bytes_recieved,fromlen;
  18.         char buffer[65535];
  19.         struct sockaddr_in from;
  20.         struct ip *ip;
  21.         struct tcp *tcp;

  22.         sock = Open_Raw_Socket();
  23.         /*now since the socket has been created,
  24.           set the interface into promiscuous mode */
  25.         Set_Promisc(INTERFACE,sock);

  26.         while(1)
  27.         {
  28.                 fromlen = sizeof from ;
  29.                 bytes_recieved = recvfrom ( sock , buffer ,sizeof buffer ,
  30.                                 0 , ( struct sockaddr * ) &from , &fromlen ) ;
  31.                 printf ( "\n Bytes received :::%5d\n ",bytes_recieved ) ;
  32.                 printf ( "Source address ::: %s\n ",inet_ntoa( from.sin_addr ));
  33.                 ip = (struct ip *)buffer ;
  34.                /* See if this is a TCP packet */       
  35.                 if ( ip->;ip_protocol == 6)
  36.                 {
  37.                         /*this is a TCP packer*/
  38.                         printf (" IP header length ::: %d ",ip->;ip_length );
  39.                         printf (" Protocol ::: %d\n" ,ip->;ip_protocol);
  40.                         tcp = ( struct tcp * ) ( buffer + ( 4*ip->;ip_length ));
  41.                         printf (" Source port ::: %d\n ",ntohs (tcp->;tcp_source_port));
  42.                         printf ("Dest port ::: %d \n",ntohs (tcp->;tcp_dest_port));
  43.                 }
  44.         }
  45. }

  46. int Open_Raw_Socket()
  47. {
  48.         int sock;
  49.         if ((sock =socket(AF_INET,SOCK_RAW,IPPROTO_TCP))<0 )
  50.         {
  51.                 //then the socket was not created properly and must die
  52.                 perror ( "The taw socket was not created" );
  53.                 exit(0);
  54.         }
  55.         return (sock);
  56. }

  57. int Set_Promisc(char *interface ,int sock )
  58. {
  59.         struct ifreq ifr;
  60.         strncpy ( ifr.ifr_name ,interface ,strnlen (interface)+1);
  61.         if ((ioctl(sock ,SIOCGIFFLAGS, &ifr)== -1))
  62.         {
  63.                 /*Could not retrieve flags for the interfaxe */
  64.                 perror (" Could not retrive flags for the interface ");
  65.                 exit (0);
  66.         }
  67.         printf ("The interface is ::: %s \n",interface);
  68.         perror("REtrieved flags from interface successfully");


  69.         /*Now that the flags have been retrieved */
  70.         /* set the flags to PROMISC */
  71.         ifr.ifr_flags|=IFF_PROMISC;
  72.         if (ioctl (sock,SIOCSIFFLAGS, &ifr)==-1)
  73.         {
  74.                 /*Could not set the flags on the interface */
  75.                 perror("Could not set the PROMISC flag:");
  76.                 exit(0);
  77.         }
  78.         printf ("setting interface :::%s ::: to promisc", interface);

  79.         return(0);
  80. }
复制代码

  1. /******************headers.h***************************/
  2. /*structure of an ip header*/
  3. struct ip
  4. {
  5.         unsigned int        ip_length:4; /*little-endian*/
  6.         unsigned int        ip_version:4;
  7.         unsigned char        ip_tops;
  8.         unsigned short        ip_total_length;
  9.         unsigned short        ip_id;
  10.         unsigned short        ip_flags;
  11.         unsigned char        ip_ttl;
  12.         unsigned char        ip_protocol;
  13.         unsigned short        ip_cksum;
  14.         unsigned int        ip_source;
  15.         unsigned int        ip_dest;
  16. };


  17. /*Structure of a TCP header */
  18. struct tcp
  19. {
  20.         unsigned short        tcp_source_port;
  21.         unsigned short        tcp_dest_port;
  22.         unsigned int        tcp_seqno;
  23.         unsigned int        tcp_ackno;
  24.         unsigned int        tcp_res1:4,        /*little-endian*/
  25.         tcp_hlen:4,
  26.         tcp_fin:1,
  27.         tcp_syn:1,
  28.         tcp_rst:1,
  29.         tcp_psh:1,
  30.         tcp_ack:1,
  31.         tcp_urg:1,
  32.         tcp_rest2:2;
  33.         unsigned short        tcp_winsize;
  34.         unsigned short        tcp_cksum;
  35.         unsigned short        tcp_urgent;
  36. }
  37. /*****************EOF***************************/
  38.        


  39.        
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP