luabind::object LuaProxy::NPC::layerObj(lua_State *L) const { if(!isValid_throw(L)) return luabind::object(); NPCMOB* thisnpc = ::NPC::Get(m_index); return findlayer(((std::string)thisnpc->layerName).c_str(), L); }
int echo_get_id(struct datalink *dl, struct MAC *srcmac, struct MAC *dstmac, uint32_t real_ip, uint32_t src, uint32_t *dly, uint16_t *ip_id ) { struct timeval tva,tvb; struct layer *proto; int n; if(gettimeofday(&tva,NULL) < 0 ){ fprintf(stderr,"gettimeofday returned error %s\n" ,strerror(errno)); return -1; } ICMPEchoRequest(dl,srcmac,dstmac,real_ip,src,rand()%0xFFFF , rand()%0xffff); proto = recvlayers(dl,&n); if( proto == NULL ){ fprintf(stderr,"recvlayers returned error %s\n" ,strerror(errno)); return -1; } if(gettimeofday(&tvb,NULL) < 0 ){ fprintf(stderr,"gettimeofday returned error %s\n" ,strerror(errno)); return -1; } *dly = tvb.tv_usec - tva.tv_usec; proto = findlayer(proto,LT_IP); fprintf(stderr,"ip_id=%x\n",ntohs(((xip)proto->proto)->ip_id)); if( proto == NULL ){ fprintf(stderr,"findlayer returned error %s\n" ,strerror(errno)); return -1; } *ip_id = ntohs( ((xip)proto->proto)->ip_id); return 0; }
int main(int argc, char **argv) { struct layer *head,*tcp; struct TCPSocket ts; struct MAC imac,dmac; uint32_t ip,dip,gip; uint16_t eport; int n; if(argc < 6) usage(*argv); if(if_menu(&imac) < 0) exit(1); str_to_ip(argv[1],&ip); str_to_ip(argv[2],&dip); str_to_ip(argv[5],&gip); if( ARPRequest(&imac,&dmac,ip,gip,5) < 0 ){ fprintf(stderr,"error: no route to host.\n"); exit(1); } ARPReply(&imac,ip,&dmac,gip); eport = atoi(argv[4]); createSocket(&ts,&imac,&dmac,ip,dip,atoi(argv[3]),atoi(argv[3])); filterDatalink("tcp"); head = NULL; while(!kbhit()){ if(ts.hostport++ < eport) SYN(&ts); if( ( head = recvlayers(&n) ) == NULL) continue; if( (tcp = findlayer(head,LT_TCP) ) != NULL ){ struct tcphdr *t; t = (xtcp)tcp->proto; if( ( ( t->th_flags & TH_SYN ) == TH_SYN) && ( ( t->th_flags & TH_ACK ) == TH_ACK) ){ printf("recv: SYN-ACK from port %d\n",ntohs(t->th_sport)); printlayers(tcp); RST(&ts); } } rmlayers(head); } closeDatalink(); exit(0); }