EzDevInfo.com

ethernet interview questions

Top ethernet frequently asked interview questions

Read MAC Address from network adapter in .NET

I'd like to be able to read the mac address from the first active network adapter using VB.net or C# (using .NET 3.5 SP1) for a winform application


Source: (StackOverflow)

How to filter MAC addresses using tcpdump?

I am running tcpdump on DD-WRT routers in order to capture uplink data from mobile phones. I would like to listen only to some mac addresses. To do this I tried to run the command using a syntax similar to Wireshark:

tcpdump -i prism0 ether src[0:3] 5c:95:ae -s0 -w | nc 192.168.1.147 31337

so that I can listen to all the devices that have as initial mac address 5c:95:ae.

The problem is that the syntax is wrong and I was wondering if anyone of you knows the right syntax to get what I want.


Source: (StackOverflow)

Advertisements

OpenCV: How to capture frames from an Ethernet camera

I have earlier programmed USB webcam, where the sole aim is to get the live frames from the camera and display in a window. I used cvCaptureFromCAM for that purpose, which worked fine for USB Camera(see code below).

I want to know how do I capture frames from a Gigabit Ethernet camera? I guess I need to capture frames from some default IP address using some API. Can some one point me to right direction?

I will be using C++ with OpenCV on Windows 7 on an Intel i3 processor.

#include "cv.h"
#include "highgui.h"
#include <stdio.h>

// A Simple Camera Capture Framework 
int main() {
    CvCapture* capture = cvCaptureFromCAM( CV_CAP_ANY );
    if ( !capture ) {
        fprintf( stderr, "ERROR: capture is NULL \n" );
        getchar();
        return -1;
    }

    // Create a window in which the captured images will be presented
    cvNamedWindow( "mywindow", CV_WINDOW_AUTOSIZE );

    // Show the image captured from the camera in the window and repeat
    while ( 1 ) {
        // Get one frame
        IplImage* frame = cvQueryFrame( capture );

        if ( !frame ) {
            fprintf( stderr, "ERROR: frame is null...\n" );
            getchar();
            break;
        }

        cvShowImage( "mywindow", frame );

        // Do not release the frame!
        // If ESC key pressed, Key=0x10001B under OpenCV 0.9.7(linux version),
        // remove higher bits using AND operator
        if ( (cvWaitKey(10) & 255) == 27 ) break;
    }

    // Release the capture device housekeeping
    cvReleaseCapture( &capture );
    cvDestroyWindow( "mywindow" );
    return 0;
}

Update

So now I am able to display the live images in the vendor provided software GUI. But still I want to display the image (and possibly video) using the IP address of the camera.

When I know the IP address of the camera, why can't I access the data (images) sent by the camera and display on browser? I tried typing the ip address of the camera (i.e 192.169.2.3) on my browser (192.169.2.4), but it say "page not found". What does it mean?


Source: (StackOverflow)

Detecting network state (connected - disconnected) in C#

I am in need of a piece of code that can detect if a network connection is connected or disconnected. The connected state would mean a cable was plugged into the Ethernet connection. A disconnected state would mean there is not cable connected.

I can't use the WMI interface due to the fact that I'm running on Windows CE. I don't mind invoking the Win32 API but remember that I'm using Windows CE and running on the Compact Framework.


Source: (StackOverflow)

How do you get the ethernet address using Java?

I would like to retrieve the ethernet address of the network interface that is used to access a particular website.

How can this be done in Java?

Solution Note that the accepted solution of getHardwareAddress is only available in Java 6. There does not seem to be a solution for Java 5 aside from executing i(f|p)confing.


Source: (StackOverflow)

Anybody knows the truth about USB to RJ45 connector support on Android devices?

I need to use Android tablet or smartphone to connect a specialized device through RJ45 in the open location, without additional power and probably under bad weather. The device supports HTTP and has RJ45 connector. There is no wireless support. The clients are very reluctant to carry around the wireless router and its battery.

There are some postings on the web that since 3.2 or about Android includes support for Ethernet to USB converter, and also there is a separately published driver for Android devices and some discussions here even list supported devices. Unfortunately all these instructions are clearly for the rooted device. Has anybody ever succeeded to get RJ45 to USB adapter working on a non-rooted Android device, and with which exactly hardware?

I have tried on two devices, Galaxy Nexus (Android 4.1.2, kernel 3.0.31) and ThinkPad tablet (Android 4.0.3, kernel 2.6.39). Galaxy Nexus has USB OTG (that works for devices like desktop mouse) and ThinkPad even features the full size USB Host ports (that also works). So yes, there is the tested and working USB host support.

I have tried multiple USB to Ethernet converters, including Apple Mac converter, D-Link DUB E-100SMC2209USB/ETH and some others. Some of these converters work fine even on handhelds running QTopia, but none works with my two Android devices. The converters are somwhat "alive" with they LEDs flashing but seem not attempting any DHCP or the like. I also tried to write the driver using Android USB host API but seems not very trivial.

Update: I have just disovered that ASIX provides as is nothing drivers for they converter devices, claiming that these drivers should work also for Android (high versions including), see here for instance.

Update: Android kernel 3.0.31 seems containing the whole bunch of various USB to RJ45 converter drivers, with many of them active by default. So probably it is all just about rooting...

Update: ASIX drivers can also be built and load into Android kernel no problem.


Source: (StackOverflow)

What is the total length of pure TCP Ack sent over ethernet?

I have captured a pure TCP ack using Microsoft Network Monitor. It shows the captured frame length as 54 bytes. IP header (20 bytes) + TCP Header (20 bytes) + Src MAC (6 bytes) + Dst MAC (6 bytes) + Frame Type (2 bytes). I don't see a CRC (4 byte) field. I know the minimum frame length for Ethernet is 64 bytes (46 + 18) and the maximum is 1518. Why don't I see this in Network Monitor? The value of the data field for Ethernet frame is 46-1500. Is the IP dataframe padded with zeros in 6 octets to make the total frame length 46?

Found Answer: The minimum length of the data field of a packet sent over an Ethernet is 46 octets. If necessary, the data field should be padded (with octets of zero) to meet the Ethernet minimum frame size. This padding is not part of the IP packet and is not included in the total length field of the IP header. http://www.ietf.org/rfc/rfc0894.txt

What is minimum overhead for a frame in IEEE 802.11. What is the maximum and minimum frame size there? What will be the frame size of a pure TCP Ack over WiFi?

I will also accept partial answers


Source: (StackOverflow)

is it possible to do memcpy in bits instead of bytes?

I would like to know is it possible to do memcpy by bits instead of bytes?

I am writing a C code for Ethernet frame with VLAN tagging, in which I need to fill different values for VLAN header attributes (PCP-3bits,DEI-1bit,VID-12bits).

How can I do memcpy to those bits, or any other possibility to fill values to those attributes in bits.

Thanks in advance !


Source: (StackOverflow)

How can I fetch the ethernet port given the ip address?

I am trying to write a bash script to fetch the ethernet port of an interface whose IP address I know. I need to grab this from ifconfig but can't seem to be able to figure out how to go about it. Any ideas?

Thanks.


Source: (StackOverflow)

How to send Ethernet-Frames in Java without TCP/IP Stack

My Java application should control an external device (EtherCAT Bus technology) directly connected to the network interface of my computer(Ubuntu and Windows). No other network devices are connected. The communication has do be done on Standard IEEE 802.3 Ethernet Frames without IP stack.

Example for sending data:

int etherType =  0x88A4;  // the EtherType registered by IEEE
byte[] macBroadcast = new byte[] {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
byte[] macSource = new byte[] ... ;  // MAC Address of my network interface card
byte[] buffer = ... // the data to send

device.write(macSource, macBroadcast, etherType, buffer);

I tried JNetPcap, which uses the pcap native library. The given API was fine, but there were multithreading issues on heavy load, which forced me to give up.

netty.io was also a candidate. I am not sure, but a TCP/IP stack is mandatory. Am I right?

Are there other ideas to communicate with low level Ethernet Frames? I would prefer a pure java library like netty.io, if one exists.

Of course JNA/JNI is an option, too. But I don't want to write C code.

Other alternatives?


Source: (StackOverflow)

How to connect an ethernet device directly to a switch in linux?

We have an embedded board where the ethernet device is directly connected to a switch without a phy in between. To make things more complicated the ethernet device's mdio bus is connected to the switch's mdio for control.

I have managed to use the fixed mdio/phy driver to enable ethernet and that works by matching the switch's default configuration to the fixed phy's.

How do I now connect to the mdio bus to change the switch settings? Since the ethernet device's attached phy is filled by the fixed phy how do I now attach the real mdio bus to the system so I can configure it. There seems to be no direct userspace interface to an mdio bus. Do I create a fake ethernet device whose only purpose is to access the mdio bus or do I somehow attach it to the ethernet device which will then have two mdio busses attached?

PS: It seems like the physical mdio bus driver finds the switch but how do I talk to it?


Source: (StackOverflow)

How does PPP or Ethernet recover from errors?

Looking at the data-link level standards, such as PPP general frame format or Ethernet, it's not clear what happens if the checksum is invalid. How does the protocol know where the next frame begins?

Does it just scan for the next occurrence of "flag" (in the case of PPP)? If so, what happens if the packet payload just so happens to contain "flag" itself? My point is that, whether packet-framing or "length" fields are used, it's not clear how to recover from invalid packets where the "length" field could be corrupt or the "framing" bytes could just so happen to be part of the packet payload.

UPDATE: I found what I was looking for (which isn't strictly what I asked about) by looking up "GFP CRC-based framing". According to Communication networks

The GFP receiver synchronizes to the GFP frame boundary through a three-state process. The receiver is initially in the hunt state where it examines four bytes at a time to see if the CRC computed over the first two bytes equals the contents of the next two bytes. If no match is found the GFP moves forward by one byte as GFP assumes octet synchronous transmission given by the physical layer. When the receiver finds a match it moves to the pre-sync state. While in this intermediate state the receiver uses the tentative PLI (payload length indicator) field to determine the location of the next frame boundary. If a target number N of successful frame detection has been achieved, then the receiver moves into the sync state. The sync state is the normal state where the receiver examines each PLI, validates it using cHEC (core header error checking), extracts the payload, and proceeds to the next frame.

In short, each packet begins with "length" and "CRC(length)". There is no need to escape any characters and the packet length is known ahead of time.

There seems to be two major approaches to packet framing:

  • encoding schemes (bit/byte stuffing, Manchester encoding, 4b5b, 8b10b, etc)
  • unmodified data + checksum (GFP)

The former is safer, the latter is more efficient. Both are prone to errors if the payload just happens to contain a valid packet and line corruption causes the proceeding bytes to contain the "start of frame" byte sequence but that sounds highly improbable. It's difficult to find hard numbers for GFP's robustness, but a lot of modern protocols seem to use it so one can assume that they know what they're doing.


Source: (StackOverflow)

How to send a WOL package(or anything at all) through a nic which has no IP address?

I'm trying to send a WOL package on all interfaces in order to wake up the gateway(which is the DHCP server, so the machine won't have an IP yet).

And it seems that I can only bind sockets to IP and port pairs...

So the question is: How can a create a socket(or something else) that is bound to a NIC that has no IP? (Any languge is ok. c# is prefered)

@ctacke: I know that WOL is done by MAC address... My problem is that windows only sends UDP broadcasts on the NIC what Windows considers to be the primary NIC (which is not even the NIC with the default route on my Vista machine). And I can not seems to find a way to bind a socket to an interface which has no IP address. (like DHCP clients do this)

@Arnout: Why not? The clients know the MAC address of the gateway. I just want a send a WOL packet like a DHCP client does initially...(DHCP discover packets claim to come from 0.0.0.0) I don't mind if I have to construct the whole packet byte by byte...


Source: (StackOverflow)

avrdude: stk500_getsync(): not in sync: resp=0x00 (Tried everything but replacement)

avrdude: stk500_getsync(): not in sync: resp=0x00

enter image description here

I have this problem and nothing I've searched help, I already tried everything. Im using arduino uno with ethernet shield.

I plugged a Led from digital pin to GND directly without any resistor if that was the problem, I do it often so far if that was the cause it just broke down now.

If there are other solution to this please help out, I already did the following:

• Port check

• Board check

• Driver check / re-install

• Cable check / renewed

none of it seems to work. If it is broken would my ethernet shield be harmed and be broken as well? Which should I replace.


Source: (StackOverflow)

StandBy like activity

I would like to create a StandBy activity for my device, and so far I created an activity that when is called will turn off my display.

The code is the following:

public class MainActivity extends Activity {
private SensorManager mSensorManager;
private PowerManager mPowerManager;
private WindowManager mWindowManager;
private WakeLock mWakeLock;
private Button button;
private TextView textView;

/** Called when the activity is first created. */
@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    try {
        // Get an instance of the SensorManager
        mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);

        // Get an instance of the PowerManager
        mPowerManager = (PowerManager) getSystemService(POWER_SERVICE);

        // Get an instance of the WindowManager
        mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
        mWindowManager.getDefaultDisplay();

        setContentView(R.layout.activity_main);
        // textView = (TextView)findViewById(R.id.textView1);
        button = (Button) findViewById(R.id.testText);
        button.setOnClickListener(mButtonStopListener);

        mWakeLock = mPowerManager.newWakeLock(
                PowerManager.PARTIAL_WAKE_LOCK, "Your Tag");
        // mWakeLock.acquire();
        final WindowManager.LayoutParams params = getWindow()
                .getAttributes();
        params.screenBrightness = 0;
        getWindow().setAttributes(params);

    } catch (final Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        Log.e("onCreate", e.getMessage());
    }
} // END onCreate

View.OnClickListener mButtonStopListener = new OnClickListener() {
    @Override
    public void onClick(final View v) {
        try {
            if (mWakeLock.isHeld()) {
                mWakeLock.release();
                System.err.println("mWakeLock.release()  onTouch");
            }
        } catch (final Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            Log.e("onPause", e.getMessage());
        }

    }
};

@Override
protected void onResume() {
    super.onResume();

    try {
        if (mWakeLock.isHeld()) {
            System.err.println("mWakeLock.release() onResume");
            mWakeLock.release();
        } else {
            System.err.println("mWakeLock.acquire() onResume");
            mWakeLock.acquire();

        }
    } catch (final Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        Log.e("onResume", e.getMessage());
    }

}

@Override
protected void onPause() {
    super.onPause();


}

}

As I said this code enable me to turn off the screen, and I'm able to turn on the screen clicking twice the power button (I don't know why I have two click the button twice, but this is a secondary issue).

The main problem is that when the display turn off the action ACTION_SCREEN_OFF is generated, and as a consequence the android EthernetService disable my connection. Anyone know how to keep the connection active?

Thanks;)


Source: (StackOverflow)