"Fossies" - the Fresh Open Source Software Archive

Member "tcpflow-1.6.1/src/wifipcap/util.cpp" (19 Feb 2021, 1975 Bytes) of package /linux/misc/tcpflow-1.6.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "util.cpp" see the Fossies "Dox" file reference documentation.

    1 #include "os.h"
    2 #include <stdarg.h>
    3 #include <cstdlib>
    4 #include <cstdio>
    5 #include <iostream>
    6 #ifndef _WIN32
    7 #include <sys/socket.h>
    8 #include <netinet/in.h>
    9 #include <arpa/inet.h>
   10 #else
   11 #define snprintf sprintf_s
   12 #endif
   13 #include "util.h"
   14 #include "ethertype.h"
   15 #include "wifipcap.h"
   16 
   17 //std::ostream& operator<<(std::ostream& out, const WifipcapCallbacks::MAC& mac) {
   18 //    const char *fmt = WifipcapCallbacks::MAC::print_fmt == WifipcapCallbacks::MAC::PRINT_FMT_COLON ? 
   19 //  "%02x:%02x:%02x:%02x:%02x:%02x" :
   20 //  "%02x%02x%02x%02x%02x%02x";
   21 //    char buf[24];
   22 //    sprintf(buf, fmt, 
   23 //      (int)((mac.val>>40)&0xff),
   24 //      (int)((mac.val>>32)&0xff),
   25 //      (int)((mac.val>>24)&0xff),
   26 //      (int)((mac.val>>16)&0xff),
   27 //      (int)((mac.val>>8)&0xff),
   28 //      (int)((mac.val)&0xff)
   29 //      );
   30 //    out << buf;
   31 //    return out;
   32 //}
   33 //
   34 
   35 //std::ostream& operator<<(std::ostream& out, const struct in_addr& ip) {
   36 //    out << inet_ntoa(ip);
   37 //    return out;
   38 //}
   39 
   40 #if 0
   41 char *va(const char *format, ...)
   42 {
   43     va_list     argptr;
   44     static int index = 0;
   45     static char buf[8][512];
   46     
   47     char *b = *(buf + index);
   48 
   49     va_start (argptr, format);
   50     vsprintf (b, format,argptr);
   51     va_end (argptr);
   52 
   53     index = (index + 1) % 8;
   54 
   55     return b;   
   56 }
   57 
   58 /*
   59  * Convert a token value to a string; use "fmt" if not found.
   60  */
   61 const char *
   62 tok2strbuf(register const struct tok *lp, register const char *fmt,
   63        register int v, char *buf, size_t bufsize)
   64 {
   65     if (lp != NULL) {
   66         while (lp->s != NULL) {
   67             if (lp->v == v)
   68                 return (lp->s);
   69             ++lp;
   70         }
   71     }
   72     if (fmt == NULL)
   73         fmt = "#%d";
   74 
   75     (void)snprintf(buf, bufsize, fmt, v);
   76     return (const char *)buf;
   77 }
   78 
   79 /*
   80  * Convert a token value to a string; use "fmt" if not found.
   81  */
   82 const char *
   83 tok2str(register const struct tok *lp, register const char *fmt,
   84     register int v)
   85 {
   86     static char buf[4][128];
   87     static int idx = 0;
   88     char *ret;
   89 
   90     ret = buf[idx];
   91     idx = (idx+1) & 3;
   92     return tok2strbuf(lp, fmt, v, ret, sizeof(buf[0]));
   93 }
   94 #endif