📄 nextport.c
字号:
/***********************************************************************//* *//* Module: tcp_ip/tcp/tcpsock.c *//* Release: 2001.3 *//* Version: 99.0 *//* Purpose: TCP API Support *//* *//*---------------------------------------------------------------------*//* *//* Copyright 1999, Blunk Microsystems *//* ALL RIGHTS RESERVED *//* *//* Licensees have the non-exclusive right to use, modify, or extract *//* this computer program for software development at a single site. *//* This program may be resold or disseminated in executable format *//* only. The source code may not be redistributed or resold. *//* *//***********************************************************************/#include "../tcp_ipp.h"/***********************************************************************//* Global Function Definitions *//***********************************************************************//***********************************************************************//* TcpNextPort: Return next unused TCP local port number *//* *//***********************************************************************/ui16 TcpNextPort(void){ static ui16 port_num; CircLink *link; ui16 netorder; int i; for (i = 0; i < (HI_PORT_NUM - LO_PORT_NUM); ++i) { /*-----------------------------------------------------------------*/ /* Increment the port number, wrapping around as necessary. */ /*-----------------------------------------------------------------*/ ++port_num; if ((port_num < LO_PORT_NUM) || (port_num > HI_PORT_NUM)) port_num = LO_PORT_NUM; /*-----------------------------------------------------------------*/ /* Check every open TCP socket. */ /*-----------------------------------------------------------------*/ netorder = htons(port_num); for (link = TcpLruList.next_bck;; link = link->next_bck) { /*---------------------------------------------------------------*/ /* Port number unique if end of socket list reached. */ /*---------------------------------------------------------------*/ if (link == &TcpLruList) return netorder; /*---------------------------------------------------------------*/ /* Break to try another number if already in use. */ /*---------------------------------------------------------------*/ if (((SOCKET)link)->local.sin_port == netorder) break; } } return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -