- 论坛徽章:
- 0
|
我在CU看到这个程序,自己调试的时候,总是有"tow or more data types
in declaration of 'Open_Raw_Socket' " 请问这是什么问题?谢谢。我用的是redflag4.0。
另外问一下,用gcc编译程序时,如果错误比较多,满屏显示不完,用什么命令可以分屏显示?谢谢。
- #include <stdio.h>;
- #include <sys/socket.h>;
- #include <sys/types.h>;
- /*#include <socketbits.h>;*/
- #include <sys/ioctl.h>;
- #include <net/if.h>;
- #include <netinet/in.h>;
- #include <arpa/inet.h>;
- #include <unistd.h>;
- #include "headers.h"
- #define INTERFACE "eth0"
- /* Prototype area */
- int Open_Raw_Socket(void);
- int Set_Promisc(char *interface,int sock);
- int main()
- {
- int sock,bytes_recieved,fromlen;
- char buffer[65535];
- struct sockaddr_in from;
- struct ip *ip;
- struct tcp *tcp;
- sock = Open_Raw_Socket();
- /*now since the socket has been created,
- set the interface into promiscuous mode */
- Set_Promisc(INTERFACE,sock);
- while(1)
- {
- fromlen = sizeof from ;
- bytes_recieved = recvfrom ( sock , buffer ,sizeof buffer ,
- 0 , ( struct sockaddr * ) &from , &fromlen ) ;
- printf ( "\n Bytes received :::%5d\n ",bytes_recieved ) ;
- printf ( "Source address ::: %s\n ",inet_ntoa( from.sin_addr ));
- ip = (struct ip *)buffer ;
- /* See if this is a TCP packet */
- if ( ip->;ip_protocol == 6)
- {
- /*this is a TCP packer*/
- printf (" IP header length ::: %d ",ip->;ip_length );
- printf (" Protocol ::: %d\n" ,ip->;ip_protocol);
- tcp = ( struct tcp * ) ( buffer + ( 4*ip->;ip_length ));
- printf (" Source port ::: %d\n ",ntohs (tcp->;tcp_source_port));
- printf ("Dest port ::: %d \n",ntohs (tcp->;tcp_dest_port));
- }
- }
- }
- int Open_Raw_Socket()
- {
- int sock;
- if ((sock =socket(AF_INET,SOCK_RAW,IPPROTO_TCP))<0 )
- {
- //then the socket was not created properly and must die
- perror ( "The taw socket was not created" );
- exit(0);
- }
- return (sock);
- }
- int Set_Promisc(char *interface ,int sock )
- {
- struct ifreq ifr;
- strncpy ( ifr.ifr_name ,interface ,strnlen (interface)+1);
- if ((ioctl(sock ,SIOCGIFFLAGS, &ifr)== -1))
- {
- /*Could not retrieve flags for the interfaxe */
- perror (" Could not retrive flags for the interface ");
- exit (0);
- }
- printf ("The interface is ::: %s \n",interface);
- perror("REtrieved flags from interface successfully");
- /*Now that the flags have been retrieved */
- /* set the flags to PROMISC */
- ifr.ifr_flags|=IFF_PROMISC;
- if (ioctl (sock,SIOCSIFFLAGS, &ifr)==-1)
- {
- /*Could not set the flags on the interface */
- perror("Could not set the PROMISC flag:");
- exit(0);
- }
- printf ("setting interface :::%s ::: to promisc", interface);
- return(0);
- }
复制代码
- /******************headers.h***************************/
- /*structure of an ip header*/
- struct ip
- {
- unsigned int ip_length:4; /*little-endian*/
- unsigned int ip_version:4;
- unsigned char ip_tops;
- unsigned short ip_total_length;
- unsigned short ip_id;
- unsigned short ip_flags;
- unsigned char ip_ttl;
- unsigned char ip_protocol;
- unsigned short ip_cksum;
- unsigned int ip_source;
- unsigned int ip_dest;
- };
- /*Structure of a TCP header */
- struct tcp
- {
- unsigned short tcp_source_port;
- unsigned short tcp_dest_port;
- unsigned int tcp_seqno;
- unsigned int tcp_ackno;
- unsigned int tcp_res1:4, /*little-endian*/
- tcp_hlen:4,
- tcp_fin:1,
- tcp_syn:1,
- tcp_rst:1,
- tcp_psh:1,
- tcp_ack:1,
- tcp_urg:1,
- tcp_rest2:2;
- unsigned short tcp_winsize;
- unsigned short tcp_cksum;
- unsigned short tcp_urgent;
- }
- /*****************EOF***************************/
-
-
复制代码 |
|