Changeset 566

Show
Ignore:
Timestamp:
06/19/06 15:11:14 (3 years ago)
Author:
common
Message:

nepenthes
- allow hw address lookup using /proc/net/arp in Socket::getRemoteHWA(string *address)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • nepenthes/trunk/nepenthes-core/include/Socket.hpp

    r341 r566  
    149149        virtual void          setLocalHost(uint32_t i); 
    150150        virtual uint32_t getLocalHost(); 
    151         virtual uint32_t getRemoteHost(); 
     151                virtual uint32_t getRemoteHost(); 
     152                virtual bool getRemoteHWA(string *address); 
    152153        virtual list <DialogueFactory *>   * getFactories(); 
    153154        virtual list <Dialogue *>          * getDialogst(); 
  • nepenthes/trunk/nepenthes-core/src/Socket.cpp

    r341 r566  
    492492        return sDesc; 
    493493} 
     494 
     495bool Socket::getRemoteHWA(string *address) 
     496{ 
     497        if ( !(m_Type & ST_TCP) && !(m_Type & ST_UDP) ) 
     498        { 
     499                return false; 
     500        } 
     501 
     502/* 
     503 * 
     504 * borrowed from arp.c in net-tools  
     505 * 
     506 */ 
     507 
     508#define _PATH_PROCNET_ARP               "/proc/net/arp" 
     509        char ip[100]; 
     510        char hwa[100]; 
     511        char mask[100]; 
     512        char line[200]; 
     513        char dev[100]; 
     514        int type, flags; 
     515        FILE *fp; 
     516 
     517        /* Open the PROCps kernel table. */ 
     518        if ( (fp = fopen(_PATH_PROCNET_ARP, "r")) == NULL ) 
     519        { 
     520                logCrit("Could not open %s\n",_PATH_PROCNET_ARP); 
     521        } 
     522 
     523        /* Bypass header -- read until newline */ 
     524        if ( fgets(line, sizeof(line), fp) != (char *) NULL ) 
     525        { 
     526                strcpy(mask, "-"); 
     527                strcpy(dev, "-"); 
     528                /* Read the ARP cache entries. */ 
     529                for ( ; fgets(line, sizeof(line), fp); ) 
     530                { 
     531                        int num = sscanf(line, "%s 0x%x 0x%x %100s %100s %100s\n", 
     532                                                         ip, &type, &flags, hwa, mask, dev); 
     533                        if ( num < 4 ) 
     534                                break; 
     535 
     536                        if ( inet_addr(ip) == m_RemoteHost ) 
     537                        { 
     538//                              logSpam("ip:%s type:0x%x flags:0x%x hwa:%s mask:%s dev:%s\n",ip, type, flags, hwa, mask, dev); 
     539                                *address = hwa; 
     540                                fclose(fp); 
     541                                return true; 
     542                        } 
     543                } 
     544        } 
     545        return false; 
     546}