|
我用命令gcc xxx.c -o xxx编译程序时出现提示:
xxx.c:8:two or more data types in declaration of 'main'
不知道是什么原因,希望解答,谢谢.
我的代码:
#include <stdio.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include "headers.h"
int main()
{
int sock, bytes_received, fromlen;
char buffer[65535];
struct sockaddr_in from;
struct ip *ip;
struct tcp *tcp;
sock=socket(AF_INET, SOCK_RAW, IPPROTO_TCP);
while(1)
{
fromlen=sizeof from;
bytes_received=recvfrom(sock,buffer,sizeof buffer,
0,(struct sockaddr*)&from,&fromlen);
printf("\nByte_received:::%5d\n", bytes_received);
printf("Source address:::%s\n", inet_ntoa(from.sin_addr));
ip=(struct ip*)buffer;
printf("IP header length:::%d\n", ip->ip_length);
printf("Protocal:::%d\n",ip->ip_protocol);
tcp=(struct tcp*)(buffer+(4*ip->ip_length));
printf("Source port:::%d\n", ntohs(tcp->tcp_source_port));
}
return 0;
} |
|