Code example for FileDescriptor

0
    /** 
     * Creates a socket on the specified interface. 
     */ 
    public RawSocket(String interfaceName) throws SocketException {
        mInterfaceName = interfaceName;
        fd = new FileDescriptor();
        create(fd, mInterfaceName);
        guard.open("close");
    } 
 
    /** 
     * Reads a raw packet into the specified buffer, with the 
     * specified timeout.  Packets not destined for the desired UDP 
     * port are discarded.  Returns the length actually read.  No 
     * indication of overflow is signaled.  The packet data will start 
     * at the IP header (EthernetII dest/source/type headers are 
     * removed). 
     */ 
    public int read(byte[] packet, int offset, int byteCount, int destPort,
        int timeoutMillis) {
        if (packet == null) {