java - Fake UDP Response For DNS -


as part of academic project write piece of code can generate fake udp response. doing using jnetpcap , here code:

public static void sendresponse() throws ioexception {         system.out.println("generating fake response!");         try {             string host = "fakeme.example.com";             int port = xxxx; //this port dns lookup service runs.             byte[] message = "hello boyz !".getbytes();             // internet address of specified host             inetaddress address;             address = inetaddress.getbyname("77.**.**.**");              // initialize datagram packet data , address             datagrampacket packet = new datagrampacket(message, message.length, address, port);             // create datagram socket, send packet through it, close it.             datagramsocket dsocket = new datagramsocket();             dsocket.send(packet);             dsocket.close();         } catch (socketexception ex) {             logger.getlogger(sniffer.class.getname()).log(level.severe, null, ex);         }     } 

it happens have service, when piece of code runs service should return value. in case fails.

where have screwed?

thanks.

additional information: piece of code calls is:

public static pcappackethandler<string> packet_handler(pcap pcap) { pcappackethandler<string> jpackethandler = new pcappackethandler<string>() {             udp udp = new udp();              @override             public void nextpacket(pcappacket packet, string user) {                  if (!packet.hasheader(udp)) {                     return; // not udp package, skip                 }                     try {                         system.out.println("fake response ");                         //send repsonse                         sendresponse();                     } catch (ioexception ex) {                         logger.getlogger(sniffer.class.getname()).log(level.severe, null, ex);                     }             }         };         return jpackethandler;     } 

please note: , running first , service (which dns lookup given web address check if spoofer working) in 2 terminal tabs. asked used port, put in port address of code. correct way it?

thanks again.