Exemple #1
0
struct ydapi_comm * ydapi_comm_init()
{
    struct ydapi_comm *yc = malloc(sizeof(struct ydapi_comm));
    yc->httphl = ydapi_init_httph_lines();
    get_server_addrinfo(YDAPI_SERVADDR, YDAPI_SERVPORT, false, &(yc->srvinfo)); 
    get_ip_string(yc->srvinfo, yc->srvip);

    return yc;
}
Exemple #2
0
void classify_packet(uint8_t* packet, struct pcap_pkthdr& header)
{
    struct ip* ip   = (struct ip*) (packet + calc_ip_offset(packet));
    struct udphdr* udp = (struct udphdr*) (packet + calc_udp_offset(packet));
    uint32_t offset  = calc_rtcp_offset(packet);

    uint16_t pos = 0;
    LibTip::CTipRelay relay;
    LibTip::CTipRelay::Classification c =
        relay.Classify((packet + offset), (header.len - offset), pos);

    char srcIP[20];
    char dstIP[20];

    get_ip_string(srcIP, ip->ip_src);
    get_ip_string(dstIP, ip->ip_dst);
    
    printf("%08lu.%06lu:  %s:%05hu tx ",
           header.ts.tv_sec, (unsigned long) header.ts.tv_usec,
           srcIP, ntohs(udp->uh_sport));
           
    switch (c) {
    case LibTip::CTipRelay::SYSTEM:
        printf("SYSTEM ");
        break;
        
    case LibTip::CTipRelay::MEDIA_SOURCE:
        printf("MEDIA SOURCE (pos = 0x%hx) ", pos);
        break;
        
    case LibTip::CTipRelay::MEDIA_SINK:
        printf("MEDIA SINK (pos = 0x%hx) ", pos);
        break;

    case LibTip::CTipRelay::NOT_TIP:
    default:
        printf("NOT_TIP ");
        break;
    }

    printf("to %s:%05hu\n", dstIP, ntohs(udp->uh_dport));
}
Exemple #3
0
/*
 * Takes a socket descriptor and returns the socket's IP address.
 */
int getsock_ip (int fd, char *ipaddr)
{
        struct sockaddr_storage name;
        socklen_t namelen = sizeof (name);

        assert (fd >= 0);

        if (getsockname (fd, (struct sockaddr *) &name, &namelen) != 0) {
                log_message (LOG_ERR, "getsock_ip: getsockname() error: %s",
                             strerror (errno));
                return -1;
        }

        if (get_ip_string ((struct sockaddr *) &name, ipaddr, IP_LENGTH) ==
            NULL)
                return -1;

        return 0;
}
Exemple #4
0
/*
 * Return the peer's socket information.
 */
int getpeer_information (int fd, char *ipaddr, char *string_addr)
{
        struct sockaddr_storage sa;
        socklen_t salen = sizeof sa;

        assert (fd >= 0);
        assert (ipaddr != NULL);
        assert (string_addr != NULL);

        /* Set the strings to default values */
        ipaddr[0] = '\0';
        strlcpy (string_addr, "[unknown]", HOSTNAME_LENGTH);

        /* Look up the IP address */
        if (getpeername (fd, (struct sockaddr *) &sa, &salen) != 0)
                return -1;

        if (get_ip_string ((struct sockaddr *) &sa, ipaddr, IP_LENGTH) == NULL)
                return -1;

        /* Get the full host name */
        return getnameinfo ((struct sockaddr *) &sa, salen,
                            string_addr, HOSTNAME_LENGTH, NULL, 0, 0);
}
Exemple #5
0
void parse_packet(uint8_t* packet, struct pcap_pkthdr& header, bool verbose,
                  bool doAllRtcp, LibTip::MediaType mType)
{
    struct ip* ip   = (struct ip*) (packet + calc_ip_offset(packet));
    struct udphdr* udp = (struct udphdr*) (packet + calc_udp_offset(packet));
    uint32_t offset  = calc_rtcp_offset(packet);

    char srcIP[20];
    char dstIP[20];

    get_ip_string(srcIP, ip->ip_src);
    get_ip_string(dstIP, ip->ip_dst);
    
    LibTip::CPacketBuffer buffer((packet + offset), (header.len - offset));

    // handle compound packets
    while (buffer.GetBufferSize()) {
        std::string type = "";
        LibTip::CRtcpPacket* rtcp_packet = LibTip::CRtcpPacketFactory::CreatePacketFromBuffer(buffer);

        if (rtcp_packet == NULL) {
            break;
        }

        if (rtcp_packet->GetType() == LibTip::CRtcpPacket::RTPFB) {
            LibTip::CRtcpAppFeedbackPacket* fb =
                dynamic_cast<LibTip::CRtcpAppFeedbackPacket*>(rtcp_packet);

            if (fb != NULL) {
                type = "FEEDBACK";
            }

        } else if (rtcp_packet->GetType() == LibTip::CRtcpPacket::APP) {

            LibTip::CRtcpTipPacket* tip_packet =
                dynamic_cast<LibTip::CRtcpTipPacket*>(rtcp_packet);

            if (tip_packet != NULL) {
                type = tip_packet->GetTipPacketTypeString();
            }
            
        } else if (rtcp_packet->GetType() == LibTip::CRtcpPacket::RR) {
            if (doAllRtcp) {
                type = "RR";
            }
        } else if (rtcp_packet->GetType() == LibTip::CRtcpPacket::SDES) {
            if (doAllRtcp) {
                type = "SDES";
            }
        }

        if (type != "") {
            printf("%08lu.%06lu:  %s:%05hu tx %s to %s:%05hu",
                   header.ts.tv_sec, (unsigned long) header.ts.tv_usec,
                   srcIP, ntohs(udp->uh_sport),
                   type.c_str(), dstIP, ntohs(udp->uh_dport));
            
            if (verbose) {
                std::ostringstream o;
                rtcp_packet->ToStream(o, mType);
                printf("%s\n\n", o.str().c_str());
            } else {
                printf("\n");
            }
        }
        
        delete rtcp_packet;
    }
}
Exemple #6
0
/*
 * Open a connection to a remote host.  It's been re-written to use
 * the getaddrinfo() library function, which allows for a protocol
 * independent implementation (mostly for IPv4 and IPv6 addresses.)
 */
int opensock_acl (const char *host, int port, const char *bind_to, vector_t acl)
{
        int sockfd, n;
        struct addrinfo hints, *res, *ressave;
        char portstr[6];

        assert (host != NULL);
        assert (port > 0);

        memset (&hints, 0, sizeof (struct addrinfo));
        hints.ai_family = AF_UNSPEC;
        hints.ai_socktype = SOCK_STREAM;

        snprintf (portstr, sizeof (portstr), "%d", port);

        n = getaddrinfo (host, portstr, &hints, &res);
        if (n != 0) {
                log_message (LOG_ERR,
                             "opensock: Could not retrieve info for %s", host);
                return -1;
        }

        ressave = res;
	sockfd = -1; /* keep lint happy */
        do {
		char ipaddr[IP_LENGTH];
		if (get_ip_string (res->ai_addr, ipaddr, IP_LENGTH) == NULL)
			continue;
		/* For optimizing this check_acl must be splitted
		 * into host checking and ip checking siblings
		 */
		if (! check_acl_quiet(ipaddr, host, acl)) {
			log_message(LOG_NOTICE, "Denied destination '%s' [%s]", host, ipaddr);
			continue;	/* try next address	*/
		}
		log_message(LOG_CONN, "Allowed destination '%s' [%s]", host, ipaddr);

                sockfd =
                    socket (res->ai_family, res->ai_socktype, res->ai_protocol);
                if (sockfd < 0)
                        continue;       /* ignore this one */

                /* Bind to the specified address */
                if (bind_to) {
                        if (bind_socket (sockfd, bind_to,
                                         res->ai_family) < 0) {
                                close (sockfd);
                                continue;       /* can't bind, so try again */
                        }
                } else if (config.bind_address) {
                        if (bind_socket (sockfd, config.bind_address,
                                         res->ai_family) < 0) {
                                close (sockfd);
                                continue;       /* can't bind, so try again */
                        }
                }

                if (connect (sockfd, res->ai_addr, res->ai_addrlen) == 0)
                        break;  /* success */

                close (sockfd);
        } while ((res = res->ai_next) != NULL);

        freeaddrinfo (ressave);
        if (res == NULL) {
                log_message (LOG_ERR,
                             "opensock: Could not establish a connection to %s",
                             host);
                return -1;
        }

        return sockfd;
}