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

ip_addr.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2001-2003 Swedish Institute of Computer Science.
00003  * All rights reserved. 
00004  * 
00005  * Redistribution and use in source and binary forms, with or without modification, 
00006  * are permitted provided that the following conditions are met:
00007  *
00008  * 1. Redistributions of source code must retain the above copyright notice,
00009  *    this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright notice,
00011  *    this list of conditions and the following disclaimer in the documentation
00012  *    and/or other materials provided with the distribution.
00013  * 3. The name of the author may not be used to endorse or promote products
00014  *    derived from this software without specific prior written permission. 
00015  *
00016  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 
00017  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
00018  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 
00019  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
00020  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 
00021  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
00022  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
00023  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 
00024  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 
00025  * OF SUCH DAMAGE.
00026  *
00027  * This file is part of the lwIP TCP/IP stack.
00028  * 
00029  * Author: Adam Dunkels <adam@sics.se>
00030  *
00031  */
00032 
00033 #include "lwip/ip_addr.h"
00034 #include "lwip/inet.h"
00035 #include <string.h>
00036 
00037 
00038 #define htons HTONS
00039 #define htonl HTONL
00040 
00041 struct ip_addr ip_addr_any = { 0x00000000UL };
00042 struct ip_addr ip_addr_broadcast = { 0xffffffffUL };
00043 
00044 /*-----------------------------------------------------------------------------------*/
00045 int get_int_from_char(char c){
00046 
00047   /* 0-9 */
00048   if((c >= 48) && (c <= 57)) return (c-48);
00049   return -1;
00050 }
00051 
00052 /*-----------------------------------------------------------------------------------*/
00053 void string2ip_addr(struct ip_addr *ip, char *name, int size){
00054   int i, index=0, sum[4]={0,0,0,0}, ciphers[3]={0,0,0},cont=0;
00055 
00056   if(name != NULL){
00057     for(i=0; i<3; i++){
00058       do{
00059         ciphers[cont]=get_int_from_char(name[index]);
00060         index++;
00061         cont++;
00062       }while(name[index] != 0x2e); //0x2e is the hex ascii code for '.'
00063       if(cont==3)
00064         sum[i] = ciphers[0]*100 + ciphers[1]*10 + ciphers[2];
00065       else if(cont==2)
00066         sum[i] = ciphers[0]*10 + ciphers[1];
00067       else
00068         sum[i] = ciphers[0];
00069       index++;
00070       ciphers[0] = 0; ciphers[1]= 0; ciphers[2] = 0; cont = 0;
00071     }
00072 
00073     while(name[index]!='\0'){
00074       ciphers[cont]= get_int_from_char(name[index]);
00075       index++;
00076       cont++;
00077     }
00078     if(cont==3)
00079       sum[3] = ciphers[0]*100 + ciphers[1]*10 + ciphers[2];
00080     else if(cont==2)
00081       sum[3] = ciphers[0]*10 + ciphers[1];
00082     else
00083       sum[3] = ciphers[0];
00084 
00085     IP4_ADDR(ip, sum[0],sum[1],sum[2],sum[3]);
00086   }
00087 }
00088 /*-----------------------------------------------------------------------------------*/

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