Main Page | Directories | File List | Globals

core.c

Go to the documentation of this file.
00001 /*
00002  * kernel_net/layer_3/core/core.c
00003  *
00004  * Copyright (c) 2003-2005 Lukasz Dembinski <dembol@nasa.com.pl>
00005  * All Rights Reserved
00006  * 
00007  * Date:        2005/06
00008  * Author:      Lukasz Dembinski
00009  * Info:        core.c core file
00010  * Contact:     mailto: <dembol@nasa.com.pl>
00011  *
00012  */
00013 
00014 #include <agnix/agnix.h>
00015 #include <agnix/adi/adi.h>
00016 #include <agnix/init.h>
00017 #include <agnix/net/net.h>
00018 #include <agnix/memory.h>
00019 #include <agnix/strings.h>
00020 #include <agnix/console.h>
00021 #include <agnix/types.h>
00022 
00023 #define MOD_NAME        "NET: "
00024 
00025 int net_addr(char *addr, struct net_addr_s *net_addr)
00026 {
00027     char buf[NET_ADDR_STRING_MAX_LEN];
00028     char *ptr;
00029     int i, j;
00030     int dots;
00031 
00032     j = 0;
00033     dots = 0;
00034     for (i = 0; i < NET_ADDR_STRING_MAX_LEN; i++) {
00035         if (addr[i] == '.' && j > 0) {
00036             buf[i] = 0;
00037             j = 0;
00038             dots++;
00039             if (dots > 3)
00040                 return -1;
00041                 
00042         } else 
00043         if ((addr[i] >= '0') && (addr[i] <= '9') && (j < 3)) {
00044             buf[i] = addr[i];
00045             j++;
00046         } else
00047         if (addr[i] == 0 || addr[i] == '\n')
00048             break;
00049         else
00050             return -1;
00051     }
00052     
00053     if ((dots != 3) || (addr[i - 1] == '.'))
00054         return -1;
00055         
00056     buf[i] = 0;
00057     net_addr->address[0] = (u8)atoi(buf);
00058     ptr = buf + strlen(buf) + 1;
00059     net_addr->address[1] = (u8)atoi(ptr);
00060     ptr += strlen(ptr) + 1;
00061     net_addr->address[2] = (u8)atoi(ptr);
00062     ptr += strlen(ptr) + 1;
00063     net_addr->address[3] = (u8)atoi(ptr);
00064 
00065     return 0;
00066 }
00067 
00068 int net_layer_3_init(void)
00069 {
00070     printk(MOD_NAME "\tLayer 3: core");
00071 
00072     net_layer_3_ip_init();
00073     
00074     printk("\n");
00075 
00076     return 0;
00077 }
Dokumentacje wygenerowano programem Doxygen 1.4.2 dla projektu Agnix