• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ print_sockaddr函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中print_sockaddr函数的典型用法代码示例。如果您正苦于以下问题:C++ print_sockaddr函数的具体用法?C++ print_sockaddr怎么用?C++ print_sockaddr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了print_sockaddr函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: query_one

static bool query_one(const char *lookup, unsigned int lookup_type)
{
	int j, count;
	uint8_t flags;
	struct sockaddr_storage *ip_list=NULL;
	NTSTATUS status = NT_STATUS_NOT_FOUND;

	if (got_bcast) {
		char addr[INET6_ADDRSTRLEN];
		print_sockaddr(addr, sizeof(addr), &bcast_addr);
		d_printf("querying %s on %s\n", lookup, addr);
		status = name_query(lookup,lookup_type,use_bcast,
				    use_bcast?true:recursion_desired,
				    &bcast_addr, talloc_tos(),
				    &ip_list, &count, &flags);
	} else {
		status = name_resolve_bcast(
			lookup, lookup_type,
			talloc_tos(), &ip_list, &count);
	}

	if (!NT_STATUS_IS_OK(status)) {
		return false;
	}

	if (give_flags) {
		d_printf("Flags: %s\n", query_flags(flags));
	}

	for (j=0;j<count;j++) {
		char addr[INET6_ADDRSTRLEN];
		if (translate_addresses) {
			char h_name[MAX_DNS_NAME_LENGTH];
			h_name[0] = '\0';
			if (sys_getnameinfo((const struct sockaddr *)&ip_list[j],
					sizeof(struct sockaddr_storage),
					h_name, sizeof(h_name),
					NULL, 0,
					NI_NAMEREQD)) {
				continue;
			}
			d_printf("%s, ", h_name);
		}
		print_sockaddr(addr, sizeof(addr), &ip_list[j]);
		d_printf("%s %s<%02x>\n", addr,lookup, lookup_type);
		/* We can only do find_status if the ip address returned
		   was valid - ie. name_query returned true.
		 */
		if (find_status) {
			if (!do_node_status(lookup, lookup_type, &ip_list[j])) {
				status = NT_STATUS_UNSUCCESSFUL;
			}
		}
	}

	TALLOC_FREE(ip_list);

	return NT_STATUS_IS_OK(status);
}
开发者ID:javierag,项目名称:samba,代码行数:59,代码来源:nmblookup.c


示例2: print_cmsg_ip_recverr

static void
print_cmsg_ip_recverr(struct tcb *tcp, const void *cmsg_data,
		      const size_t data_len)
{
	const struct {
		uint32_t ee_errno;
		uint8_t  ee_origin;
		uint8_t  ee_type;
		uint8_t  ee_code;
		uint8_t  ee_pad;
		uint32_t ee_info;
		uint32_t ee_data;
		struct sockaddr_in offender;
	} *err = cmsg_data;

	if (sizeof(*err) > data_len)
		return;

	tprintf(", {ee_errno=%u, ee_origin=%u, ee_type=%u, ee_code=%u"
		", ee_info=%u, ee_data=%u, offender=",
		err->ee_errno, err->ee_origin, err->ee_type,
		err->ee_code, err->ee_info, err->ee_data);
	print_sockaddr(tcp, (const void *) &err->offender,
		sizeof(err->offender));
	tprints("}");
}
开发者ID:3125788,项目名称:platform_external_strace,代码行数:26,代码来源:net.c


示例3: net_lookup_pdc

static int net_lookup_pdc(struct net_context *c, int argc, const char **argv)
{
	struct sockaddr_storage ss;
	char *pdc_str = NULL;
	const char *domain;
	char addr[INET6_ADDRSTRLEN];

	if (lp_security() == SEC_ADS) {
		domain = lp_realm();
	} else {
		domain = c->opt_target_workgroup;
	}

	if (argc > 0)
		domain=argv[0];

	/* first get PDC */
	if (!get_pdc_ip(domain, &ss))
		return -1;

	print_sockaddr(addr, sizeof(addr), &ss);
	if (asprintf(&pdc_str, "%s", addr) == -1) {
		return -1;
	}
	d_printf("%s\n", pdc_str);
	SAFE_FREE(pdc_str);
	return 0;
}
开发者ID:DavidMulder,项目名称:samba,代码行数:28,代码来源:net_lookup.c


示例4: net_lookup_host

/* lookup a hostname giving an IP */
static int net_lookup_host(struct net_context *c, int argc, const char **argv)
{
	struct sockaddr_storage ss;
	int name_type = 0x20;
	char addr[INET6_ADDRSTRLEN];
	const char *name = argv[0];
	char *p;

	if (argc == 0)
		return net_lookup_usage(c, argc, argv);

	p = strchr_m(name,'#');
	if (p) {
		*p = '\0';
		sscanf(++p,"%x",&name_type);
	}

	if (!resolve_name(name, &ss, name_type, false)) {
		/* we deliberately use DEBUG() here to send it to stderr
		   so scripts aren't mucked up */
		DEBUG(0,("Didn't find %s#%02x\n", name, name_type));
		return -1;
	}

	print_sockaddr(addr, sizeof(addr), &ss);
	d_printf("%s\n", addr);
	return 0;
}
开发者ID:DavidMulder,项目名称:samba,代码行数:29,代码来源:net_lookup.c


示例5: main

int main(int argc, char const* argv[])
{
	if (argc<2) perr("usage: chat_server [port]");

	struct addrinfo *plist = 
		get_addrinfo_list("localhost",argv[1],SOCK_STREAM);
	int fd = try_bind(plist);
	if (fd==-1) perr("Cannot bind socket to port");

	freeaddrinfo(plist);

	if (listen(fd,BACKLOG)==-1) {
		perror("listen");
		exit(1);
	}

	struct sigaction sa;
	sa.sa_handler = sigchld_handler; 
	sa.sa_flags   = SA_RESTART;
	sigemptyset(&sa.sa_mask);
	if (sigaction(SIGCHLD,&sa,NULL)==-1) {
		perror("sigaction");
		exit(1);
	}

	while(1) {
		struct sockaddr_storage addr;
		socklen_t addr_len;
		int client_fd = accept(fd,(struct sockaddr *)&addr,&addr_len);
		if (fd==-1) {
			perror("accept");
			exit(1);
		}
		fprintf(stderr,"Got connection from\n");
		print_sockaddr((struct sockaddr*)&addr);
		fprintf(stderr,"\n");

		int pid=fork();
		if (pid<0) {
			perror("fork");
			exit(1);
		} else if (pid==0) { 
			// child
			close(fd);
			const char welcome[] = "Welcome!";
			//write(client_fd,welcome,sizeof(welcome));
			struct client_mgr_t args={client_fd,60.0};
			server_recvmgr(&args);

			close(client_fd);
			exit(0);
		}

		// parent
		close(client_fd);
	}

	return 0;
}
开发者ID:qzmfranklin,项目名称:test,代码行数:59,代码来源:chat_server.cpp


示例6: net_lookup_dc

static int net_lookup_dc(struct net_context *c, int argc, const char **argv)
{
	struct ip_service *ip_list;
	struct sockaddr_storage ss;
	char *pdc_str = NULL;
	const char *domain = NULL;
	char *sitename = NULL;
	int count, i;
	char addr[INET6_ADDRSTRLEN];
	bool sec_ads = (lp_security() == SEC_ADS);

	if (sec_ads) {
		domain = lp_realm();
	} else {
		domain = c->opt_target_workgroup;
	}

	if (argc > 0)
		domain=argv[0];

	/* first get PDC */
	if (!get_pdc_ip(domain, &ss))
		return -1;

	print_sockaddr(addr, sizeof(addr), &ss);
	if (asprintf(&pdc_str, "%s", addr) == -1) {
		return -1;
	}
	d_printf("%s\n", pdc_str);

	sitename = sitename_fetch(talloc_tos(), domain);
	if (!NT_STATUS_IS_OK(get_sorted_dc_list(domain, sitename,
					&ip_list, &count, sec_ads))) {
		SAFE_FREE(pdc_str);
		TALLOC_FREE(sitename);
		return 0;
	}
	TALLOC_FREE(sitename);
	for (i=0;i<count;i++) {
		print_sockaddr(addr, sizeof(addr), &ip_list[i].ss);
		if (!strequal(pdc_str, addr))
			d_printf("%s\n", addr);
	}
	SAFE_FREE(pdc_str);
	return 0;
}
开发者ID:DavidMulder,项目名称:samba,代码行数:46,代码来源:net_lookup.c


示例7: add_interface

static void add_interface(const struct iface_struct *ifs)
{
	char addr[INET6_ADDRSTRLEN];
	struct interface *iface;

	if (iface_find((const struct sockaddr *)&ifs->ip, False)) {
		DEBUG(3,("add_interface: not adding duplicate interface %s\n",
			print_sockaddr(addr, sizeof(addr), &ifs->ip) ));
		return;
	}

	if (!(ifs->flags & (IFF_BROADCAST|IFF_LOOPBACK))) {
		DEBUG(3,("not adding non-broadcast interface %s\n",
					ifs->name ));
		return;
	}

	iface = SMB_MALLOC_P(struct interface);
	if (!iface) {
		return;
	}

	ZERO_STRUCTPN(iface);

	iface->name = SMB_STRDUP(ifs->name);
	if (!iface->name) {
		SAFE_FREE(iface);
		return;
	}
	iface->flags = ifs->flags;
	iface->ip = ifs->ip;
	iface->netmask = ifs->netmask;
	iface->bcast = ifs->bcast;

	DLIST_ADD(local_interfaces, iface);

	DEBUG(2,("added interface %s ip=%s ",
		iface->name,
		print_sockaddr(addr, sizeof(addr), &iface->ip) ));
	DEBUG(2,("bcast=%s ",
		print_sockaddr(addr, sizeof(addr),
			&iface->bcast) ));
	DEBUG(2,("netmask=%s\n",
		print_sockaddr(addr, sizeof(addr),
			&iface->netmask) ));
}
开发者ID:abartlet,项目名称:samba-old,代码行数:46,代码来源:interface.c


示例8: accept

int accept(int sockfd, struct sockaddr *addr, socklen_t addrlen) {
	if (!orig_accept)
		orig_accept = (orig_accept_t)dlsym(RTLD_NEXT, "accept");
			
	int rv = orig_accept(sockfd, addr,  addrlen);
	print_sockaddr(sockfd, "accept", addr, rv);

	return rv;
}
开发者ID:irregulator,项目名称:firejail,代码行数:9,代码来源:libtrace.c


示例9: bind

int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen) {
	if (!orig_bind)
		orig_bind = (orig_bind_t)dlsym(RTLD_NEXT, "bind");
			
	int rv = orig_bind(sockfd, addr, addrlen);
	print_sockaddr(sockfd, "bind", addr, rv);

	return rv;
}
开发者ID:irregulator,项目名称:firejail,代码行数:9,代码来源:libtrace.c


示例10: connect

int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen) {
	if (!orig_connect)
		orig_connect = (orig_connect_t)dlsym(RTLD_NEXT, "connect");
			
 	int rv = orig_connect(sockfd, addr, addrlen);
	print_sockaddr(sockfd, "connect", addr, rv);

	return rv;
}
开发者ID:irregulator,项目名称:firejail,代码行数:9,代码来源:libtrace.c


示例11: winbindd_wins_byname

void winbindd_wins_byname(struct winbindd_cli_state *state)
{
	struct sockaddr_storage *ip_list = NULL;
	int i, count, maxlen, size;
	fstring response;
	char addr[INET6_ADDRSTRLEN];

	/* Ensure null termination */
	state->request->data.winsreq[sizeof(state->request->data.winsreq)-1]='\0';

	DEBUG(3, ("[%5lu]: wins_byname %s\n", (unsigned long)state->pid,
		state->request->data.winsreq));

	*response = '\0';
	maxlen = sizeof(response) - 1;

	ip_list = lookup_byname_backend(
		state->mem_ctx, state->request->data.winsreq, &count);
	if (ip_list != NULL){
		for (i = count; i ; i--) {
			print_sockaddr(addr, sizeof(addr), &ip_list[i-1]);
			size = strlen(addr);
			if (size > maxlen) {
				TALLOC_FREE(ip_list);
				request_error(state);
				return;
			}
			if (i != 0) {
				/* Clear out the newline character */
				/* But only if there is something in there,
				otherwise we clobber something in the stack */
				if (strlen(response)) {
					response[strlen(response)-1] = ' ';
				}
			}
			fstrcat(response,addr);
			fstrcat(response,"\t");
		}
		size = strlen(state->request->data.winsreq) + strlen(response);
		if (size > maxlen) {
		    TALLOC_FREE(ip_list);
		    request_error(state);
		    return;
		}
		fstrcat(response,state->request->data.winsreq);
		fstrcat(response,"\n");
		TALLOC_FREE(ip_list);
	} else {
		request_error(state);
		return;
	}

	fstrcpy(state->response->data.winsresp,response);

	request_ok(state);
}
开发者ID:Alexandr-Galko,项目名称:samba,代码行数:56,代码来源:winbindd_wins.c


示例12: print_cmsg_ip_origdstaddr

static void
print_cmsg_ip_origdstaddr(struct tcb *tcp, const void *cmsg_data,
			  const size_t data_len)
{
	if (sizeof(struct sockaddr_in) > data_len)
		return;

	tprints(", ");
	print_sockaddr(tcp, cmsg_data, data_len);
}
开发者ID:3125788,项目名称:platform_external_strace,代码行数:10,代码来源:net.c


示例13: print_cmsg_ip_origdstaddr

static void
print_cmsg_ip_origdstaddr(struct tcb *tcp, const void *cmsg_data,
			  const size_t data_len)
{
	const int addr_len =
		data_len > sizeof(struct sockaddr_storage)
		? sizeof(struct sockaddr_storage) : data_len;

	print_sockaddr(tcp, cmsg_data, addr_len);
}
开发者ID:yunchih,项目名称:strace,代码行数:10,代码来源:msghdr.c


示例14: process_dc_dns

static NTSTATUS process_dc_dns(TALLOC_CTX *mem_ctx,
			       const char *domain_name,
			       uint32_t flags,
			       struct ip_service_name *dclist,
			       int num_dcs,
			       struct netr_DsRGetDCNameInfo **info)
{
	int i = 0;
	bool valid_dc = false;
	struct netlogon_samlogon_response *r = NULL;
	uint32_t nt_version = NETLOGON_NT_VERSION_5 |
			      NETLOGON_NT_VERSION_5EX;
	uint32_t ret_flags = 0;
	NTSTATUS status;

	nt_version |= map_ds_flags_to_nt_version(flags);

	for (i=0; i<num_dcs; i++) {

		char addr[INET6_ADDRSTRLEN];
		print_sockaddr(addr, sizeof(addr), &dclist[i].ss);

		DEBUG(10,("LDAP ping to %s (%s)\n", dclist[i].hostname, addr));

		if (ads_cldap_netlogon(mem_ctx, &dclist[i].ss,
					domain_name,
					nt_version,
					&r))
		{
			nt_version = r->ntver;
			ret_flags = get_cldap_reply_server_flags(r, nt_version);

			if (check_cldap_reply_required_flags(ret_flags, flags)) {
				valid_dc = true;
				break;
			}
		}

		continue;
	}

	if (!valid_dc) {
		return NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND;
	}

	status = make_dc_info_from_cldap_reply(mem_ctx, flags, &dclist[i].ss,
					       &r->data.nt5_ex, info);
	if (NT_STATUS_IS_OK(status)) {
		return store_cldap_reply(mem_ctx, flags, &dclist[i].ss,
					 nt_version, &r->data.nt5_ex);
	}

	return status;
}
开发者ID:Distrotech,项目名称:samba,代码行数:54,代码来源:dsgetdcname.c


示例15: net_lookup_kdc

static int net_lookup_kdc(struct net_context *c, int argc, const char **argv)
{
#ifdef HAVE_KRB5
	krb5_error_code rc;
	krb5_context ctx;
	struct ip_service *kdcs;
	const char *realm;
	int num_kdcs = 0;
	int i;
	NTSTATUS status;

	initialize_krb5_error_table();
	rc = krb5_init_context(&ctx);
	if (rc) {
		DEBUG(1,("krb5_init_context failed (%s)\n",
			 error_message(rc)));
		return -1;
	}

	if (argc > 0) {
		realm = argv[0];
	} else if (lp_realm() && *lp_realm()) {
		realm = lp_realm();
	} else {
		char **realms;

		rc = krb5_get_host_realm(ctx, NULL, &realms);
		if (rc) {
			DEBUG(1,("krb5_gethost_realm failed (%s)\n",
				 error_message(rc)));
			return -1;
		}
		realm = (const char *) *realms;
	}

	status = get_kdc_list(realm, NULL, &kdcs, &num_kdcs);
	if (!NT_STATUS_IS_OK(status)) {
		DEBUG(1,("get_kdc_list failed (%s)\n", nt_errstr(status)));
		return -1;
	}

	for (i = 0; i < num_kdcs; i++) {
		char addr[INET6_ADDRSTRLEN];

		print_sockaddr(addr, sizeof(addr), &kdcs[i].ss);

		d_printf("%s:%u\n", addr, kdcs[i].port);
	}

	return 0;
#endif
	DEBUG(1, ("No kerberos support\n"));
	return -1;
}
开发者ID:DavidMulder,项目名称:samba,代码行数:54,代码来源:net_lookup.c


示例16: rpc_dc_name

static bool rpc_dc_name(const char *domain,
			fstring srv_name,
			struct sockaddr_storage *ss_out)
{
	struct ip_service *ip_list = NULL;
	struct sockaddr_storage dc_ss;
	int count, i;
	NTSTATUS result;
	char addr[INET6_ADDRSTRLEN];

	/* get a list of all domain controllers */

	if (!NT_STATUS_IS_OK(get_sorted_dc_list(domain, NULL, &ip_list, &count,
						False))) {
		DEBUG(3, ("Could not look up dc's for domain %s\n", domain));
		return False;
	}

	/* Remove the entry we've already failed with (should be the PDC). */

	for (i = 0; i < count; i++) {
		if (is_zero_addr((struct sockaddr *)&ip_list[i].ss))
			continue;

		if (name_status_find(domain, 0x1c, 0x20, &ip_list[i].ss, srv_name)) {
			result = check_negative_conn_cache( domain, srv_name );
			if ( NT_STATUS_IS_OK(result) ) {
				dc_ss = ip_list[i].ss;
				goto done;
			}
		}
	}

	SAFE_FREE(ip_list);

	/* No-one to talk to )-: */
	return False;		/* Boo-hoo */

 done:
	/* We have the netbios name and IP address of a domain controller.
	   Ideally we should sent a SAMLOGON request to determine whether
	   the DC is alive and kicking.  If we can catch a dead DC before
	   performing a cli_connect() we can avoid a 30-second timeout. */

	print_sockaddr(addr, sizeof(addr), &dc_ss);
	DEBUG(3, ("rpc_dc_name: Returning DC %s (%s) for domain %s\n", srv_name,
		  addr, domain));

	*ss_out = dc_ss;
	SAFE_FREE(ip_list);

	return True;
}
开发者ID:0x24bin,项目名称:winexe-1,代码行数:53,代码来源:namequery_dc.c


示例17: print_cmsg_ip_recverr

static void
print_cmsg_ip_recverr(struct tcb *tcp, const void *cmsg_data,
		      const size_t data_len)
{
	const struct sock_ee *const err = cmsg_data;

	tprintf("{ee_errno=%u, ee_origin=%u, ee_type=%u, ee_code=%u"
		", ee_info=%u, ee_data=%u, offender=",
		err->ee_errno, err->ee_origin, err->ee_type,
		err->ee_code, err->ee_info, err->ee_data);
	print_sockaddr(tcp, &err->offender, sizeof(err->offender));
	tprints("}");
}
开发者ID:yunchih,项目名称:strace,代码行数:13,代码来源:msghdr.c


示例18: get_workgroups

/****************************************************************************
  display tree of smb workgroups, servers and shares
****************************************************************************/
static bool get_workgroups(struct user_auth_info *user_info)
{
        struct cli_state *cli;
        struct sockaddr_storage server_ss;
	TALLOC_CTX *ctx = talloc_tos();
	char *master_workgroup = NULL;

        /* Try to connect to a #1d name of our current workgroup.  If that
           doesn't work broadcast for a master browser and then jump off
           that workgroup. */

	master_workgroup = talloc_strdup(ctx, lp_workgroup());
	if (!master_workgroup) {
		return false;
	}

	if (!use_bcast && !find_master_ip(lp_workgroup(), &server_ss)) {
		DEBUG(4,("Unable to find master browser for workgroup %s, "
			 "falling back to broadcast\n",
			 master_workgroup));
		use_bcast = true;
	}

	if (!use_bcast) {
		char addr[INET6_ADDRSTRLEN];

		print_sockaddr(addr, sizeof(addr), &server_ss);

		cli = get_ipc_connect(addr, &server_ss, user_info);
		if (cli == NULL) {
			return false;
		}
	} else {
		cli = get_ipc_connect_master_ip_bcast(talloc_tos(),
						      user_info,
						      &master_workgroup);
		if (cli == NULL) {
			DEBUG(4, ("Unable to find master browser by "
				  "broadcast\n"));
			return false;
		}
	}

        if (!cli_NetServerEnum(cli, master_workgroup,
                               SV_TYPE_DOMAIN_ENUM, add_name, &workgroups))
                return False;

        return True;
}
开发者ID:andrew-aladev,项目名称:samba-talloc-debug,代码行数:52,代码来源:smbtree.c


示例19: net_lookup_master

static int net_lookup_master(struct net_context *c, int argc, const char **argv)
{
	struct sockaddr_storage master_ss;
	const char *domain = c->opt_target_workgroup;
	char addr[INET6_ADDRSTRLEN];

	if (argc > 0)
		domain=argv[0];

	if (!find_master_ip(domain, &master_ss))
		return -1;
	print_sockaddr(addr, sizeof(addr), &master_ss);
	d_printf("%s\n", addr);
	return 0;
}
开发者ID:DavidMulder,项目名称:samba,代码行数:15,代码来源:net_lookup.c


示例20: print_group_req

static void
print_group_req(struct tcb *tcp, long addr, int len)
{
	struct group_req greq;

	if (len != sizeof(greq) ||
	    umove(tcp, addr, &greq) < 0) {
		printaddr(addr);
		return;
	}

	tprintf("{gr_interface=%u, gr_group=", greq.gr_interface);
	print_sockaddr(tcp, &greq.gr_group, sizeof(greq.gr_group));
	tprintf("}");

}
开发者ID:yunchih,项目名称:strace,代码行数:16,代码来源:net.c



注:本文中的print_sockaddr函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ print_spaces_filtered函数代码示例发布时间:2022-05-30
下一篇:
C++ print_revision函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap