Linux伊甸园论坛's Archiver

liuke19851220 发表于 2008-4-15 11:51

网络流量监控程序,帮忙看看

毕业设计题目,网络流量监控软件,c语言写的,代码如下,我用gcc编译没出问题)wQ lb| nM%c IZ]
#include  <stdio.h>  
]7aF*F!R(Hc7y1s #include  <stdlib.h>
A!Um ~,n,A!B #include <netdb.h>
3M^-qX]6B&w8U #include <netinet/tcp.h>nt Y:u1u
#include <netinet/udp.h>
i2~j&C2|f O2{ #include <stdlib.h>
J!J(HF \R #include <unistd.h>
7~ w GN5q #include <signal.h>#\+F5y,@3I/R%y
#include <net/if.h>
XoQ$?lc#F #include <net/if_arp.h>
q+H1M,a D #include <sys/ioctl.h>
9?~4pZs O:h #include <sys/stat.h>
{u$` B4UMh #include <fcntl.h>
l|'Zq&QF#d"m ^ #include <linux/if_ether.h>
i0u:az,e:D6o+@Yv #include <linux/net.h>c;W9\acii$D F
#include <net/ethernet.h>
c$a Ld6hGwR5YCC0] #include <errno.h>
8_+S?9KOz #include <netpacket/packet.h>
:W3E$km3q(uQ #include <asm/types.h>(Y#Jp2Qa:M1Kx L
#include <endian.h>(p)B.]5`SVb t
#include <byteswap.h>*k9d-D4jXX%T W M
#include <pthread.h>K a9O1P/n H)\1F
#include <sys/un.h>
2A_|nYo #include <time.h>S7ARr9p&Aq2m
#include <sys/time.h>hf,Pr3q

(o*J1hJ L)M)Ik void set_timer(int interval){
M}J$MKp|o0s
)w6g+|T#[,R         struct itimerval itv, oldtv;
(`7Uo?9Q         itv.it_interval.tv_sec = interval;
IP Kk qD!A]J ?o,IW         itv.it_interval.tv_usec = 0;
I]'^'m}l{ g7[         itv.it_value.tv_sec = interval;
,L6d [Mu|5[7l!D         itv.it_value.tv_usec = 0;
U#leEv3d%L#d Q         setitimer(ITIMER_REAL, &itv, &oldtv); v+C*vp%|4K6u?
}MP?U(|`e
int count8e*zT'S5Fz3] M M F
void time_handle()
"R4p ]$F9to*z {
bI|E/V int i;`u @]$B

bL-j2I"|&cB printf("bandwidth is %d\n",count);
d Md2v5l\"h:O count=0;
IG*|C+] K Ed6?2Gh
}0D#@*T]&eEd8U
nr-L.bmD
n5|j9Z^5_
f |}i4T
int main()9P$QGjOm$@;ud3{k;j
{
&X0xe,O[ ~my int sock;h:tT_3Jp1Nf
struct ifreq ifstruct;c(n8Tam(sf}
struct sockaddr_ll sll;
"l0jpV] b i struct sockaddr_in addr;
F,c0r$I3Gp}%D char buf[2000];
:\ oZB+Nyf int r;
9H2\.tk*E int len;
2K6\V tN{ d zw len = sizeof(addr);
%J0q8jX0q"n'\+dd if((sock = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_IPV6))) == -1)
![muz Sf {
(gQ)\ ZH#ta }
b+b'dJeC/NA sll.sll_family = PF_PACKET;5I4E[-b p;z$xj
        sll.sll_protocol = htons(ETH_P_IPV6);Q0`V%pbIi0SE/M.MB
strcpy(ifstruct.ifr_name, "eth1");
8X+z,{)li?`l ioctl(sock, SIOCGIFINDEX, &ifstruct);
r+z4j4R)JDxK+as0\ sll.sll_ifindex = ifstruct.ifr_ifindex;
c9@cl2N]H `G bind(sock,(struct sockaddr*)&sll,sizeof(struct sockaddr_ll));0U vb.|Ir2yI
signal(SIGALRM, time_handle);4{ z:@kA z
set_timer(1);G+wC!Iw2{%e{P7p8U
count=0;
#uw9|8u#Ep/^l for(; ;)
$m\GtJ~ {
9oO Q-})h y x0nv'T r = recvfrom(sock,(char *)buf,sizeof(buf), 0, (struct sockaddr *)&addr,&len);
M\!~r6V+_ x6l#Kn count+=r;
iR)A O2f(Ix }0tK,?4C.lw-QXn
}3d$K%g$d:T$FY(W:D2W6m
帮我看看啊,那里有问题,急啊````Z:On!Xz;e0L
P7e1K%isGKx
[[i] 本帖最后由 liuke19851220 于 2008-4-18 08:49 编辑 [/i]]

luren04 发表于 2008-4-15 15:19

哈,我的论文则是linux下包过滤防火墙的架构。

diwayou 发表于 2008-4-15 23:35

struct itimerval struct ifreq 定义这两个结构体的头文件没有包含吧?

flag 发表于 2008-4-16 11:04

编译没出问题?运行出问题?!e%[$M;Vw T
楼主把问题表达清楚了吗?

liuke19851220 发表于 2008-4-17 12:54

#include  <stdio.h>  
4n6g`$@Ns #include  <stdlib.h>

liuke19851220 发表于 2008-4-17 12:56

bandwidth is -3768778
nK'? j:cX)iF8U0E ^ bandwidth is -3506673:e$^6o&_T,nbS8a
bandwidth is -3618825
7h L4[Te7np{_ bandwidth is -3555190Y$Q{+N#V@
bandwidth is -3586732
'H-t$F/bX#dx 这个是运行结果

flag 发表于 2008-4-17 13:35

count没见到在哪里定义的啊?

liuke19851220 发表于 2008-4-18 08:11

忘记了,发错程序了,这个是我没改之前的,改了后还是有那个问题,带宽不可能是负值的阿

flag 发表于 2008-4-18 08:27

I 服了 U,你到底想不想解决问题。到现在连准确的程序都没看到。。。。。

liuke19851220 发表于 2008-4-18 08:47

不好意思啊```我重新搞下,帮我看看```我在ubuntu下用gcc编译,没有警告和错误,运行时出了哪个问题,不知道是怎么了

diwayou 发表于 2008-4-21 03:07

我的回复下面怎么那么多广告呢?

页: [1]

Powered by Discuz! Archiver 6.1.0  © 2001-2007 Comsenz Inc.