VirtualBox

Ignore:
Timestamp:
Dec 11, 2008 7:31:54 AM (16 years ago)
Author:
vboxsync
Message:

slirp: logging enhancements

Location:
trunk/src/VBox/Devices/Network/slirp
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Network/slirp/debug.c

    r15245 r15287  
    1515#endif
    1616
     17#define IP4_ADDR_PRINTF_DECOMP(ip) ((ip) >> 24), ((ip) >> 16) & 0xff, ((ip) >> 8) & 0xff, (ip) & 0xff
     18#define IP4_ADDR_PRINTF_FORMAT "%u.%u.%u.%u"
    1719/*
    1820 * Dump a packet in the same format as tcpdump -x
     
    229231
    230232    ip = ntohl(*(uint32_t*)pvValue);
    231     return RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, "%u.%u.%u.%u",
    232            (ip >> 24), (ip >> 16) & 0xff, (ip >> 8) & 0xff, ip & 0xff);
     233    return RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, IP4_ADDR_PRINTF_FORMAT,
     234           IP4_ADDR_PRINTF_DECOMP(ip));
    233235}
    234236
     
    241243    struct socket *so = (struct socket*)pvValue;
    242244    uint32_t ip;
     245    struct sockaddr addr;
     246    socklen_t socklen = sizeof(struct sockaddr);
     247    int status = 0;
    243248
    244249    AssertReturn(strcmp(pszType, "natsock") == 0, 0);
    245250
     251    status = getsockname(so->s, &addr, &socklen);
     252
     253    Assert(status == 0 && addr.sa_family == AF_INET);
     254
    246255    ip = ntohl(so->so_faddr.s_addr);
    247     return RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, "socket %4d: state=%04x ip=%u.%u.%u.%u",
    248            so->s, so->so_state, (ip >> 24), (ip >> 16) & 0xff, (ip >> 8) & 0xff, ip & 0xff);
     256    return RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, "socket %4d:(proto:%u) "
     257            "state=%04x ip=" IP4_ADDR_PRINTF_FORMAT ":%d name=" IP4_ADDR_PRINTF_FORMAT ":%d",
     258            so->s, so->so_type, so->so_state, IP4_ADDR_PRINTF_DECOMP(ip), so->so_fport,
     259            IP4_ADDR_PRINTF_DECOMP(((struct sockaddr_in *)&addr)->sin_addr.s_addr),
     260            ((struct sockaddr_in *)&addr)->sin_port);
    249261}
    250262
     
    295307#endif
    296308
    297 int 
    298 debug_init() 
     309int
     310debug_init()
    299311{
    300312    int rc = VINF_SUCCESS;
  • trunk/src/VBox/Devices/Network/slirp/slirp.c

    r15286 r15287  
    106106#define CHECK_FD_SET(so, events, set)           \
    107107    (DO_CHECK_FD_SET((so), (events), set))
     108
     109/*
     110 * Loging macros
     111 */
     112#if VBOX_WITH_DEBUG_NAT_SOCKETS
     113# if defined(VBOX_WITH_SIMPLIFIED_SLIRP_SYNC) && defined(RT_OS_WINDOWS)
     114#  define  DO_LOG_NAT_SOCK(so, proto, winevent, r_fdset, w_fdset, x_fdset)              \
     115    do {                                                                                \
     116        LogRel(("  " #proto "%R[natsock] %R[natwinnetevents]\n", (so), (winevent)));    \
     117    } while (0)
     118# else
     119#  define  DO_LOG_NAT_SOCK(so, proto, winevent, r_fdset, w_fdset, x_fdset)                              \
     120    do {                                                                                                \
     121            LogRel(("  " #proto " %R[natsock] %s %s %s\n", (so), FD_ISSET((so)->s, (r_fdset))?"READ":"",\
     122                     FD_ISSET((so)->s, (w_fdset))?"WRITE":"", FD_ISSET((so)->s, (x_fdset))?"OOB":""));  \
     123    } while (0)
     124# endif /* VBOX_WITH_DEBUG_NAT_SOCKETS */
     125#else
     126# define DO_LOG_NAT_SOCK(so, proto, winevent, r_fdset, w_fdset, x_fdset) do {} while (0)
     127#endif /* !VBOX_WITH_DEBUG_NAT_SOCKETS */
     128
     129#define LOG_NAT_SOCK(so, proto, winevent, r_fdset, w_fdset, x_fdset) DO_LOG_NAT_SOCK((so), proto, (winevent), (r_fdset), (w_fdset), (x_fdset))
    108130
    109131static const uint8_t special_ethaddr[6] =
     
    730752
    731753            POLL_TCP_EVENTS(rc, error, so, &NetworkEvents);
    732 #if 0
    733 # if defined(VBOX_WITH_SIMPLIFIED_SLIRP_SYNC) && defined(RT_OS_WINDOWS)
    734             LogRel(("  %R[natsock] %R[natwinnetevents]\n", so, &NetworkEvents));
    735 # else
    736             LogRel(("  %R[natsock] %s %s %s\n", so, FD_ISSET(so->s, readfds)?"READ":"",
    737                      FD_ISSET(so->s, writefds)?"WRITE":"", FD_ISSET(so->s, xfds)?"OOB":""));
    738 # endif
    739 #endif
     754
     755            LOG_NAT_SOCK(so, TCP, &NetworkEvents, readfds, writefds, xfds);
    740756
    741757            /*
     
    906922            POLL_UDP_EVENTS(rc, error, so, &NetworkEvents);
    907923
     924            LOG_NAT_SOCK(so, UDP, &NetworkEvents, readfds, writefds, xfds);
     925
    908926            if (so->s != -1 && CHECK_FD_SET(so, NetworkEvents, readfds))
    909927            {
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette