OSDN Git Service

fix DHCP client problem
authornyatla <nyatla@47198e57-cb75-475f-84c4-a814cd6f29e0>
Sat, 10 Aug 2013 02:30:29 +0000 (02:30 +0000)
committernyatla <nyatla@47198e57-cb75-475f-84c4-a814cd6f29e0>
Sat, 10 Aug 2013 02:30:29 +0000 (02:30 +0000)
git-svn-id: http://svn.osdn.jp/svnroot/mimic/trunk@306 47198e57-cb75-475f-84c4-a814cd6f29e0

lib/src/NyLPC_cMiMicEnv.h
lib/src/net/dhcp/NyLPC_cDhcpClient.c
lib/src/net/dhcp/NyLPC_cDhcpClient.h

index 80b2ea0..3b65df6 100644 (file)
@@ -13,7 +13,7 @@ extern "C" {
 #endif /* __cplusplus */\r
 \r
 \r
-#define NyLPC_cMiMicEnv_VERSION "MiMic/1.4.51"\r
+#define NyLPC_cMiMicEnv_VERSION "MiMic/1.4.52"\r
 \r
 \r
 #ifdef __cplusplus\r
index ee20d4d..caa9a2a 100644 (file)
@@ -93,15 +93,17 @@ static NyLPC_TBool getUInt8Option(const NyLPC_TUInt8* i_buf,NyLPC_TUInt16 len,Ny
        }\r
        return NyLPC_TBool_FALSE;\r
 }\r
-static NyLPC_TBool NyLPC_TDhcpHeader_parseDHCPOFFER(const NyLPC_TUInt8* i_buf,NyLPC_TUInt16 i_len,NyLPC_TUInt32 i_xid,NyLPC_TcIPv4Config_t* result)\r
+static NyLPC_TBool NyLPC_TDhcpHeader_parseDHCPOFFER(const NyLPC_TUInt8* i_buf,NyLPC_TUInt16 i_len,NyLPC_TUInt32 i_xid,NyLPC_TcDhcpClient_t* i_inst)\r
 {\r
        struct NyLPC_TDhcpHeader* p=(struct NyLPC_TDhcpHeader*)i_buf;\r
        //XIDのチェック\r
        if(p->xid!=NyLPC_HTONL(i_xid)){\r
                return NyLPC_TBool_FALSE;\r
        }\r
-       //サーバ情報をIPへ保存\r
-       if(!getUInt32Option(i_buf,i_len,DHCP_OPT_ID_SERVER_ID,&result->ip_addr.v)){\r
+       //OFFERのclient IPアドレスをresultへ保存情報の保存\r
+       i_inst->_result->ip_addr.v=p->yiaddr;\r
+       //SERVER IDを保存\r
+       if(!getUInt32Option(i_buf,i_len,DHCP_OPT_ID_SERVER_ID,&i_inst->_offerserver.v)){\r
                return NyLPC_TBool_FALSE;\r
        }\r
        return NyLPC_TBool_TRUE;\r
@@ -133,19 +135,20 @@ static void NyLPC_TDhcpHeader_setDHCPDISCOVER(char* i_buf,NyLPC_TUInt32 i_xid,co
        p->hlen=6;\r
        p->xid=NyLPC_HTONL(i_xid);\r
        p->chaddr.emac=*emac;\r
+       p->flags=NyLPC_HTONS(0x8000);\r
        memcpy(i_buf+sizeof(struct NyLPC_TDhcpHeader),\r
                "\x63\x82\x53\x63"              //4\r
                "\x35\x01\x01"                  //3 MESSAGE TYPE\r
                "\x37\x03\x01\x03\x06"  //5 REQUEST LIST(1,3,6)\r
-               "\x3d\x07\x00\x00\x00\x00\x00\x00\x10" //9 CLIENT INDIFIRE\r
+               "\x3d\x07\x01\x00\x00\x00\x00\x00\x00" //9 CLIENT INDIFIRE\r
                "\xff",4+3+5+9+1);\r
        //emacの上書き\r
-       memcpy((i_buf+sizeof(struct NyLPC_TDhcpHeader)+4+3+5+2),emac->addr,6);\r
+       memcpy((i_buf+sizeof(struct NyLPC_TDhcpHeader)+4+3+5+3),emac->addr,6);\r
        //送信するパケットの長さ\r
        *o_len=sizeof(struct NyLPC_TDhcpHeader)+4+3+5+9+1;\r
        return;\r
 }\r
-static void NyLPC_TDhcpHeader_setDHCPREQUEST(char* i_buf,NyLPC_TUInt32 i_xid,const struct NyLPC_TIPv4Addr* i_sid,const struct NyLPC_TEthAddr* emac,NyLPC_TUInt16* o_len)\r
+static void NyLPC_TDhcpHeader_setDHCPREQUEST(char* i_buf,NyLPC_TUInt32 i_xid,const struct NyLPC_TIPv4Addr* i_sid,const struct NyLPC_TIPv4Addr* i_reqid,const struct NyLPC_TEthAddr* emac,NyLPC_TUInt16* o_len)\r
 {\r
        struct NyLPC_TDhcpHeader* p=(struct NyLPC_TDhcpHeader*)i_buf;\r
        memset(i_buf,0,sizeof(struct NyLPC_TDhcpHeader));\r
@@ -154,19 +157,23 @@ static void NyLPC_TDhcpHeader_setDHCPREQUEST(char* i_buf,NyLPC_TUInt32 i_xid,con
        p->hlen=6;\r
        p->xid=NyLPC_HTONL(i_xid);\r
        p->chaddr.emac=*emac;\r
+       p->flags=NyLPC_HTONS(0x8000);\r
        memcpy(i_buf+sizeof(struct NyLPC_TDhcpHeader),\r
                "\x63\x82\x53\x63"              //4\r
                "\x35\x01\x03"                  //3 MESSAGE TYPE\r
                "\x37\x03\x01\x03\x06"  //5 REQUEST LIST(1,3,6)\r
-               "\x3d\x07\x00\x00\x00\x00\x00\x00\x10" //9 CLIENT INDIFIRE\r
+               "\x3d\x07\x01\x00\x00\x00\x00\x00\x00" //9 CLIENT INDIFIRE\r
                "\x36\x04\x00\x00\x00\x00" // 6 SERVER ID\r
-               "\xff",4+3+5+9+6+1);\r
+               "\x32\x04\x00\x00\x00\x00" // 6 Reqested IP\r
+               "\xff",4+3+5+9+6+6+1);\r
        //emacの上書き\r
-       memcpy((i_buf+sizeof(struct NyLPC_TDhcpHeader)+4+3+5+2),emac->addr,6);\r
+       memcpy((i_buf+sizeof(struct NyLPC_TDhcpHeader)+4+3+5+3),emac->addr,6);\r
        //sidの上書き\r
        memcpy((i_buf+sizeof(struct NyLPC_TDhcpHeader)+4+3+5+9+2),i_sid,4);\r
+       //reqidの上書き\r
+       memcpy((i_buf+sizeof(struct NyLPC_TDhcpHeader)+4+3+5+9+6+2),i_reqid,4);\r
        //送信するパケットの長さ\r
-       *o_len=sizeof(struct NyLPC_TDhcpHeader)+4+3+5+9+6+1;\r
+       *o_len=sizeof(struct NyLPC_TDhcpHeader)+4+3+5+9+6+6+1;\r
        return;\r
 }\r
 \r
@@ -244,7 +251,7 @@ static NyLPC_TBool NyLPC_cDhcpClient_dhcpRequest(NyLPC_TcDhcpClient_t* i_sock,Ny
        if(buf==NULL || s<hint){\r
                return NyLPC_TBool_FALSE;\r
        }\r
-       NyLPC_TDhcpHeader_setDHCPREQUEST(buf,i_sock->txid,&(i_sock->_result->ip_addr),&i_sock->_result->eth_mac,&s);\r
+       NyLPC_TDhcpHeader_setDHCPREQUEST(buf,i_sock->txid,&(i_sock->_offerserver),&(i_sock->_result->ip_addr),&i_sock->_result->eth_mac,&s);\r
        i_sock->_status=TcDhcpSock_ST_WAIT_ACK;\r
        if(!NyLPC_cUdpSocket_psend(&i_sock->super,&NyLPC_TIPv4Addr_BROADCAST,67,buf,s)){\r
                NyLPC_cUdpSocket_releaseSendBuf(&i_sock->super,buf);\r
@@ -333,7 +340,7 @@ static NyLPC_TBool onPacket(NyLPC_TcUdpSocket_t* i_inst,const void* i_buf,const
                if(mt!=DHCP_OPT_ID_MESSAGETYPE_OFFER){\r
                        return NyLPC_TBool_FALSE;\r
                }\r
-               if(!NyLPC_TDhcpHeader_parseDHCPOFFER(i_buf,i_info->size,inst->txid,inst->_result)){\r
+               if(!NyLPC_TDhcpHeader_parseDHCPOFFER(i_buf,i_info->size,inst->txid,inst)){\r
                        return NyLPC_TBool_FALSE;\r
                }\r
                inst->_status=TcDhcpSock_ST_WAIT_OFFER_OK;\r
index 2d24ad3..1557de7 100644 (file)
@@ -39,6 +39,8 @@ struct NyLPC_TcDhcpClient{
        NyLPC_TcIPv4Config_t* _result;\r
        NyLPC_TUInt32 txid;\r
        volatile NyLPC_TUInt16 _status;\r
+       //offer情報\r
+       struct NyLPC_TIPv4Addr _offerserver;\r
 };\r
 \r
 \r