greenplumn test_ifaddrs 源码

  • 2022-08-18
  • 浏览 (757)

greenplumn test_ifaddrs 代码

文件路径:/src/tools/ifaddrs/test_ifaddrs.c

/*
 * src/tools/ifaddrs/test_ifaddrs.c
 *
 *
 *	test_ifaddrs.c
 *		test pg_foreach_ifaddr()
 */

#include "postgres.h"

#include <netinet/in.h>
#include <arpa/inet.h>

#include "libpq/ifaddr.h"


static void
print_addr(struct sockaddr *addr)
{
	char		buffer[256];
	int			ret,
				len;

	switch (addr->sa_family)
	{
		case AF_INET:
			len = sizeof(struct sockaddr_in);
			break;
#ifdef HAVE_IPV6
		case AF_INET6:
			len = sizeof(struct sockaddr_in6);
			break;
#endif
		default:
			len = sizeof(struct sockaddr_storage);
			break;
	}

	ret = getnameinfo(addr, len, buffer, sizeof(buffer), NULL, 0,
					  NI_NUMERICHOST);
	if (ret != 0)
		printf("[unknown: family %d]", addr->sa_family);
	else
		printf("%s", buffer);
}

static void
callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)
{
	printf("addr: ");
	print_addr(addr);
	printf("  mask: ");
	print_addr(mask);
	printf("\n");
}

int
main(int argc, char *argv[])
{
#ifdef WIN32
	WSADATA		wsaData;

	if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0)
	{
		fprintf(stderr, "WSAStartup failed\n");
		return 1;
	}
#endif

	if (pg_foreach_ifaddr(callback, NULL) < 0)
		fprintf(stderr, "pg_foreach_ifaddr failed: %s\n", strerror(errno));
	return 0;
}

相关信息

greenplumn 源码目录

相关文章

greenplumn adminpack 源码

greenplumn verify_nbtree 源码

greenplumn auth_delay 源码

greenplumn auto_explain 源码

greenplumn blcost 源码

greenplumn blinsert 源码

greenplumn bloom 源码

greenplumn blscan 源码

greenplumn blutils 源码

greenplumn blvacuum 源码

0  赞