uIP 1.0 based webserver for LPC1114 + ENC28J60

Dependencies:   mbed TMP102

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers uiplib.c Source File

uiplib.c

00001 /*
00002  * Copyright (c) 2004, Adam Dunkels and the Swedish Institute of
00003  * Computer Science.
00004  * All rights reserved.
00005  *
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions
00008  * are met:
00009  * 1. Redistributions of source code must retain the above copyright
00010  *    notice, this list of conditions and the following disclaimer.
00011  * 2. Redistributions in binary form must reproduce the above copyright
00012  *    notice, this list of conditions and the following disclaimer in the
00013  *    documentation and/or other materials provided with the distribution.
00014  * 3. The name of the author may not be used to endorse or promote
00015  *    products derived from this software without specific prior
00016  *    written permission.
00017  *
00018  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
00019  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00020  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00021  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
00022  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00023  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
00024  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00025  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
00026  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00027  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00028  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029  *
00030  * This file is part of the uIP TCP/IP stack
00031  *
00032  * $Id: uiplib.c,v 1.2 2006/06/12 08:00:31 adam Exp $
00033  *
00034  */
00035 
00036 
00037 #include "uip.h"
00038 #include "uiplib.h"
00039 
00040 
00041 /*-----------------------------------------------------------------------------------*/
00042 unsigned char
00043 uiplib_ipaddrconv(char *addrstr, unsigned char *ipaddr)
00044 {
00045   unsigned char tmp;
00046   char c;
00047   unsigned char i, j;
00048 
00049   tmp = 0;
00050   
00051   for(i = 0; i < 4; ++i) {
00052     j = 0;
00053     do {
00054       c = *addrstr;
00055       ++j;
00056       if(j > 4) {
00057     return 0;
00058       }
00059       if(c == '.' || c == 0) {
00060     *ipaddr = tmp;
00061     ++ipaddr;
00062     tmp = 0;
00063       } else if(c >= '0' && c <= '9') {
00064     tmp = (tmp * 10) + (c - '0');
00065       } else {
00066     return 0;
00067       }
00068       ++addrstr;
00069     } while(c != '.' && c != 0);
00070   }
00071   return 1;
00072 }
00073 
00074 /*-----------------------------------------------------------------------------------*/