TCP API 函数

TCP API 包包含以下主要 TCP API 函数:

  • tcp_app_register()
  • tcp_app_handle_destroy()
  • tcp_api_next_avail_port_get()
  • tcp_connection_with_source_open()
  • tcp_connection_open_with_options()
  • tcp_connection_open_with_options_core()
  • tcp_appl_name_from_rem_port_get()
  • tcp_data_send_with_options()
  • tcp_data_send()
  • tcp_receive_command_send()
  • tcp_intf_hndl_copy()
  • tcp_connection_close()
  • tcp_connection_abort()
  • tcp_conn_routing_instance_set()
  • tcp_api_fatal_error()
  • tcp_connection_local_addr_get()

下面各节对每个 TCP API 函数进行说明。

tcp_app_register()

ApiT_Tcp_App_Handle tcp_app_register (Objid app_module_id)
  • Abstract(摘要):向 API 包注册应用层,以便管理单个连接
  • Argument(参数):包含应用进程的模块的对象 ID
  • Return Value(返回值):包含后续所有 API 调用所需连接信息的句柄

tcp_app_handle_destroy()

void tcp_app_handle_destroy (ApiT_Tcp_App_Handle* tcp_hndl_ptr)
  • Abstract(摘要):注销应用层与 API 包的注册
  • Argument(参数):调用 tcp_app_register() 返回的句柄
  • Return Value(返回值):无

tcp_api_next_avail_port_get()

int tcp_api_next_avail_port_get (ApiT_Tcp_App_Handle tcp_intf_hndl)
  • Abstract(摘要):返回 TCP 接口上可供调用应用程序使用的下一个可用端口
  • Argument(参数):调用 tcp_app_register() 返回的句柄
  • Return Value(返回值):下一个可用端口号

tcp_connection_with_source_open()

int tcp_connection_with_source_open (ApiT_Tcp_App_Handle*, IpT_Address rem_addr,TcpT_Port rem_port, IpT_Address local_addr, TcpT_Port loc_port, int command, int ip_qos)
  • Abstract(摘要):在本主机与远程主机之间打开一个 TCP 连接
  • Arguments(参数):
    • 指向调用 tcp_app_register() 返回的句柄的指针
    • 远程主机的 IP 地址(当命令为 TCPC_COMMAND_OPEN_PASSIVE 时可能被忽略)
    • 远程主机上的端口
    • 本主机的 IP 地址
    • 本主机上的端口
    • 命令为 TCPC_COMMAND_OPEN_PASSIVE 或 TCPC_COMMAND_OPEN_ACTIVE,取决于所需的连接类型
    • QoS 为 0–7 范围内的值,表示希望在 IP 数据报头部优先级字段中设置的取值
  • Return Value(返回值):TCP 连接的 ID
  • Notes(注记):如果为被动打开,则在收到 SYN 数据包后,将发送一个类型为 TCPC_IND_CONNECT_REQUEST 的中断,并附带 ICI tcp_open_ind
  • Warning(警告):已弃用。仅适用于 IPv4。

tcp_connection_open_with_options()

int tcp_connection_open_with_options (ApiT_Tcp_App_Handle* tcp_hndl_ptr, InetT_Address rem_addr, TcpT_Port rem_port, int command, TcpT_Conn_Open_Options* options)
  • Abstract(摘要):在本主机与远程主机之间打开一个 TCP 连接
  • Arguments(参数):
    • 指向调用 tcp_app_register() 返回的句柄的指针
    • 远程主机的 IP 地址(当命令为 TCPC_COMMAND_OPEN_PASSIVE 时不会被忽略),远程主机上的端口
    • 命令为 TCPC_COMMAND_OPEN_PASSIVE 或 TCPC_COMMAND_OPEN_ACTIVE,取决于所需的连接类型
    • 如 选项结构一节所述的各种选项
  • Return Value(返回值):TCP 连接的 ID
  • Notes(注记):连接建立时发送 TCPC_IND_ESTAB。如果主动打开超时,则发送 TCPC_IND_ABORTED。如果为被动打开,则在收到 SYN 数据包后,将发送一个类型为 TCPC_IND_CONNECT_REQUEST 的中断,并附带 ICI tcp_open_ind 或 tcp_open_ind_inet

tcp_connection_open_with_options_core()

int tcp_connection_open_with_options_core (ApiT_Tcp_App_Handle* tcp_hndl_ptr, InetT_Address rem_addr, TcpT_Port rem_port, int command, TcpT_Conn_Open_Options* options, int routing_instance)
  • Abstract(摘要):在本主机与远程主机之间打开一个 TCP 连接
  • Arguments(参数):
    • 指向调用 tcp_app_register() 返回的句柄的指针
    • 远程主机的 IP 地址(当命令为 TCPC_COMMAND_OPEN_PASSIVE 时不会被忽略),远程主机上的端口
    • 命令为 TCPC_COMMAND_OPEN_PASSIVE 或 TCPC_COMMAND_OPEN_ACTIVE,取决于所需的连接类型
    • 如 选项结构一节所述的各种选项
    • routing_instance 仅由 BGP 模型使用
  • Return Value(返回值):TCP 连接的 ID
  • Notes(注记):连接建立时发送 TCPC_IND_ESTAB。如果主动打开超时,则发送 TCPC_IND_ABORTED。如果为被动打开,则在收到 SYN 数据包后,将发送一个类型为 TCPC_IND_CONNECT_REQUEST 的中断,并附带 ICI tcp_open_ind 或 tcp_open_ind_inet。

tcp_appl_name_from_rem_port_get()

void tcp_appl_name_from_rem_port_get (GnaT_App remote_port, char* appl_name)
  • Abstract(摘要):复制与指定服务器端口相对应的应用名称(“Ftp”、“E-mail”等)
  • Arguments(参数):
    • 指示应用远程端口的枚举值
    • 指向用于存储应用名称的目标缓冲区的指针
    • 注意——该缓冲区必须足够大,能够容纳应用名称字符串
  • Return Value(返回值):无

tcp_data_send_with_options()

void tcp_data_send_with_options (ApiT_Tcp_App_Handle tcp_hndl, Packet* data_pkptr)
  • Abstract(摘要):连接建立后,通过该连接发送数据包
  • Argument(参数):
    • 调用 tcp_app_register() 返回的句柄
    • 指向应用程序希望发送的数据包的指针
    • 数据块的选项,按逻辑顺序排列:
      • TCPC_OPT_NONE——效果与 tcp_data_send () 相同
      • TCPC_OPT_FIN——在数据之后发送 FIN(关闭)
      • TCPC_OPT_URG——发送带有紧急标志的数据
  • Return Value(返回值):无

tcp_data_send()

void tcp_data_send (ApiT_Tcp_App_Handle tcp_hndl, Packet* data_pkptr)
  • Abstract(摘要):连接建立后,通过该连接发送数据包
  • Arguments(参数):
    • 调用 tcp_app_register() 返回的句柄
    • 指向应用程序希望发送的数据包的指针
  • Return Value(返回值):无

tcp_receive_command_send()

void tcp_receive_command_send (ApiT_Tcp_App_Handle tcp_hndl, int receive_count)
  • Abstract(摘要):向 TCP 接口表明应用程序已准备好接收来自远程主机的一个或多个数据包
  • Arguments(参数):
    • 调用 tcp_app_register() 返回的句柄
    • 应用程序愿意接受的额外数据包的最大数量(即除已发出的所有尚未满足的接收请求之和以外的数量)
  • Return Value(返回值):无

tcp_intf_hndl_copy()

ApiT_Tcp_App_Handle tcp_intf_hndl_copy (ApiT_Tcp_App_Handle tcp_hndl)
  • Abstract(摘要):返回作为参数 tcp_hndl 传入的原始数据句柄。这使得调用该函数的应用程序可以将句柄的数据值复制到一个新变量中
  • Arguments(参数):调用 tcp_app_register() 返回的句柄
  • Return Value(返回值):与参数 tcp_hndl 相同的句柄

tcp_connection_close()

void tcp_connection_close (ApiT_Tcp_App_Handle tcp_hndl)
  • Abstract(摘要):在所有数据发送完毕后关闭连接
  • Arguments(参数):调用 tcp_app_register() 返回的句柄
  • Return Value(返回值):无

tcp_connection_abort()

void tcp_connection_abort (ApiT_Tcp_App_Handle tcp_hndl)
  • Abstract(摘要):提前终止连接。这可能因应用层的要求而必要。
  • Argument(参数):调用 tcp_app_register() 返回的句柄
  • Return Value(返回值):无

tcp_conn_routing_instance_set()

void tcp_conn_routing_instance_set (ApiT_Tcp_App_Handle tcp_hndl, int instance)
  • Abstract(摘要):设置 TCP 连接的路由实例
  • Argument(参数):
    • 调用 tcp_app_register() 返回的句柄
    • 整数实例编号
  • Return Value(返回值):无

tcp_api_fatal_error()

void tcp_api_fatal_error (const char* msg_str)
  • Abstract(摘要):将 msg_str* 所引用的错误消息复制到标准输出,并终止仿真
  • Argument(参数):指向包含相应错误消息的字符串缓冲区的指针
  • Return Value(返回值):无

tcp_connection_local_addr_get()

InetT_Address tcp_connection_local_addr_get (ApiT_Tcp_App_Handle* tcp_handle_ptr)
  • Abstract(摘要):确定连接实际使用的 IP 地址
  • Arguments(参数):调用 tcp_app_register() 返回的句柄
  • Return Value(返回值):一个通用 IP 地址(IPv4 或 IPv6)

有关本部分的更多信息,请参见:

本站文档由 北京智网畅联科技有限公司 整理、翻译并提供 · Documentation compiled and provided by Beijing ZNetLink Technology Co., Ltd.

交流群 · QQ Group:OPNET/智网妙算网络仿真交流群(群号 486383494)

原文档 © 2017 Riverbed Technology · 本站为公益翻译,由 AI 辅助完成,请仔细甄别

Original documentation © 2017 Riverbed Technology. Community translation, AI-assisted. Contact: jiazequn@znetlink.com