⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tcpopen.c

📁 用于嵌入式系统的TCP/IP协议栈及若干服务
💻 C
字号:
/**            Copyright (c) 1998-2001 by NETsilicon Inc.**  This software is copyrighted by and is the sole property of*  NETsilicon.  All rights, title, ownership, or other interests*  in the software remain the property of NETsilicon.  This*  software may only be used in accordance with the corresponding*  license agreement.  Any unauthorized use, duplication, transmission,*  distribution, or disclosure of this software is expressly forbidden.**  This Copyright notice may not be removed or modified without prior*  written consent of NETsilicon.**  NETsilicon, reserves the right to modify this software*  without notice.**  NETsilicon*  411 Waverley Oaks Road                  USA 781.647.1234*  Suite 227                               http://www.netsilicon.com*  Waltham, MA 02452                       AmericaSales@netsilicon.com***************************************************************************  $Name: Fusion 6.52 Fusion 6.51 $*  $Date: 2001/09/20 10:21:44 $*  $Source: M:/psisrc/stack/tcp/rcs/tcpopen.c $*  $Revision: 1.21 $***************************************************************************  File Description:  Opens an Internet TCP socket for I/O***************************************************************************/#include "std.h"#include "socket.h"#include "ip.h"#include "fnsproto.h"#include "in.h"#include "fpublic.h"#include "debug.h"#ifdef DNS_RESOLVER#include "nameser.h"#include "netdb.h"#include "resolv.h"#endif#ifdef  DEBUGimport  boolean tcp_debug;#endifexport  int fns_tcp_open (int pref_sock, u16 dport,                          char *daddr, int * errp){	int sd;    struct in_sockaddr inaddr;#ifdef DNS_RESOLVER	struct hostent *ph;#else    struct in_addr dinaddr;#endif	if ((sd = fns_socket(AF_INET, SOCK_STREAM, IP_TCP, errp)) == ERR)		return ERR;	if (pref_sock != 0)		if (fns_ip_bind(sd, pref_sock, errp) == ERR)			goto out;	if (daddr != (char *)0) {#ifndef DNS_RESOLVER        if( ! fns_inet_aton(daddr, &dinaddr)) {            (void)so_uclose((u16)sd);		    debug1(tcp_debug, "fns_tcp_open: illegal destination address %s\n", daddr );		    return ERR;	    }        inaddr.sin_addr.s_addr = dinaddr.s_addr;#else	    /* With DNS we can get a name */	    ph = gethostbyname( daddr );	    if( !ph ) {            (void)so_uclose((u16)sd);            debug1(tcp_debug,"fns_tcp_open: unknown host %s\n", daddr );		    return ERR;	    }        inaddr.sin_addr.s_addr = NetToHost32((u8 *)ph->h_addr_list[0]);#endif        inaddr.sin_port = dport;        inaddr.sin_family = AF_INET;		if(fns_connect(sd, (saddr *)&inaddr, sizeof(inaddr), errp) != 0) 		{out:      so_uclose((u16)sd);		  return ERR;		}	}	return sd;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -