Exemple #1
0
static udp_pair *
NewUTP(
    struct ip *pip,
    struct udphdr *pudp)
{
    udp_pair *pup;

    if (0) {
	 printf("trace.c:NewUTP() calling MakeUdpPair()\n");
    }
    pup = MakeUdpPair();
    ++num_udp_pairs;
    /* make a new one, if possible */
    if ((num_udp_pairs+1) >= max_udp_pairs) {
	MoreUdpPairs(num_udp_pairs+1);
    }

    /* create a new UDP pair record and remember where you put it */
    utp[num_udp_pairs] = pup;
    pup->ignore_pair=ignore_pairs[num_udp_pairs];


    /* grab the address from this packet */
    CopyAddr(&pup->addr_pair,
	     pip, ntohs(pudp->uh_sport), ntohs(pudp->uh_dport));

    /* data structure setup */
    pup->a2b.pup = pup;
    pup->b2a.pup = pup;
    pup->a2b.ptwin = &pup->b2a;
    pup->b2a.ptwin = &pup->a2b;

    /* fill in connection name fields */
    pup->a2b.host_letter = strdup(NextHostLetter());
    pup->b2a.host_letter = strdup(NextHostLetter());
    pup->a_hostname = strdup(HostName(pup->addr_pair.a_address));
    pup->a_portname = strdup(ServiceName(pup->addr_pair.a_port));
    pup->a_endpoint =
	strdup(EndpointName(pup->addr_pair.a_address,
			    pup->addr_pair.a_port));
    pup->b_hostname = strdup(HostName(pup->addr_pair.b_address));
    pup->b_portname = strdup(ServiceName(pup->addr_pair.b_port));
    pup->b_endpoint = 
	strdup(EndpointName(pup->addr_pair.b_address,
			    pup->addr_pair.b_port));

    pup->filename = cur_filename;

    return(pup);
}
// Obtain the name of an endpoint, following connections.
// The result should be released by the caller.
static CFStringRef ConnectedEndpointName(MIDIEndpointRef endpoint) {
    CFMutableStringRef result = CFStringCreateMutable(NULL, 0);
    CFStringRef str;
    OSStatus err;
    
    // Does the endpoint have connections?
    CFDataRef connections = NULL;
    int nConnected = 0;
    bool anyStrings = false;
    err = MIDIObjectGetDataProperty(endpoint, kMIDIPropertyConnectionUniqueID, &connections);
    if (connections != NULL) {
        // It has connections, follow them
        // Concatenate the names of all connected devices
        nConnected = CFDataGetLength(connections) / sizeof(MIDIUniqueID);
        if (nConnected) {
            const SInt32 *pid = reinterpret_cast <const SInt32 *>(CFDataGetBytePtr(connections));
            for (int i = 0; i < nConnected; ++i, ++pid) {
                MIDIUniqueID id = EndianS32_BtoN(*pid);
                MIDIObjectRef connObject;
                MIDIObjectType connObjectType;
                err = MIDIObjectFindByUniqueID(id, &connObject, &connObjectType);
                if (err == noErr) {
                    if (connObjectType == kMIDIObjectType_ExternalSource
                        || connObjectType == kMIDIObjectType_ExternalDestination) {
                        // Connected to an external device's endpoint (10.3 and later).
                        str = EndpointName(static_cast <MIDIEndpointRef>(connObject), true);
                    }
                    else {
                        // Connected to an external device (10.2) (or something else, catch-all)
                        str = NULL;
                        MIDIObjectGetStringProperty(connObject, kMIDIPropertyName, &str);
                    }
                    if (str != NULL) {
                        if (anyStrings)
                            CFStringAppend(result, CFSTR(", "));
                        else anyStrings = true;
                        CFStringAppend(result, str);
                        CFRelease(str);
                    }
                }
            }
        }
        CFRelease(connections);
    }
    if (anyStrings)
        return result;
    
    // Here, either the endpoint had no connections, or we failed to obtain names for any of them.
    return EndpointName(endpoint, false);
}
void CAMIDIEndpoints::AddEndpoints(MIDIEndpointRef endpoint, EndpointList &eplist) {
    Endpoint *ep, *prev;
    OSStatus err;
    CFStringRef str;
    
    // Add the driver-owned endpoint
    ep = new Endpoint(endpoint, EndpointName(endpoint, false), NULL);
    eplist.push_back(ep);
    prev = ep;
    
    // Does the endpoint have connections?
    CFDataRef connections = NULL;
    int nConnected = 0;
    MIDIObjectGetDataProperty(endpoint, kMIDIPropertyConnectionUniqueID, &connections);
    if (connections != NULL) {
        // It has connections, follow them
        nConnected = CFDataGetLength(connections) / sizeof(MIDIUniqueID);
        if (nConnected) {
            const SInt32 *pid = reinterpret_cast <const SInt32 *>(CFDataGetBytePtr(connections));
            for (int i = 0; i < nConnected; ++i, ++pid) {
                MIDIUniqueID id = 0;//EndianS32_BtoN(*pid);
                MIDIObjectRef connObject;
                MIDIObjectType connObjectType;
                err = MIDIObjectFindByUniqueID(id, &connObject, &connObjectType);
                if (err == noErr) {
                    if (connObjectType == kMIDIObjectType_ExternalSource
                        || connObjectType == kMIDIObjectType_ExternalDestination) {
                        // Connected to an external device's endpoint (10.3 and later).
                        str = EndpointName(static_cast <MIDIEndpointRef>(connObject), true);
                    }
                    else {
                        // Connected to an external device (10.2) (or something else, catch-all)
                        str = NULL;
                        MIDIObjectGetStringProperty(connObject, kMIDIPropertyName, &str);
                    }
                    if (str != NULL) {
                        ep = new Endpoint(endpoint, str, connObject);
                        eplist.push_back(ep);
                        prev->SetNext(ep);
                        prev = ep;
                    }
                }
            }
        }
    }
}