2

So far my understanding of achieveing this is using NET_FUNCS:

typedef struct net_funcs{
STATUS (*start) (void*);               /* driver’s start func */
STATUS (*stop) (void*);                /* driver’s stop func */
STATUS (*unload) (void*);              /* driver’s unload func */
int (*ioctl) (void*, int, caddr_t);    /* driver’s ioctl func */
STATUS (*send) (void* , M_BLK_ID);     /* driver’s send func */
STATUS (*mCastAddrAdd) (void*, char*); /* driver’s mcast add func */
STATUS (*mCastAddrDel) (void*, char*); /* driver’s mcast delete func */
STATUS (*mCastAddrGet) (void*, MULTI_TABLE*);/* driver’s mcast get func */
STATUS (*pollSend) (void*, M_BLK_ID);  /* driver’s poll send func */
STATUS (*pollRcv) (void*, M_BLK_ID);   /* driver’s poll receive func */
STATUS (*addressForm) (M_BLK_ID, M_BLK_ID, M_BLK_ID);/* driver’s addr formation func */
STATUS (*packetDataGet) (M_BLK_ID, M_BLK_ID);/* driver’s pkt data get func */
STATUS (*addrGet) (M_BLK_ID, M_BLK_ID, M_BLK_ID, M_BLK_ID, M_BLK_ID);/* driver’s pkt addr get func */} NET_FUNCS;

I have a pointer to a M_BLK struct called pMblk(of type M_BLK_ID = * M_BLK) that I believe holds the information to our Ethernet package(header and data), this is where my understanding starts to fade, I'm not 100% sure this is where our whole package is stored or is just part of a whole(cluster). Specifically using adderGet (using a same function but for our case its endEtherPacketAddrGet), The way I understand this function is that if you put your structure with all the information from the packet into the param 1, and followed with other pointers I created param 2: pSrc, param 3: pDest, param 4: pESrc, param 5: pEDst, I seems like it would make sense that the information for the senders IP address would be somewhere withing the pSrc Struct. This is where I've really struggled in printing out the information with in this object as a log message, For now I just want to print out the sender IP address, later more info but I havent been able to print anything coherent. I've tried:

printf("pSrc->mData: %d", pSrc->mData); // not actually using print just for the sake of the example
printf("pSrc->mData: %c", pSrc->mData); // not actually using print just for the sake of the example

yielded blank or not useful data, also:

printf("pSrc->mData: %d", &pSrc->mData); // not actually using print just for the sake of the example
printf("pSrc->mData: %c", &pSrc->mData); // not actually using print just for the sake of the example

These are not the only things I've tried I just want to give a feeling of where I am and what I am trying to do, that being said is there a fundamental understanding that I'm off on here because I feel as though I'm close? Is there a different approach to reaching this information, or is it stored in a different member of the structure? Any guidance on this would be greatly appreciated!

Trist
  • 41
  • 4

3 Answers3

2

These c code pieces would be helpful.

unsigned char    *mData = (unsigned char *)(pMblk->mBlkHdr.mData);
IP_HEADER_T      *pkt_iph = (IP_HEADER_T *)&mData[14]; /* ethernet packet only */
unsigned int      src_ip_addr = pkt_iph->src;
unsigned int      dst_ip_addr = pkt_iph->dst;
JaeMann Yeh
  • 358
  • 2
  • 9
  • 1
    Thanks for the response! however i don't think its quite what I'm looking for unfortunately, for the sake of what i am doing I don't have access to the net.h where the IP_HEADER_T struct lives, I tried moving over the functionality and doesn't seems to work, with that being said do you have other suggestions for pulling out this information from the ethernet packet, thanks again! – Trist Jul 06 '20 at 20:08
2

solved this using pointer arithmetic:

        srcAddr[0] = *(mBlk->m_data + 6);
        srcAddr[1] = *(mBlk->m_data + 7);
        srcAddr[2] = *(mBlk->m_data + 8);
        srcAddr[3] = *(mBlk->m_data + 9);
        srcAddr[4] = *(mBlk->m_data + 10);
        srcAddr[5] = *(mBlk->m_data + 11);
        printf("Source Address: %02x:%02x:%02x:%02x:%02x:%02x\n", srcAddr[0], srcAddr[1], srcAddr[2], srcAddr[3], srcAddr[4], srcAddr[5]);

m_data is a typedef for mBlk->mBlkHdr.mData

Trist
  • 41
  • 4
2

Little late to the party, but to specifically arrange the data pointers to the exact location within the message block:

unsigned char *destAddr;
unsigned char *srcAddr;
LL_HDR_INFO *hdrInfo;

/*Pass in the packet and the LL_HDR_INFO object*/
endEtherPacketDataGet(mBlk, hdrInfo);

/*Copy from source to destination the number of bytes passed in*/
bcopy(mBlk->mBlkHdr.mData + hdrInfo->destAddrOffset, destAddr, hdrInfo->destSize);

/*Print the 6 byte physical address*/
printf("Destination Address: %02x:%02x:%02x:%02x:%02x:%02x\n", destAddr[0], destAddr[1], destAddr[2], destAddr[3], destAddr[4], destAddr[5]);

bcopy(mBlk->mBlkHdr.mData + hdrInfo->srcAddrOffset, srcAddr, hdrInfo->srcSize);
printf("Source Address: %02x:%02x:%02x:%02x:%02x:%02x\n", srcAddr[0], srcAddr[1], srcAddr[2], srcAddr[3], srcAddr[4], srcAddr[5]);

This will allow you to debug the information within the received packet.

Noble
  • 104
  • 10