Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: MbedFileServer_1768MiniDK2 RedWireBridge IssueDebug_gcc MiMicRemoteMCU-for-Mbed ... more
Diff: core/uip/NyLPC_cIPv4.c
- Revision:
- 57:bc4330dfa62f
- Parent:
- 48:00d211aac2ec
- Child:
- 69:8c5f220441f5
--- a/core/uip/NyLPC_cIPv4.c Sat Aug 10 02:52:22 2013 +0000
+++ b/core/uip/NyLPC_cIPv4.c Fri Sep 13 06:38:16 2013 +0000
@@ -170,7 +170,40 @@
}
return NULL;
}
-
+/**
+ * 指定番号のTCPポートが未使用かを返す。
+ * @return
+ * i_lport番のポートが未使用であればTRUE
+ */
+static NyLPC_TBool cSocketTbl_isClosedTcpPort(
+ NyLPC_TcPtrTbl_t* i_inst,
+ NyLPC_TUInt16 i_lport)
+{
+ NyLPC_TcBaseSocket_t** p=(NyLPC_TcBaseSocket_t**)(i_inst->buf);
+ NyLPC_TcTcpSocket_t* tp;
+ int i;
+ //一致するポートを検索
+ for(i=i_inst->size-1;i>=0;i--){
+ if(p[i]==NULL){
+ continue;
+ }
+ if(p[i]->_typeid!=NyLPC_TcBaseSocket_TYPEID_TCP_SOCK){
+ tp=((NyLPC_TcTcpSocket_t*)p[i]);
+ //TCPソケット && !クローズ && ポート一致なら使用中
+ if((tp->tcpstateflags!=UIP_CLOSED) && tp->uip_connr.lport==i_lport){
+ return NyLPC_TBool_FALSE;
+ }
+ }
+ if(p[i]->_typeid!=NyLPC_TcBaseSocket_TYPEID_TCP_LISTENER){
+ //Listenerソケット && ポート一致なら使用中
+ if(((NyLPC_TcTcpListener_t*)p[i])->_port==i_lport){
+ return NyLPC_TBool_FALSE;
+ }
+ }
+ }
+ //未使用
+ return NyLPC_TBool_TRUE;
+}
/**
* テーブルにある有効なソケットのperiodicをすべて呼び出します。
*/
@@ -273,6 +306,7 @@
//instanceの初期化
NyLPC_cMutex_initialize(&(i_inst->_sock_mutex));
NyLPC_cMutex_initialize(&(i_inst->_listener_mutex));
+ i_inst->tcp_port_counter=0;
i_inst->_ref_config=NULL;
return;
}
@@ -399,10 +433,24 @@
return NyLPC_TBool_FALSE;
}
+NyLPC_TUInt16 NyLPC_cIPv4_getNewPortNumber(NyLPC_TcIPv4_t* i_inst)
+{
+ NyLPC_TUInt16 i,n;
+ for(i=0;i<0x0fff;i--){
+ i_inst->tcp_port_counter=(i_inst->tcp_port_counter+1)%0x0fff;
+ n=i_inst->tcp_port_counter+49152;
+ if(cSocketTbl_isClosedTcpPort(&i_inst->_socket_tbl,n))
+ {
+ return n;
+ }
+ }
+ return 0;
+}
+
/**********************************************************************
*
- * public function
+ * packet handler
*
**********************************************************************/
MiMic Webservice library