Exemplo n.º 1
0
static void updateTech(void)
{
	char buf[16000];
	char *p = buf;
	const char *ext;
	int type;
	int i;
	ext = ASAPInfo_GetOriginalModuleExt(edited_info, saved_module, saved_module_len);
	if (ext != NULL)
		p += sprintf(p, "Composed in %s\r\n", ASAPInfo_GetExtDescription(ext));
	i = ASAPInfo_GetSongs(edited_info);
	if (i > 1) {
		p += sprintf(p, "SONGS %d\r\n", i);
		i = ASAPInfo_GetDefaultSong(edited_info);
		if (i > 0)
			p += sprintf(p, "DEFSONG %d (song %d)\r\n", i, i + 1);
	}
	p += sprintf(p, ASAPInfo_GetChannels(edited_info) > 1 ? "STEREO\r\n" : "MONO\r\n");
	p += sprintf(p, ASAPInfo_IsNtsc(edited_info) ? "NTSC\r\n" : "PAL\r\n");
	type = ASAPInfo_GetTypeLetter(edited_info);
	if (type != 0)
		p += sprintf(p, "TYPE %c\r\n", type);
	p += sprintf(p, "FASTPLAY %d (%d Hz)\r\n", ASAPInfo_GetPlayerRateScanlines(edited_info), ASAPInfo_GetPlayerRateHz(edited_info));
	if (type == 'C')
		p += sprintf(p, "MUSIC %04X\r\n", ASAPInfo_GetMusicAddress(edited_info));
	if (type != 0) {
		p = appendAddress(p, "INIT %04X\r\n", ASAPInfo_GetInitAddress(edited_info));
		p = appendAddress(p, "PLAYER %04X\r\n", ASAPInfo_GetPlayerAddress(edited_info));
		p = appendAddress(p, "COVOX %04X\r\n", ASAPInfo_GetCovoxAddress(edited_info));
	}
	i = ASAPInfo_GetSapHeaderLength(edited_info);
	if (i >= 0) {
		while (p < buf + sizeof(buf) - 17 && i + 4 < saved_module_len) {
			int start = saved_module[i] + (saved_module[i + 1] << 8);
			int end;
			if (start == 0xffff) {
				i += 2;
				start = saved_module[i] + (saved_module[i + 1] << 8);
			}
			end = saved_module[i + 2] + (saved_module[i + 3] << 8);
			p += sprintf(p, "LOAD %04X-%04X\r\n", start, end);
			i += 5 + end - start;
		}
	}
	chomp(buf);
	SendDlgItemMessage(infoDialog, IDC_TECHINFO, WM_SETTEXT, 0, (LPARAM) buf);
}
Exemplo n.º 2
0
__private_extern__
void
interface_update_ipv6(struct ifaddrs *ifap, const char *if_name)
{
	struct ifaddrs		*ifa;
	struct ifaddrs		*ifap_temp	= NULL;
	CFStringRef		interface;
	boolean_t		interfaceFound	= FALSE;
	CFStringRef		key		= NULL;
	CFMutableDictionaryRef	oldIFs;
	CFMutableDictionaryRef	newDict		= NULL;
	CFMutableDictionaryRef	newIFs;
	int			sock		= -1;

	oldIFs = CFDictionaryCreateMutable(NULL,
					   0,
					   &kCFTypeDictionaryKeyCallBacks,
					   &kCFTypeDictionaryValueCallBacks);
	newIFs = CFDictionaryCreateMutable(NULL,
					   0,
					   &kCFTypeDictionaryKeyCallBacks,
					   &kCFTypeDictionaryValueCallBacks);

	if (!ifap) {
		if (getifaddrs(&ifap_temp) == -1) {
			SCLog(TRUE, LOG_ERR, CFSTR("getifaddrs() failed: %s"), strerror(errno));
			goto error;
		}
		ifap = ifap_temp;
	}

	for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
		struct in6_ifreq	ifr6;
#define	flags6	ifr6.ifr_ifru.ifru_flags6
		struct sockaddr_in6	*sin6;

		if (ifa->ifa_addr->sa_family != AF_INET6) {
			continue;			/* sorry, not interested */
		}

		/* check if this is the requested interface */
		if (if_name) {
			if (strncmp(if_name, ifa->ifa_name, IFNAMSIZ) == 0) {
				interfaceFound = TRUE;	/* yes, this is the one I want */
			} else {
				continue;		/* sorry, not interested */
			}
		}

		if (sock == -1) {
			sock = dgram_socket(AF_INET6);
			if (sock == -1) {
				SCLog(TRUE, LOG_NOTICE, CFSTR("interface_update_ipv6: socket open failed, %s"), strerror(errno));
				goto error;
			}
		}

		/* get the current cache information */
		interface = CFStringCreateWithCString(NULL, ifa->ifa_name, kCFStringEncodingMacRoman);
		key       = SCDynamicStoreKeyCreateNetworkInterfaceEntity(NULL,
									  kSCDynamicStoreDomainState,
									  interface,
									  kSCEntNetIPv6);
		CFRelease(interface);

		newDict = copyIF(key, oldIFs, newIFs);

		/* ALIGN: ifa->ifa_addr aligned (getifaddrs), cast ok. */
		sin6 = (struct sockaddr_in6 *)(void *)ifa->ifa_addr;

		/* XXX: embedded link local addr check */
		if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr) || IN6_IS_ADDR_MC_LINKLOCAL(&sin6->sin6_addr)) {
			u_int16_t	index;

			index = sin6->sin6_addr.s6_addr16[1];
			if (index != 0) {
				sin6->sin6_addr.s6_addr16[1] = 0;
				if (sin6->sin6_scope_id == 0) {
					sin6->sin6_scope_id = ntohs(index);
				}
			}
		}

		bzero((char *)&ifr6, sizeof(ifr6));
		strncpy(ifr6.ifr_name, ifa->ifa_name, sizeof(ifr6.ifr_name));
		ifr6.ifr_addr = *sin6;
		if (ioctl(sock, SIOCGIFAFLAG_IN6, &ifr6) == -1) {
			/* if flags not available for this address */
			SCLog(TRUE,
			      (errno != EADDRNOTAVAIL) ? LOG_NOTICE : LOG_DEBUG,
			      CFSTR("interface_update_ipv6: ioctl failed, %s"),
			      strerror(errno));
		}

		appendAddress  (newDict, kSCPropNetIPv6Addresses, sin6);
#ifdef	NOTYET
		appendScopeID  (newDict, sin6);
#endif	/* NOTYET */
		/* ALIGN: ifa should be aligned (from getifaddrs), cast ok.
		 * appendPrefixLen expect byte alignment */
		appendPrefixLen(newDict, (struct sockaddr_in6 *)(void *)ifa->ifa_netmask);
		appendFlags    (newDict, flags6);


		if (ifa->ifa_flags & IFF_POINTOPOINT
		    && ifa->ifa_dstaddr != NULL) {
			struct sockaddr_in6	*dst6;

			/* ALIGN: ifa should be aligned (from getifaddrs), cast ok. */
			dst6 = (struct sockaddr_in6 *)(void *)ifa->ifa_dstaddr;

			/* XXX: embedded link local addr check */
			if (IN6_IS_ADDR_LINKLOCAL(&dst6->sin6_addr) || IN6_IS_ADDR_MC_LINKLOCAL(&dst6->sin6_addr)) {
				u_int16_t	index;

				index = dst6->sin6_addr.s6_addr16[1];
				if (index != 0) {
					dst6->sin6_addr.s6_addr16[1] = 0;
					if (dst6->sin6_scope_id == 0) {
						dst6->sin6_scope_id = ntohs(index);
					}
				}
			}

			appendAddress(newDict, kSCPropNetIPv6DestAddresses, dst6);
		}

		CFDictionarySetValue(newIFs, key, newDict);
		CFRelease(newDict);
		CFRelease(key);
	}

	/* if the last address[es] were removed from the target interface */
	if (if_name && !interfaceFound) {
		interface = CFStringCreateWithCString(NULL, if_name, kCFStringEncodingMacRoman);
		key       = SCDynamicStoreKeyCreateNetworkInterfaceEntity(NULL,
									  kSCDynamicStoreDomainState,
									  interface,
									  kSCEntNetIPv6);
		CFRelease(interface);

		newDict = copyIF(key, oldIFs, newIFs);

		CFDictionarySetValue(newIFs, key, newDict);
		CFRelease(newDict);
		CFRelease(key);
	}

	CFDictionaryApplyFunction(newIFs, updateStore, oldIFs);

    error :

	if (ifap_temp)	freeifaddrs(ifap_temp);
	if (sock != -1)	close(sock);
	CFRelease(oldIFs);
	CFRelease(newIFs);

	return;
}