Beispiel #1
0
WORD name_ok(BYTE *name, WORD ok, WORD nilok)
{
	WORD	hit;

	if (name[0] == '@' || !name[0] || blank_name(name) )
	{
		if (nilok)
			return (TRUE);
		else
		{
			hndl_alert(1, string_addr(STNONAM));
			return (FALSE);
		}
	}
	else
	{
		hit = find_name(name);
		if (hit == NIL || hit == ok)
			return (TRUE);
		else
		{
			hndl_alert(1, string_addr(STNMDUP));
			return (FALSE);
		}
	}
}
Beispiel #2
0
/*
 * Initialize short-message handling. 
 * Make one or more sockets and set up to listen on them.
 * This function is xxx ought-to-be ipv6-agnostic, and is even
 * almost UDP/TCP-agnostic.
 */
bool
SMnet::listen_on_port(std::string port)
{
	int s;
	int gotasocket = 0;
	struct addrinfo myhints;
	struct addrinfo *myaddrs, *ap;

	memset(&myhints, 0, sizeof(myhints));
	myhints.ai_family = AF_UNSPEC;		// Any address family eg v4/6
	myhints.ai_socktype = SOCK_DGRAM;	// Datagrams for now FIXME
	myhints.ai_flags = AI_PASSIVE;		// From anybody

	s = getaddrinfo(NULL, (port.c_str()), &myhints, &myaddrs);
	if (s != 0) {
		cerr << "listen_on_port(" << port 
		     << ") can't get addr/port to listen on" << endl;
		return -1;
	}
	
	for (ap = myaddrs; ap != NULL; ap = ap->ai_next) {
	
		int fd, i;

		fd = socket(ap->ai_family, ap->ai_socktype, ap->ai_protocol);
		if (fd < 0)
			continue;		// Try another
		// Set our port number & address.
		i = bind(fd, ap->ai_addr, ap->ai_addrlen);
		if (i < 0) {
			cerr << "listen_on_port(" << port
			     << ") can't bind to addr '"
			     << string_addr (ap, true) << "': " 
			     << strerror(errno) << endl;
			close(fd);		// Don't leave it dangling
			continue;		// Try another
		}
		
		(void) fcntl(fd, F_SETFL, O_NONBLOCK);	// Non-blocking I/O
#ifdef O_CLOEXEC
		(void) fcntl(fd, F_SETFD, O_CLOEXEC);	// Close on exec child
#endif

		// Now set up our class to poll on, and use, this socket.
		add_socket (fd, POLLIN|POLLPRI, ap->ai_family,
			ap->ai_socktype, ap->ai_protocol, ap->ai_addr,
			ap->ai_addrlen);
		// Be slightly verbose here.
		cerr << "Listening at address '"
		     << string_addr (ap, true) << "'." << endl;
		gotasocket++;
		// And keep looping to make several sockets if we can!
	}
	freeaddrinfo(myaddrs);		// Don't leak memory.

	if (!gotasocket)
		return false;
	return true;
}
Beispiel #3
0
WORD get_file(WORD label)
{
	WORD	butn, ii;
	BYTE	tmp_path[64], tmp_name[13];
		
	if ( !sav_rcspath[0] )
		get_defpath(tmp_path, "*.RSC");
	else
		strcpy(tmp_path, sav_rcspath);
	tmp_name[0] = '\0';

#if GEMDOS
	if (Sversion() >= 0x0140)
	{
		LONG	fs_label;

		fs_label = string_addr(label);
		fsel_exinput(ADDR(&tmp_path[0]), ADDR(&tmp_name[0]), &butn, (BYTE FAR *)fs_label);
	}
	else
#endif
		fsel_input(ADDR(&tmp_path[0]), ADDR(&tmp_name[0]), &butn);
	graf_mouse(rcs_mform, 0x0L);
	if (butn)
	{
		if (!tmp_name[0])
			if (hndl_alert(1, string_addr(NOFNAME)) == 1)
				return(FALSE);
		if (strcmp(sav_rcspath, tmp_path))
		{
#if GEMDOS
			Dsetpath((const char *)ADDR(tmp_path));
#else
			dos_chdir(ADDR(tmp_path));
#endif
			strcpy(sav_rcspath, tmp_path);
		}
		strcpy(rcs_rfile, &tmp_path[0]);
	 	for (ii = 0; rcs_rfile[ii] && rcs_rfile[ii] != '*'; ii++)
	 		;
	  	rcs_rfile[ii - 1] = NULL;	/* knock off slash */
		strcat(rcs_rfile, "\\");
		strcpy(&rsc_path[1], rcs_rfile);
		rsc_path[0] = strlen(rcs_rfile);
	  	strcat(rcs_rfile, &tmp_name[0]);
		/* Force 'rsc' extension on resource file.*/
			r_to_xfile(rcs_rfile, "RSC"); 
		r_to_xfile(rcs_dfile, "DFN");
		return (TRUE);
	} /* if butn */
	else
		return (FALSE);
} /* get_file */
Beispiel #4
0
LONG get_mem(UWORD bytes)
{
	LONG	ret;
	LONG	left;

	ret = rcs_free;
#if	MC68K
	if (bytes & 0x1)
		bytes++;
#endif
	rcs_free += bytes;
	left = avail_mem();
	if (left < 1000 && !rcs_low)
	{
		hndl_alert(1, string_addr(STLOMEM));
		rcs_low = TRUE;
	}
	if (left <= 0 && !rcs_panic)
	{
		hndl_alert(1, string_addr(STPANIC));
		rcs_panic = TRUE;
	}
	return (ret);
}
Beispiel #5
0
void set_ip_header(IP_HEADER* ip_hdr,char version,unsigned char ihl,unsigned char tos,
				  unsigned short identification,unsigned char zero_flag,unsigned char do_not_fragments,
				  unsigned char more_fragments,unsigned short int fragment_offset,unsigned char ttl,
				  unsigned char protocol,unsigned short int checksum,char* source_address,
				  char* remote_address,unsigned int optional){
	ip_hdr->version = version;
	ip_hdr->ihl     = ihl;
	ip_hdr->tos     = tos;
	if(protocol==IP_TCP_PROTOCOL) 			    ip_hdr->total_length = sizeof(IP_HEADER)+sizeof(TCP_HEADER);
	else if(protocol==IP_UDP_PROTOCOL)  		ip_hdr->total_length = sizeof(IP_HEADER)+sizeof(UDP_HEADER);
	else if(protocol==IP_ICMP_PROTOCOL) 		ip_hdr->total_length = sizeof(IP_HEADER)+sizeof(ICMP_HEADER);
	else    					ip_hdr->total_length = IP_DEFAULT_LENGTH;
	ip_hdr->identification = htons(identification);
	ip_hdr->zero_flag = zero_flag;
	ip_hdr->do_not_fragments = do_not_fragments;
	ip_hdr->more_fragments   = more_fragments;
	ip_hdr->fragment_offset  = fragment_offset;
	ip_hdr->ttl              = ttl;
	ip_hdr->protocol         = protocol;
	ip_hdr->checksum         = checksum;
	ip_hdr->source_address   = string_addr(source_address);
	ip_hdr->remote_address   = string_addr(remote_address);
	ip_hdr->optional = optional;
}
Beispiel #6
0
LOCAL LONG ins_tree(LONG stree, WORD sobj, WORD kind, WORD dobj, WORD dx, WORD dy)
{
	LONG	dtree;
	BYTE	name[9];

	dtree = copy_tree(stree, sobj, TRUE);
	unique_name(&name[0], "TREE%hd", LWGET(RSH_NTREE(head)) + 1);
	if (new_index( (BYTE *) dtree, kind, &name[0]) == NIL)
	{
		hndl_alert(1, string_addr(STNFULL));
		return (-1L);
	}
	else
	{
		add_trindex(dtree);
		dobj = mov_tree(LWGET(RSH_NTREE(head)), dobj, dx, dy);
		select_tree(ad_view, trunpan_f(dobj));
		name_tree(dobj);
		dselct_tree(ad_view, trunpan_f(dobj));
		return (dtree);
	}
}
Beispiel #7
0
VOID get_obname(BYTE *name, LONG ntree, WORD nobj)
{
	WORD	where;
	LONG	addr;

	addr = ntree + nobj * sizeof(OBJECT);
	where = find_value((BYTE *) addr);
	if (where != NIL)
	{
		if (!name[0] || name[0] == '@')
			del_index(where);
		else
			strcpy(get_name(where), name);
	}
	else
	{
		if (name[0] && name[0] != '@')
		{
			where = new_index((BYTE *)addr, OBJKIND, name);
			if (where == NIL)
				hndl_alert(1, string_addr(STNFULL));
		}
	}
}
bool SMnet::msg_is_from_relay(const char *srcaddr, socklen_t srcaddrlen,
			      const char *relay_ip, const char *relay_port)
{
	bool is_from_relay = false;

	struct addrinfo myhints;
	struct addrinfo *myaddrs, *ap;
	int s = 0;

	LOG(DEBUG) << "Source addr: " << string_addr((struct sockaddr *)srcaddr, srcaddrlen, true);

	// We are allowing relay_ip to be empty. If it is, this isn't from a relay.
	if (!relay_ip || strlen(relay_ip) == 0) {
		return false;
	}

	memset(&myhints, 0, sizeof(myhints));
	myhints.ai_family = AF_UNSPEC;		// Any address family eg v4/6
	myhints.ai_socktype = SOCK_DGRAM;	// Datagrams for now FIXME
#ifdef AI_IDN
	myhints.ai_flags = AI_IDN;		// Int'l dom names OK.
#endif
	s = getaddrinfo(relay_ip, relay_port, &myhints, &myaddrs);
	if (!s) {
		for (ap = myaddrs; ap != NULL; ap = ap->ai_next) {
			if (ap->ai_addrlen == srcaddrlen &&
				!memcmp(ap->ai_addr, srcaddr, srcaddrlen)) {
				is_from_relay = true;
				break;
			}
		}
		freeaddrinfo(myaddrs);		// Don't leak memory.
	}

	return is_from_relay;
}
Beispiel #9
0
WORD abandon_button(VOID)
{		
	return(  hndl_alert(1,string_addr(ABNDCHGS)) );
}
Beispiel #10
0
/* Make printable IP address */
std::string
SMnet::string_addr (struct addrinfo *myaddr, bool withport)
{
	return string_addr (myaddr->ai_addr, myaddr->ai_addrlen, withport);
}
Beispiel #11
0
VOID edit_str(LONG tree, WORD sobj)
{
	LONG	obspec; 
	WORD	where, type, exitobj, ok;
	GRECT	p;
	WORD	min_width, neww, len; 
	BYTE	text[73], name[9]; 

	get_fields(tree, sobj, &type, &obspec, &p);
	len = (WORD)LSTRLEN(LLGET(obspec));
	if (len <= 72)
	{
		ini_tree(&tree, STRDIAL);
		where = set_obname(tree, STRNAME, name, ad_view, sobj);
		set_text(tree, OSTRITEM, (LONG)ADDR(&text[0]), 73);
		LLSTRCPY(LLGET(obspec), (LONG)ADDR(&text[0]));
		if ( rcs_state == ALRT_STATE )
			hide_obj( tree, STRNAME);
		if (!text[0])
			text[0] = '@';
		do {
			exitobj = hndl_dial(tree, OSTRITEM, &p);
			desel_obj(tree, exitobj);
			ok = DEFAULT & GET_FLAGS(tree, exitobj);
		} while ( ok && !name_ok(name, where, TRUE));

		if (ok)
		{
			rcs_edited = TRUE;
			get_obname(name, ad_view, sobj);
			if (text[0] == '@')
				text[0] = '\0';

			if (rcs_state == ALRT_STATE)
			{		
				if (strlen(text) > 40 )
				{
					hndl_alert(1, string_addr(STOOLONG));
					text[40] = '\0';
				}
				update_if(obspec, &text[0]);
				fix_alert(ad_view);
				unhide_obj(tree, STRNAME);
			}
			else
			{
				neww = (WORD)(gl_wchar * strlen(text));
				if (rcs_state == MENU_STATE)
				{
					if (type == G_TITLE)
					{
						if (!newsize_obj(ad_view, sobj, neww,gl_hchar, TRUE))
							text[len] = '\0';
						fix_menu_bar(ad_view);
					}
					else if (in_which_menu(ad_view, sobj) == 1
						&& in_menu(ad_view, sobj) == 1
						&& strlen(text) > 20 )
		    		{
						hndl_alert(1, string_addr(STOOLONG));	
						text[20] = '\0';
					}
					else  if(!newsize_obj(ad_view, sobj, neww,gl_hchar, FALSE))
						text[len] = '\0';
				}
				else if (type == G_STRING || type == G_BUTTON )
				{
					min_width = GET_WIDTH(ad_view, sobj);
					if( neww > min_width )
						if(!newsize_obj(ad_view, sobj, neww,gl_hchar, FALSE))
							text[len] = '\0';
				}
			}
			if( rcs_state != ALRT_STATE)
				update_if(obspec, &text[0]);
		}
	}
}
Beispiel #12
0
void set_sockaddr_in(struct sockaddr_in* myaddr,char* source_address,char* source_port){
	myaddr->sin_family = AF_INET;
	myaddr->sin_port   = string_htons(source_port);
	myaddr->sin_addr.s_addr  = string_addr(source_address);
	memset(myaddr->sin_zero,0,8);
}
Beispiel #13
0
void mod_ip_header_source_ip(IP_HEADER* ip_hdr,char* source_address){
	ip_hdr->source_address   = string_addr(source_address);
}