]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/Common/ethernet/FreeRTOS-uIP/uiplib.c
Add FreeRTOS-Plus directory.
[freertos] / FreeRTOS / Demo / Common / ethernet / FreeRTOS-uIP / uiplib.c
1 /*\r
2  * Copyright (c) 2004, Adam Dunkels and the Swedish Institute of\r
3  * Computer Science.\r
4  * All rights reserved.\r
5  *\r
6  * Redistribution and use in source and binary forms, with or without\r
7  * modification, are permitted provided that the following conditions\r
8  * are met:\r
9  * 1. Redistributions of source code must retain the above copyright\r
10  *    notice, this list of conditions and the following disclaimer.\r
11  * 2. Redistributions in binary form must reproduce the above copyright\r
12  *    notice, this list of conditions and the following disclaimer in the\r
13  *    documentation and/or other materials provided with the distribution.\r
14  * 3. The name of the author may not be used to endorse or promote\r
15  *    products derived from this software without specific prior\r
16  *    written permission.\r
17  *\r
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS\r
19  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\r
20  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
21  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY\r
22  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE\r
24  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\r
26  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\r
27  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\r
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
29  *\r
30  * This file is part of the uIP TCP/IP stack\r
31  *\r
32  * $Id: uiplib.c,v 1.2 2006/06/12 08:00:31 adam Exp $\r
33  *\r
34  */\r
35 #include "uip.h"\r
36 #include "uiplib.h"\r
37 \r
38 /*-----------------------------------------------------------------------------------*/\r
39 unsigned char uiplib_ipaddrconv( char *addrstr, unsigned char *ipaddr )\r
40 {\r
41         unsigned char   tmp;\r
42         char                    c;\r
43         unsigned char   i, j;\r
44 \r
45         tmp = 0;\r
46 \r
47         for( i = 0; i < 4; ++i )\r
48         {\r
49                 j = 0;\r
50                 do\r
51                 {\r
52                         c = *addrstr;\r
53                         ++j;\r
54                         if( j > 4 )\r
55                         {\r
56                                 return 0;\r
57                         }\r
58 \r
59                         if( c == '.' || c == 0 )\r
60                         {\r
61                                 *ipaddr = tmp;\r
62                                 ++ipaddr;\r
63                                 tmp = 0;\r
64                         }\r
65                         else if( c >= '0' && c <= '9' )\r
66                         {\r
67                                 tmp = ( tmp * 10 ) + ( c - '0' );\r
68                         }\r
69                         else\r
70                         {\r
71                                 return 0;\r
72                         }\r
73 \r
74                         ++addrstr;\r
75                 } while( c != '.' && c != 0 );\r
76         }\r
77 \r
78         return 1;\r
79 }\r
80 \r
81 /*-----------------------------------------------------------------------------------*/\r