Commit 4c0d54fc authored by Junxing Zhang's avatar Junxing Zhang

stub files for Plab

parent 5e78b7a0
...@@ -2,7 +2,7 @@ all: stubd stub-monitor ...@@ -2,7 +2,7 @@ all: stubd stub-monitor
stubd: stubd.o stub-pcap.o stub.h stubd: stubd.o stub-pcap.o stub.h
gcc -g -Wall -lm -lpcap stubd.o stub-pcap.o -o stubd gcc -g -Wall -lm -lpcap stubd.o stub-pcap.o -o stubd
monitor-stub: monitor-stub.c stub.h stub-monitor: stub-monitor.c stub.h
gcc -g -Wall stub-monitor.c -o stub-monitor gcc -g -Wall stub-monitor.c -o stub-monitor
stubd.o: stubd.c stub.h stubd.o: stubd.c stub.h
gcc -g -Wall -c stubd.c gcc -g -Wall -c stubd.c
......
...@@ -103,6 +103,7 @@ int search_sniff_rcvdb(int path_id, u_long seqnum) { ...@@ -103,6 +103,7 @@ int search_sniff_rcvdb(int path_id, u_long seqnum) {
void pop_sniff_rcvdb(int path_id, u_long to_seqnum){ void pop_sniff_rcvdb(int path_id, u_long to_seqnum){
int to_index = search_sniff_rcvdb(path_id, to_seqnum); int to_index = search_sniff_rcvdb(path_id, to_seqnum);
if (to_index != -1) { if (to_index != -1) {
//if the packet has no payload or the last sent seqnum equals the pop number
if ((sniff_rcvdb[path_id].records[to_index].seq_end==sniff_rcvdb[path_id].records[to_index].seq_start) if ((sniff_rcvdb[path_id].records[to_index].seq_end==sniff_rcvdb[path_id].records[to_index].seq_start)
|| (sniff_rcvdb[path_id].records[to_index].seq_end-1 == to_seqnum)) { || (sniff_rcvdb[path_id].records[to_index].seq_end-1 == to_seqnum)) {
sniff_rcvdb[path_id].start = (to_index+1)%SNIFF_WINSIZE; //complete pop-up sniff_rcvdb[path_id].start = (to_index+1)%SNIFF_WINSIZE; //complete pop-up
...@@ -181,7 +182,7 @@ u_int16_t handle_IP(u_char *args, const struct pcap_pkthdr* pkthdr, const u_char ...@@ -181,7 +182,7 @@ u_int16_t handle_IP(u_char *args, const struct pcap_pkthdr* pkthdr, const u_char
ip_dst = ip->ip_dst.s_addr; ip_dst = ip->ip_dst.s_addr;
if (flag_debug){ if (flag_debug){
//For an unknown reason, inet_ntoa returns the same string if called twice in one fprintf //Note:inet_ntoa returns the same string if called twice in one line due to static string buffer
fprintf(stdout,"IP src:%s ", inet_ntoa(ip->ip_src)); fprintf(stdout,"IP src:%s ", inet_ntoa(ip->ip_src));
fprintf(stdout,"dst:%s hlen:%d version:%d len:%d\n",inet_ntoa(ip->ip_dst),hlen,version,len); fprintf(stdout,"dst:%s hlen:%d version:%d len:%d\n",inet_ntoa(ip->ip_dst),hlen,version,len);
} }
...@@ -327,7 +328,7 @@ void init_pcap(int to_ms) { ...@@ -327,7 +328,7 @@ void init_pcap(int to_ms) {
char string_filter[128]; char string_filter[128];
//struct in_addr addr; //struct in_addr addr;
dev = "eth0"; //"vnet"; dev = "vnet"; //"eth0";
/* ask pcap for the network address and mask of the device */ /* ask pcap for the network address and mask of the device */
pcap_lookupnet(dev,&netp,&maskp,errbuf); pcap_lookupnet(dev,&netp,&maskp,errbuf);
......
...@@ -232,7 +232,11 @@ int receive_monitor(int sockfd) { ...@@ -232,7 +232,11 @@ int receive_monitor(int sockfd) {
memcpy(&tmpulong, nextptr, SIZEOF_LONG); memcpy(&tmpulong, nextptr, SIZEOF_LONG);
destnum = ntohl(tmpulong); destnum = ntohl(tmpulong);
//receive dest addrs //return success if no dest addr is given
if (destnum == 0){
return 1;
}
//otherwise, receive dest addrs
if (recv_all(sockfd, buf, destnum*SIZEOF_LONG)==0) { if (recv_all(sockfd, buf, destnum*SIZEOF_LONG)==0) {
return 0; return 0;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment