Log In
New Account
  
 
Home My Page Project Tree Code Snippets Project Openings NUTSS
 
 
Summary Tracker Lists CVS Files
 

CVS | Administration


File:  [GForge:cvsroot/nutss] / libnutss / examples / asynchtest.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Tue Apr 24 11:42:45 2007 UTC (9 years, 11 months ago) by saikat
Branches: saikat, MAIN
CVS tags: version_0_1_0, initial, HEAD
Initial upload



#include <stdio.h>
#include <stdlib.h>
#include "nutss.h"

#ifdef WIN32
#define snprintf _snprintf
#endif

#define EXCH 100000
//#define TEST_ONE_PROCESS

//int _tmain(int argc, _TCHAR* argv[])
int main(int arg, char ** argv)
{
	char* proxy =  "sip.nutss.net:5060";
	char * user =  "ari1";
	char *domain = "nutss.net";

	char * pw = "password";
	char* listeningUser = user;  //person to connect to
	char * svcuname = "admin";
	char * svcdomain = "nutss.net";
	struct sockaddr_ns nct;
	int zero = 0;
    int one = 1;
	struct fd_set readfds;
	SOCKET s;

	printf("test starting\n");

	putenv("NUTSS_CERT=client.pem:password@root.pem");

	nutss_config_set(NUTSS_CONFIG_USERNAME, user, strlen(user));
	nutss_config_set(NUTSS_CONFIG_PROXYUSERNAME, user, strlen(user));
	nutss_config_set(NUTSS_CONFIG_PROXYPASSWORD, pw, strlen(pw));
	nutss_config_set(NUTSS_CONFIG_DOMAINNAME, domain, strlen(domain));
	nutss_config_set(NUTSS_CONFIG_SIGPROXY, proxy, strlen(proxy));
	nutss_config_set(NUTSS_CONFIG_OPT_SECURE, &zero, sizeof(zero));
	nutss_config_set(NUTSS_CONFIG_SVCUSERNAME, svcuname, strlen(svcuname));
	nutss_config_set(NUTSS_CONFIG_SVCDOMAINNAME, svcdomain, strlen(svcdomain));
	nutss_init();

	memset(&nct,0, sizeof(nct));
		//now set up nct for the connect
	nct.family = AF_NUTSS;

	strncpy(nct.user, listeningUser, sizeof(nct.user));
	strncpy(nct.domain, domain, sizeof(nct.domain));
	strncpy(nct.service, "nutsstestapp", sizeof(nct.service));

	s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
	if(	0 != nutss_bind(s, (struct sockaddr *)&nct, sizeof(nct)))
	{
		printf("failed to bind correctly\n");
		exit(0);
	}
	else
		listen(s, 10);

	ioctlsocket(s, FIONBIO, (unsigned long *) &one);
	printf("socket set to nonblocking\n");

	FD_ZERO(&readfds);
	FD_SET(s, &readfds);
	if(! select(1, &readfds, 0,0,0))
		printf("select returned no fds\n");
	else
	{
		SOCKET s2;
		printf("\nselect succeeded\n\n");
		s2= nutss_accept(s, 0, 0);
		if(s2 != INVALID_SOCKET)
			printf("\n\n----\nsocket successfully opened\n--\n\n");
		else
		{
			printf("open failed: %d\n", errno);
			exit(0);
		}
		//
	}

	Sleep(1000000);

	return 0;
}

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>
 

GForge.cis.cornell.edu is brought to you by

Cornell Computing and Information Science


Powered By GForge Collaborative Development Environment