Пример #1
0
static int Synthmessage(char *m, int n, void *clientdesc, int clientdesclength, int fd)  {
    struct ClientAddressStruct ras;
    ClientAddr ra = &ras;

    catchupflag= FALSE;

    ras.cl_addr = *((struct sockaddr_in *) clientdesc);
    ras.clilen = clientdesclength;
    ras.sockfd = fd;

    if (ShowBytes) {
	int i;
	printf("%d byte message:\n", n);
	for (i = 0; i < n; ++i) {
	    printf(" %x (%c)\t", m[i], m[i]);
	    if (i%4 == 3) printf("\n");
	}
	printf("\n");
    }

#ifdef PRINTADDRS
    PrintClientAddr(ra);
#endif

    PrintOSCPacket(m, n);
    return catchupflag;
}
Пример #2
0
void ParseOSCPacket(char *buf, int n, ClientAddr returnAddr) {
    int size, messageLen, i;
    char *messageName;
    char *args;

#ifdef PRINTADDRS
    PrintClientAddr(returnAddr);
#endif


    if ((n%4) != 0) {
	complain("SynthControl packet size (%d) not a multiple of 4 bytes: dropping",
		 n);
	return;
    }

    if ((n >= 8) && (strncmp(buf, "#bundle", 8) == 0)) {
	/* This is a bundle message. */

	if (n < 16) {
	    complain("Bundle message too small (%d bytes) for time tag", n);
	    return;
	}

	/* Print the time tag */
	printf("[ %lx%08lx\n", ntohl(*((unsigned long *)(buf+8))),
	       ntohl(*((unsigned long *)(buf+12))));
	/* Note: if we wanted to actually use the time tag as a little-endian
	   64-bit int, we'd have to word-swap the two 32-bit halves of it */

	i = 16; /* Skip "#group\0" and time tag */
	while(i<n) {
	    size = ntohl(*((int *) (buf + i)));
	    if ((size % 4) != 0) {
		complain("Bad size count %d in bundle (not a multiple of 4)", size);
		return;
	    }
	    if ((size + i + 4) > n) {
		complain("Bad size count %d in bundle (only %d bytes left in entire bundle)",
			 size, n-i-4);
		return;	
	    }
	    
	    /* Recursively handle element of bundle */
	    ParseOSCPacket(buf+i+4, size, returnAddr);
	    i += 4 + size;
	}
	if (i != n) {
	    complain("This can't happen");
	}
	printf("]\n");
    } else {
	/* This is not a bundle message */

	messageName = buf;
	args = DataAfterAlignedString(messageName, buf+n);
	if (args == 0) {
	    complain("Bad message name string: %s\nDropping entire message.\n",
		     htm_error_string);
	    return;
	}
	messageLen = args-messageName;	    
	Smessage(messageName, (void *)args, n-messageLen, returnAddr);
    }
}