OSDN Git Service

update libMiMic
[mimic/MiMicSDK.git] / lib / src / netif / NyLPC_cIPv4Config.c
1 /*********************************************************************************
2  * PROJECT: MiMic
3  * --------------------------------------------------------------------------------
4  *
5  * This file is part of MiMic
6  * Copyright (C)2011 Ryo Iizuka
7  *
8  * MiMic is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License as published
10  * by the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20  *
21  * For further information please contact.
22  *  http://nyatla.jp/
23  *  <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
24  *
25  *********************************************************************************/
26
27 #include "NyLPC_cIPv4Config.h"
28
29
30
31 /**
32  * See header file.
33  */
34 void NyLPC_cIPv4Config_initialzeForEthernet(NyLPC_TcIPv4Config_t* i_inst,const struct NyLPC_TEthAddr* i_ether_addr,NyLPC_TUInt16 i_ether_frame_len)
35 {
36     i_inst->ip_addr=i_inst->netmask=i_inst->dr_addr=NyLPC_TIPv4Addr_ZERO;
37     i_inst->eth_mac=*i_ether_addr;
38     //mssの計算
39     i_inst->default_mss=i_ether_frame_len-(UIP_ETHERHEADER_LEN+UIP_TCPH_LEN + UIP_IPH_LEN);
40     return;
41 }
42 void NyLPC_cIPv4Config_initialzeCopy(NyLPC_TcIPv4Config_t* i_inst,const NyLPC_TcIPv4Config_t* i_src)
43 {
44     memcpy(i_inst,i_src,sizeof(NyLPC_TcIPv4Config_t));
45 }
46 /**
47  * See header file.
48  */
49 void NyLPC_cIPv4Config_setDefaultRoute(NyLPC_TcIPv4Config_t* i_inst,const struct NyLPC_TIPv4Addr* i_dr_addr)
50 {
51     i_inst->dr_addr=*i_dr_addr;
52     return;
53 }
54
55 /**
56  * See header file.
57  */
58 void NyLPC_cIPv4Config_setIp(NyLPC_TcIPv4Config_t* i_inst,const struct NyLPC_TIPv4Addr* i_ipaddr,const struct NyLPC_TIPv4Addr* i_netmask)
59 {
60     i_inst->ip_addr=*i_ipaddr;
61     i_inst->netmask=*i_netmask;
62     return;
63 }
64
65 /**
66  * See header file.
67  */
68 NyLPC_TBool NyLPC_cIPv4Config_isLocalIP(const NyLPC_TcIPv4Config_t* i_inst,const struct NyLPC_TIPv4Addr* i_target_ip)
69 {
70     return NyLPC_TIPv4Addr_isEqualWithMask(&(i_inst->ip_addr),i_target_ip,&(i_inst->netmask));
71 }
72