Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members

Ethernet Class Reference

#include <ether.h>

Collaboration diagram for Ethernet:

Collaboration graph
[legend]
List of all members.

Static Public Member Functions

void ether_print (const u_char *)
char * etheraddr_string (const u_char *)
u_char * nametoaddr (const char *devname)

Static Private Attributes

char hex [] = "0123456789abcdef"

Member Function Documentation

void Ethernet::ether_print const u_char *   )  [static]
 

Definition at line 54 of file ether.cc.

References etheraddr_string().

00055 {
00056         const struct ether_header *ep;
00057  
00058         ep = (const struct ether_header *)bp;
00059         printf("src: %s\n",
00060              etheraddr_string(ep->ether_shost));
00061         printf("dst: %s\n",
00062              etheraddr_string(ep->ether_dhost));
00063         printf("prot: %hx\n",
00064              ntohs(ep->ether_type));
00065 }

Here is the call graph for this function:

char * Ethernet::etheraddr_string const u_char *   )  [static]
 

Definition at line 68 of file ether.cc.

References hex.

Referenced by PcapLiveNetwork::command(), ether_print(), and ArpAgent::resolve().

00069 {   
00070         unsigned i, j;
00071         register char *cp;
00072         static char buf[sizeof("00:00:00:00:00:00")];
00073     
00074         cp = buf;
00075         if ((j = *ep >> 4) != 0)
00076                 *cp++ = hex[j]; 
00077         *cp++ = hex[*ep++ & 0xf]; 
00078         for (i = 5; (int)--i >= 0;) {
00079                 *cp++ = ':';
00080                 if ((j = *ep >> 4) != 0)
00081                         *cp++ = hex[j]; 
00082                 *cp++ = hex[*ep++ & 0xf]; 
00083         }       
00084         *cp = '\0'; 
00085         return(buf);
00086 }   

u_char * Ethernet::nametoaddr const char *  devname  )  [static]
 

Definition at line 91 of file ether.cc.

00092 {
00093         static struct ifreq ifr;
00094         int s;
00095 
00096         memset(&ifr, 0, sizeof(ifr));
00097         if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
00098                 fprintf(stderr, "Ethernet::nametoaddr-- failed socket\n");
00099                 return NULL;
00100         }
00101         strncpy(ifr.ifr_name, devname, sizeof(ifr.ifr_name));
00102         if (ioctl(s, SIOCGIFADDR, (char *)&ifr) < 0) {
00103                 fprintf(stderr, "Ethernet::nametoaddr-- failed SIOCGIFADDR\n");
00104                 return NULL;
00105         }
00106         return ((u_char*) &ifr.ifr_data);
00107 }


Member Data Documentation

char Ethernet::hex = "0123456789abcdef" [static, private]
 

Definition at line 51 of file ether.cc.

Referenced by etheraddr_string().


The documentation for this class was generated from the following files:
Generated on Tue Apr 20 12:45:59 2004 for NS2.26SourcesOriginal by doxygen 1.3.3