Quantcast
Channel: Adobe Community : Popular Discussions - Archived Discussions
Viewing all articles
Browse latest Browse all 21156

Datagramsocket won't send to IP 255.255.255.255

$
0
0

I am tyring to implent a DHCP detector, so that I can tell if a client LAN has DHCP running, which is a requirement for installation of hardware I am working with, and so I form up a packet for DHCP discovery, a few hundred bytes, and send it to port 68 on IP 255.255.255.255; however when I run wireshark the packet never gets sent; the trace is empty, and of course with no packet sent I get no answer.  I tried the same code on Mac and WIndows; on Mac the system won't allow binding of ports below 1024, but on Windows one time I get a warning about firewall, but the further times nothing gets emitted. I am wondering if the Windows Vista system is blocking this request or if this is an Adobe bug... very mysterious and I am wondering if UDP requests to port 68 are being blocked.

 

Anyone ever try this in Air like me?

 

here is the code:

 

         g_datagramSocket = new DatagramSocket();
        g_datagramSocket.addEventListener(DatagramSocketDataEvent.DATA, on_DatagramReceived);
       
             // bind the socket to our local port
             //  bind on port 55568 works okay against localport 10.0.0.3
             //  port 68 fails, port 67 fails too, 546 fails
             //  IP address 127.0.0.1 is localport, a shortcut for the current IP address.
             //  mac apps cannot bind below 1024 unless administrator priv.
         g_datagramSocket.bind(68, "10.0.0.10");

 
              //  send the DHCPDiscovery packet to IP 255.255.255.255 port 67
         var packet:ByteArray = new ByteArray();
             var ii;
            
             //  fill the packet with all zeroes
             //for (ii=0; ii<308; ii++) packet.writeByte(0);
             //packet.position = 0;
            
             //  set up the rest of bytes
             packet.writeByte(0x01);            //  byte 0: opcode 1
             packet.writeByte(0x01);            //  byte 1: hardware address type 1=10Mb ethernet
             packet.writeByte(0x06);            //  byte 2: hardware address length 6
             packet.writeByte(0x00);            //  byte 3: hops 0
             packet.writeUnsignedInt (0x12345678);  // bytes: 4-7: 32 bit transaction id
             packet.writeUnsignedInt (0);  // 2 bytes: secs, 2 bytes: flags
             packet.writeUnsignedInt (0);  // 4 bytes: client IP address
             packet.writeUnsignedInt (0);  // 4 bytes: your IP address
             packet.writeUnsignedInt (0);  // 4 bytes: server IP address
             packet.writeUnsignedInt (0);  // 4 bytes: relay IP address
           
             //  16 byte hardware address
             packet.writeUnsignedInt (0x00BBCCDD);  // 4 bytes: MAC address bytes 0-3
             packet.writeUnsignedInt (0xEEFF0000);  // 4 bytes: MAC address bytes 4-7
             packet.writeUnsignedInt (0);  // 4 bytes:
             packet.writeUnsignedInt (0);  // 4 bytes:
        
             //  padding (64+128 byes)
             for (ii=0; ii<192; ii++) packet.writeByte (0);
            
             //  options
             packet.writeByte (99);  // magic cookie
             packet.writeByte (130);  // magic cookie
             packet.writeByte (83);  // magic cookie
             packet.writeByte (99);  // magic cookie

             packet.writeByte (53);  // OP:  DHCP message type
             packet.writeByte (1);        //  DHCP discover

 

             packet.writeByte (255);        //  OP: End of options
           
        g_datagramSocket.send(packet, 0, packet.length, "255.255.255.255", 67);
                //g_datagramSocket.flush();  // flush doesn't exist on datagram sockets
               
              //Listen for incoming datagrams
            g_datagramSocket.receive();  


Viewing all articles
Browse latest Browse all 21156

Trending Articles