Changeset 752709f


Ignore:
Timestamp:
03/17/06 10:58:25 (15 years ago)
Author:
Perry Lorier <perry@…>
Branches:
4.0.1-hotfixes, cachetimestamps, develop, dpdk-ndag, etsilive, getfragoff, help, libtrace4, master, ndag_format, pfring, rc-4.0.1, rc-4.0.2, rc-4.0.3, rc-4.0.4, ringdecrementfix, ringperformance, ringtimestampfixes
Children:
85a0d42
Parents:
548da5c
Message:

Add libtrace_ether_{n,a}to{a,n}
Fix bug with get seconds

Location:
lib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • lib/libtrace.h

    r7ac9705 r752709f  
    932932/*@}*/
    933933
     934/** @name Portability
     935 * This section has functions that causes annoyances to portability for one
     936 * reason or another.
     937 * @{
     938 */
     939
     940/** Convert an ethernet address to a string
     941 * @param addr  Ethernet address in network byte order
     942 * @param buf   Buffer to store the ascii representation, or NULL
     943 * @return buf, or if buf is NULL then a statically allocated buffer.
     944 *
     945 * This function is similar to the GNU ether_ntoa_r function, with a few
     946 * minor differences.  if NULL is passed as buf, then the function will
     947 * use an internal static buffer, if NULL isn't passed then the function
     948 * will use that buffer instead.
     949 *
     950 * @note the type of addr isn't struct ether_addr as it is with ether_ntoa_r,
     951 * however it is bit compatible so that a cast will work.
     952 */
     953char *trace_ether_ntoa(const uint8_t *addr, char *buf);
     954
     955/** Convert a string to an ethernet address
     956 * @param buf   Ethernet address in hex format delimited with :'s.
     957 * @param addr  buffer to store the binary representation, or NULL
     958 * @return addr, or if addr is NULL, then a statically allocated buffer.
     959 *
     960 * This function is similar to the GNU ether_aton_r function, with a few
     961 * minor differences.  if NULL is passed as addr, then the function will
     962 * use an internal static buffer, if NULL isn't passed then the function will
     963 * use that buffer instead.
     964 *
     965 * @note the type of addr isn't struct ether_addr as it is with ether_aton_r,
     966 * however it is bit compatible so that a cast will work.
     967 */
     968uint8_t *trace_ether_aton(const char *buf, uint8_t *addr);
     969
     970/*@}*/
     971
     972
    934973/** Which port is the server port */
    935974typedef enum {
  • lib/trace.c

    rb51edf5 r752709f  
    613613        }
    614614        free((*packet));
    615         packet = NULL;
     615        *packet = NULL;
    616616}       
    617617
     
    11801180size_t trace_get_capture_length(const libtrace_packet_t *packet) {
    11811181
    1182         /* Packets can be have a size of zero */
    1183         assert(packet->size>=0 && packet->size<65536);
     1182        assert(packet->size<65536);
    11841183
    11851184        if (packet->trace->format->get_capture_length) {
     
    17941793}
    17951794
     1795char *trace_ether_ntoa(const uint8_t *addr, char *buf)
     1796{
     1797        char *buf2 = buf;
     1798        static char staticbuf[17]={0,};
     1799        if (!buf2)
     1800                buf2=staticbuf;
     1801        sprintf(buf2,"%02x:%02x:%02x:%02x:%02x:%02x",
     1802                        addr[0],addr[1],addr[2],
     1803                        addr[3],addr[4],addr[5]);
     1804        return buf2;
     1805}
     1806
     1807uint8_t *trace_ether_aton(const char *buf, uint8_t *addr)
     1808{
     1809        uint8_t *buf2 = addr;
     1810        unsigned int tmp[6];
     1811        static uint8_t staticaddr[6];
     1812        if (!buf2)
     1813                buf2=staticaddr;
     1814        sscanf(buf,"%x:%x:%x:%x:%x:%x",
     1815                        &tmp[0],&tmp[1],&tmp[2],
     1816                        &tmp[3],&tmp[4],&tmp[5]);
     1817        buf2[0]=tmp[0]; buf2[1]=tmp[1]; buf2[2]=tmp[2];
     1818        buf2[3]=tmp[3]; buf2[4]=tmp[4]; buf2[5]=tmp[5];
     1819        return buf2;
     1820}
Note: See TracChangeset for help on using the changeset viewer.