Main Page | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

inet.h File Reference

#include "lwip/arch.h"
#include "lwip/opt.h"
#include "lwip/pbuf.h"
#include "lwip/ip_addr.h"

Include dependency graph for ipv4/lwip/inet.h:

Go to the source code of this file.

Defines

#define HTONS(n)   (n)
#define htons(n)   HTONS(n)
#define NTOHS   HTONS
#define ntohs   htons
#define HTONL(n)   (n)
#define htonl(n)   HTONL(n)
#define NTOHL   HTONL
#define ntohl   htonl
#define htons   HTONS
#define htonl   HTONL

Functions

u16_t inet_chksum (void *dataptr, u16_t len)
u16_t inet_chksum_pbuf (struct pbuf *p)
u16_t inet_chksum_pseudo (struct pbuf *p, struct ip_addr *src, struct ip_addr *dest, u8_t proto, u16_t proto_len)
u32_t inet_addr (const char *cp)
int inet_aton (const char *cp, struct in_addr *addr)
char * inet_ntoa (struct in_addr in)


Define Documentation

#define htonl   HTONL
 

Definition at line 121 of file ipv4/lwip/inet.h.

#define htonl  )     HTONL(n)
 

Definition at line 121 of file ipv4/lwip/inet.h.

#define HTONL  )     (n)
 

Definition at line 94 of file ipv4/lwip/inet.h.

#define htons   HTONS
 

Definition at line 120 of file ipv4/lwip/inet.h.

#define htons  )     HTONS(n)
 

Definition at line 120 of file ipv4/lwip/inet.h.

#define HTONS  )     (n)
 

Definition at line 73 of file ipv4/lwip/inet.h.

#define ntohl   htonl
 

Definition at line 113 of file ipv4/lwip/inet.h.

Referenced by dhcp_rebind(), dhcp_recv(), dhcp_renew(), dhcp_select(), ip_addr_debug_print(), netif_set_gw(), netif_set_ipaddr(), netif_set_netmask(), and next_lookup().

#define NTOHL   HTONL
 

Definition at line 112 of file ipv4/lwip/inet.h.

#define ntohs   htons
 

Definition at line 89 of file ipv4/lwip/inet.h.

Referenced by ip_frag(), ip_input(), ip_reass(), lwip_bind(), lwip_connect(), lwip_sendto(), and main().

#define NTOHS   HTONS
 

Definition at line 88 of file ipv4/lwip/inet.h.


Function Documentation

u32_t inet_addr const char *  cp  ) 
 

Definition at line 221 of file inet.c.

00222 {
00223     struct in_addr val;
00224 
00225     if (inet_aton(cp, &val)) {
00226         return (val.s_addr);
00227     }
00228     return (INADDR_NONE);
00229 }

int inet_aton const char *  cp,
struct in_addr addr
 

Definition at line 240 of file inet.c.

00241 {
00242     u32_t val;
00243     int base, n;
00244     char c;
00245 //    u_int parts[4];
00246 //    u_int *pp = parts;
00247     u32_t parts[4];
00248     u32_t* pp = parts;
00249 
00250     c = *cp;
00251     for (;;) {
00252         /*
00253          * Collect number up to ``.''.
00254          * Values are specified as for C:
00255          * 0x=hex, 0=octal, isdigit=decimal.
00256          */
00257         if (!isdigit(c))
00258             return (0);
00259         val = 0; base = 10;
00260         if (c == '0') {
00261             c = *++cp;
00262             if (c == 'x' || c == 'X')
00263                 base = 16, c = *++cp;
00264             else
00265                 base = 8;
00266         }
00267         for (;;) {
00268             if (isascii(c) && isdigit(c)) {
00269                 val = (val * base) + (c - '0');
00270                 c = *++cp;
00271             } else if (base == 16 && isascii(c) && isxdigit(c)) {
00272                 val = (val << 4) |
00273                     (c + 10 - (islower(c) ? 'a' : 'A'));
00274                 c = *++cp;
00275             } else
00276             break;
00277         }
00278         if (c == '.') {
00279             /*
00280              * Internet format:
00281              *  a.b.c.d
00282              *  a.b.c   (with c treated as 16 bits)
00283              *  a.b (with b treated as 24 bits)
00284              */
00285             if (pp >= parts + 3)
00286                 return (0);
00287             *pp++ = val;
00288             c = *++cp;
00289         } else
00290             break;
00291     }
00292     /*
00293      * Check for trailing characters.
00294      */
00295     if (c != '\0' && (!isascii(c) || !isspace(c)))
00296         return (0);
00297     /*
00298      * Concoct the address according to
00299      * the number of parts specified.
00300      */
00301     n = pp - parts + 1;
00302     switch (n) {
00303 
00304     case 0:
00305         return (0);     /* initial nondigit */
00306 
00307     case 1:             /* a -- 32 bits */
00308         break;
00309 
00310     case 2:             /* a.b -- 8.24 bits */
00311         if (val > 0xffffff)
00312             return (0);
00313         val |= parts[0] << 24;
00314         break;
00315 
00316     case 3:             /* a.b.c -- 8.8.16 bits */
00317         if (val > 0xffff)
00318             return (0);
00319         val |= (parts[0] << 24) | (parts[1] << 16);
00320         break;
00321 
00322     case 4:             /* a.b.c.d -- 8.8.8.8 bits */
00323         if (val > 0xff)
00324             return (0);
00325         val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8);
00326         break;
00327     }
00328     if (addr)
00329         addr->s_addr = htonl(val);
00330     return (1);
00331 }

u16_t inet_chksum void *  dataptr,
u16_t  len
 

Definition at line 141 of file inet.c.

00142 {
00143   u32_t acc;
00144 
00145   acc = lwip_chksum(dataptr, len);
00146   while(acc >> 16) {
00147     acc = (acc & 0xffff) + (acc >> 16);
00148   }    
00149   return ~(acc & 0xffff);
00150 }

u16_t inet_chksum_pbuf struct pbuf p  ) 
 

Definition at line 153 of file inet.c.

00154 {
00155   u32_t acc;
00156   struct pbuf *q;
00157   u8_t swapped;
00158   
00159   acc = 0;
00160   swapped = 0;
00161   for(q = p; q != NULL; q = q->next) {
00162     acc += lwip_chksum(q->payload, q->len);
00163     while(acc >> 16) {
00164       acc = (acc & 0xffffUL) + (acc >> 16);
00165     }    
00166     if(q->len % 2 != 0) {
00167       swapped = 1 - swapped;
00168       acc = (acc & 0x00ffUL << 8) | (acc & 0xff00UL >> 8);
00169     }
00170   }
00171  
00172   if(swapped) {
00173     acc = ((acc & 0x00ffUL) << 8) | ((acc & 0xff00UL) >> 8);
00174   }
00175   return ~(acc & 0xffffUL);
00176 }

u16_t inet_chksum_pseudo struct pbuf p,
struct ip_addr src,
struct ip_addr dest,
u8_t  proto,
u16_t  proto_len
 

Definition at line 92 of file inet.c.

References ip_addr::addr, DEBUGF, htons, INET_DEBUG, lwip_chksum(), NULL, u16_t, u32_t, and u8_t.

00095 {
00096   u32_t acc;
00097   struct pbuf *q;
00098   u8_t swapped;
00099 
00100   acc = 0;
00101   swapped = 0;
00102   /* iterate through all pbuf in chain */
00103   for(q = p; q != NULL; q = q->next) {    
00104     DEBUGF(INET_DEBUG, ("inet_chksum_pseudo(): checksumming pbuf %p (has next %p) \n", (void *) q, (void *)q->next));
00105     acc += lwip_chksum(q->payload, q->len);
00106     /*DEBUGF(INET_DEBUG, ("inet_chksum_pseudo(): unwrapped lwip_chksum()=%lx \n", acc));*/
00107     while(acc >> 16) {
00108       acc = (acc & 0xffffUL) + (acc >> 16);
00109     }
00110     if(q->len % 2 != 0) {
00111       swapped = 1 - swapped;
00112       acc = ((acc & 0xff) << 8) | ((acc & 0xff00UL) >> 8);
00113     }
00114     /*DEBUGF(INET_DEBUG, ("inet_chksum_pseudo(): wrapped lwip_chksum()=%lx \n", acc));*/
00115   }
00116 
00117   if(swapped) {
00118     acc = ((acc & 0xff) << 8) | ((acc & 0xff00UL) >> 8);
00119   }
00120   acc += (src->addr & 0xffffUL);
00121   acc += ((src->addr >> 16) & 0xffffUL);
00122   acc += (dest->addr & 0xffffUL);
00123   acc += ((dest->addr >> 16) & 0xffffUL);
00124   acc += (u32_t)htons((u16_t)proto);
00125   acc += (u32_t)htons(proto_len);  
00126   
00127   while(acc >> 16) {
00128     acc = (acc & 0xffffUL) + (acc >> 16);
00129   }    
00130   DEBUGF(INET_DEBUG, ("inet_chksum_pseudo(): pbuf chain lwip_chksum()=%lx\n", acc));
00131   return ~(acc & 0xffffUL);
00132 }

Here is the call graph for this function:

char* inet_ntoa struct in_addr  in  ) 
 

Definition at line 342 of file inet.c.

References i2a(), and len.

Referenced by dns_client_callback(), and main().

00342                                    {
00343   static char buf[20];
00344   unsigned int len;
00345   unsigned char *ip=(unsigned char*)&in;
00346   len=i2a(buf,ip[0]); buf[len]='.'; ++len;
00347   len+=i2a(buf+ len,ip[1]); buf[len]='.'; ++len;
00348   len+=i2a(buf+ len,ip[2]); buf[len]='.'; ++len;
00349   len+=i2a(buf+ len,ip[3]); buf[len]=0;
00350   return buf;
00351 }

Here is the call graph for this function:


Generated on Wed Jan 14 12:59:05 2004 for RTL-lwIP-0.4 by doxygen 1.3.4