Exemple #1
0
int ipx_kali_OpenSocket(ipx_socket_t *sk, int port)
{
	printf("IPX_kali: OpenSocket on port(%d)\n", port);

	if (!open_sockets) {
		if (have_empty_address()) {
			if (ipx_kali_GetMyAddress() < 0) {
				printf("IPX_kali: Error communicating with KaliNix\n");
				return -1;
			}
		}
	}
	if (!port)
		port = dynamic_socket++;

	if ((sk->fd = KaliOpenSocket(htons(port))) < 0) {
		printf("IPX_kali: OpenSocket Failed on port(%d)\n", port);
		sk->fd = -1;
		return -1;
	}
	open_sockets++;
	last_socket = port;
	sk->socket = port;
	return 0;
}
Exemple #2
0
static int ipx_udp_OpenSocket(ipx_socket_t *sk, int port) {
struct sockaddr_in sin;

	if (!open_sockets)
		if (have_empty_address())
		if (ipx_udp_GetMyAddress() < 0) FAIL("Error getting my address");

	msg("OpenSocket on D1X socket port %d",port);

	if (!port)
		port = dynamic_socket++;

	if ((sk->fd = socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP)) < 0) {
		sk->fd = -1;
		FAIL("socket() creation failed on port %d: %m",port);
		}
  if (setsockopt(sk->fd,SOL_SOCKET,SO_BROADCAST,&val_one,sizeof(val_one))) {
		if (close(sk->fd)) msg("close() failed during error recovery: %m");
		sk->fd=-1;
		FAIL("setsockopt(SO_BROADCAST) failed: %m");
		}
	sin.sin_family=AF_INET;
	sin.sin_addr.s_addr=htonl(INADDR_ANY);
	sin.sin_port=htons(baseport);
	if (bind(sk->fd,(struct sockaddr *)&sin,sizeof(sin))) {
		if (close(sk->fd)) msg("close() failed during error recovery: %m");
		sk->fd=-1;
		FAIL("bind() to UDP port %d failed: %m",baseport);
		}

	open_sockets++;
	sk->socket = port;
	return 0;
}
Exemple #3
0
int UDPGetMyAddress (void) {

char buf [256];
int i = 0;
char *s,*s2,*ns;

if (!have_empty_address ())
	return 0;
if (!((i=FindArg ("-udp")) && (s=pszArgList [i+1]) && (*s=='=' || *s=='+' || *s=='@'))) 
	s = NULL;
if (gethostname (buf,sizeof (buf))) 
	FAIL ("Error getting my hostname");
if (!(queryhost (buf))) 
	FAIL ("Querying my own hostname \"%s\"",buf);
if (s) 
	while (*s == '@') {
		portshift (++s);
		while (isdigit (*s)) 
			s++;
		}
memset (ipx_MyAddress, 0, 4);
memcpy (ipx_MyAddress + 4, qhbuf, 6);
udpBasePort [gameStates.multi.bServer] += (short) ntohs (*(unsigned short *) (qhbuf + 4));
if (!s || (s && !*s)) 
	addiflist ();
else {
	struct sockaddr_in *sin;
	if (*s=='+') 
		addiflist ();
	s++;
	for (;;) {
		while (isspace (*s)) 
			s++;
		if (!*s) 
			break;
		for (s2=s;*s2 && *s2!=',';s2++)
			;
		chk (ns = (char *) D2_ALLOC (s2-s+1));
		memcpy (ns,s,s2-s);
		ns [s2-s]='\0';
		if (!queryhost (ns)) 
			//msg ("Ignored IP interface-destination \"%s\" as being invalid",ns);
		D2_FREE (ns);
		chkbroadsize ();
		sin=broads + broadnum++;
		sin->sin_family=AF_INET;
		memcpy (&sin->sin_addr,qhbuf+0,4);
		sin->sin_port=htons (( (short)ntohs (* (unsigned short *) (qhbuf+4)))+UDP_BASEPORT);
		s=s2+ (*s2==',');
		}
	}
unifyiflist ();
return 0;
}
Exemple #4
0
int ipx_kali_GetMyAddress(void)
{

	kaliaddr_ipx mKaliAddr;

	if (!have_empty_address())
		return 0;

	if (KaliGetNodeNum(&mKaliAddr) < 0)
		return -1;

	memset(ipx_MyAddress, 0, 4);
	memcpy(ipx_MyAddress + 4, mKaliAddr.sa_nodenum, sizeof(mKaliAddr.sa_nodenum));

	return 0;
}
Exemple #5
0
int UDPGetMyAddress(void) {

char buf[256];
int i;
char *s,*s2,*ns;

	if (!have_empty_address())
		return 0;

	if (!((i=FindArg("-udp")) && (s=Args[i+1]) && (*s=='=' || *s=='+' || *s=='@'))) 
		s=NULL;

	if (gethostname(buf,sizeof(buf))) 
		FAIL("Error getting my hostname");
	if (!queryhost(buf)) 
		FAIL("Querying my own hostname \"%s\"",buf);

	if (s) 
		while (*s=='@') {
			portshift(++s);
			while (isdigit(*s)) 
				s++;
			}

	memset(ipx_MyAddress+0,0,4);
	memcpy(ipx_MyAddress+4,qhbuf,6);
	baseport+=(short)ntohs(*(unsigned short *)(qhbuf+4));
#if 0
	ipx_MyAddress [4] = 127;
	ipx_MyAddress [5] = 0;
	ipx_MyAddress [6] = 0;
	ipx_MyAddress [7] = 1;
#endif
	if (!(s && *s)) 
		addiflist();
	else {
		if (*s=='+') 
			addiflist();
		s++;
		for (;;) {
				struct sockaddr_in *sin;
			while (isspace(*s)) 
				s++;
			if (!*s) 
				break;
			for (s2=s;*s2 && *s2!=',';s2++)
				;
			chk(ns=D2_ALLOC(s2-s+1));
			memcpy(ns,s,s2-s);
			ns[s2-s]='\0';
			if (!queryhost(ns)) 
				msg("Ignored broadcast-destination \"%s\" as being invalid",ns);
			D2_FREE(ns);
			chkbroadsize();
			sin=broads+(broadnum++);
			sin->sin_family=AF_INET;
			memcpy(&sin->sin_addr,qhbuf+0,4);
			sin->sin_port=htons(((short)ntohs(*(unsigned short *)(qhbuf+4)))+UDP_BASEPORT);
			s=s2+(*s2==',');
			}
		}

	unifyiflist();
#ifndef _WIN32
	//printf(MSGHDR "Using TCP/IP address ");
	dumpraddr(ipx_MyAddress+4);
	//putchar('\n');
	if (broadnum) {
		//printf(MSGHDR "Using %u broadcast-dest%s:",broadnum,(broadnum==1?"":"s"));
		for (i=0;i<broadnum;i++) {
			//putchar(' ');
			dumpaddr(broads+i);
			}
		//putchar('\n');
		}
#endif
	return 0;
}