Search code examples
network-programmingvxworkssniffing

how to use VxWorks etherOutputHookAdd


I'm stumped trying to get etherOutputHookAdd() to work. Its counterpart, etherInputHookAdd(), seems to work fine. The OS version in question is VxWorks 5.4 .

The hook code looks like so (the code I intend to actually run is more complicated, but this serves for an example.)

int anCounter;
STATUS etherHook(struct ifnet *pif, char *buf, int size)
{
    anCounter += 1;
    return FALSE;
}

I can hook up etherInputHookAdd from the vxworks shell like so

etherInputHookAdd etherHook,"fei",0

This returns 0 (STATUS OK), after which examination of the 'anCounter' variable will indicate activity as expected. However, no such luck with the output direction. I've tried both of these command lines

etherOutputHookAdd etherHook,"fei",0
etherOutputHookAdd etherHook

Both of these return OK, but the hook routine doesn't seem to be getting called at all. My best hypotheses are (1) I'm missing an initialization step, or calling it wrong, (2) the etherOutputHookAdd implementation is just a stub, (3) you just can't call it from the shell, or (4) maybe my nic driver implementation is buggy.

Any ideas that solve the central problem - how do I see what's being sent off my board - are welcome.


Solution

  • To those few who might stumble this way .. It was the horrible 'hypothesis 4'!

    It turns out that in order for etherOutputHookAdd() to work correctly, it is incumbent on the NIC device driver writer to include a call to the function pointed to by etherOutputHookRtn. All etherOutputHookAdd() does is add your proffered packet handler to a list, so that when a NIC driver calls etherOutputHookRtn, you get a copy of what's being transmitted. Sadly, there are many drivers where for whatever reason, this was simply not done.

    So in cases such as this one, there are only two courses of action.

    • find a patch for your driver, or patch it yourself
    • change tactics entirely, e.g., try using etherInputHookAdd() on the other side.