~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
cvs/emstar/link/liblink/link_util.c


  1 /*
  2  *
  3  * Copyright (c) 2003 The Regents of the University of California.  All 
  4  * rights reserved.
  5  *
  6  * Redistribution and use in source and binary forms, with or without
  7  * modification, are permitted provided that the following conditions
  8  * are met:
  9  *
 10  * - Redistributions of source code must retain the above copyright
 11  *   notice, this list of conditions and the following disclaimer.
 12  *
 13  * - Neither the name of the University nor the names of its
 14  *   contributors may be used to endorse or promote products derived
 15  *   from this software without specific prior written permission.
 16  *
 17  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS''
 18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 19  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
 20  * PARTICULAR  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
 21  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 22  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 23  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 24  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 25  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 27  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 28  *
 29  */
 30  
 31 
 32 /*
 33  * part of liblink - helper library for dealing with a link_pkt
 34  *
 35  * $Id: link_util.c,v 1.17 2005-09-22 03:10:13 girod Exp $
 36  */
 37 
 38 char link_util_cvsid[] = "$Id: link_util.c,v 1.17 2005-09-22 03:10:13 girod Exp $";
 39 
 40 #include <stdio.h>
 41 #include <stdlib.h>
 42 
 43 #include "libmisc/misc.h"
 44 #include "liblink_i.h"
 45 
 46 
 47 /*
 48  *  various ascii output routines 
 49  */
 50 
 51 int link_type_to_buf(buf_t *buf, link_pkt_t *hdr)
 52 {
 53   switch (hdr->type) {
 54   case PKT_TYPE_TOS: 
 55     bufprintf(buf, "type=TOS[%d,%d] ", hdr->ext_type, hdr->ext_group);   
 56     break;
 57 
 58   case PKT_TYPE_MAC_CTRL: {
 59     char *ext_type = NULL;
 60 
 61     switch (hdr->ext_type) {
 62     case MAC_CTRL_RECEIPT: ext_type = "RECEIPT"; break;
 63     case MAC_CTRL_SYNC:    ext_type = "SYNC"; break;
 64     default: break;
 65     }
 66 
 67     if (ext_type)
 68       bufprintf(buf, "type=MAC[%s] ", ext_type);   
 69     else
 70       bufprintf(buf, "type=MAC[%d] ", hdr->ext_type);   
 71     break;
 72   }
 73 
 74   default:
 75     bufprintf(buf, "type=%s ", pkt_type_names[hdr->type]);
 76   }
 77   return 0;
 78 }
 79 
 80 
 81 int link_hdr_to_buf(buf_t *buf, link_pkt_t *hdr)
 82 {
 83   bufprintf(buf, "src=%s ", print_if_id(hdr->src.id));
 84   bufprintf(buf, "dst=%s ", print_if_id(hdr->dst.id));
 85   if (hdr->prev_hop.id)
 86     bufprintf(buf, "prev=%s ", print_if_id(hdr->prev_hop.id));
 87 
 88   link_type_to_buf(buf, hdr);
 89 
 90   if (hdr->max_hops)
 91     bufprintf(buf, "max_hops=%d ", hdr->max_hops);
 92   if (hdr->seqno)
 93     bufprintf(buf, "seqno=%d ", hdr->seqno);
 94   if (hdr->numTx)
 95     bufprintf(buf, "num_tx=%d ", hdr->numTx);
 96   if (hdr->numRx)
 97     bufprintf(buf, "num_rx=%d ", hdr->numRx);
 98 
 99   return 0;
100 }
101 
102 
103 int link_status_to_buf(buf_t *buf, link_status_t *stat)
104 {
105   /* copy the info to buf in printable format */
106   if (stat->top[0])
107     bufprintf(buf, 
108               "Link: %s\n"
109               "  Root Device: %s\n"
110               "  Stack: %s\n\n",
111               stat->top, stat->root, stat->trace);
112   else
113     bufprintf(buf, 
114               "Root Device: %s\n"
115               "  Stack: %s\n\n",
116               stat->root, stat->trace);
117 
118   bufprintf(buf, 
119             "Interface Addr: %s\n"
120             "MTU: %d\n"
121             "Stats:\n"
122             "  packets_rx: %d\n"
123             "  packets_tx: %d\n"
124             "  bytes_rx: %d\n"
125             "  bytes_tx: %d\n"
126             "  errors_tx: %d\n"
127             "  errors_rx: %d\n"
128             "Active: %d\nPromisc: %d\nPOT: %d\n\n",
129             print_if_id(stat->if_id),
130             stat->MTU,
131             stat->packets_rx,
132             stat->packets_tx,
133             stat->bytes_rx,
134             stat->bytes_tx,
135             stat->errors_tx,
136             stat->errors_rx,
137             stat->active,
138             stat->promisc,
139             stat->POT);
140   return 0;
141 }
142 
143 
144 
145 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.