int main(int argc, char **argv) { int lc; char *msg; /* message returned from parse_opts */ int sfd; if ((tst_kvercmp(2, 6, 22)) < 0) { tst_resm(TWARN, "This test can only run on kernels that are 2.6.22 and higher"); exit(0); } if ((msg = parse_opts(argc, argv, NULL, NULL)) != NULL) { tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg); } setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { Tst_count = 0; sfd = do_test1(lc, SIGUSR1); if (sfd < 0) continue; do_test2(lc, sfd, SIGUSR2); close(sfd); } cleanup(); return 0; }
int main(void) { do_test1(); do_test2(); return 0; }
static void do_test1(ALLEGRO_COLOR src_col, ALLEGRO_COLOR dst_col, ALLEGRO_COLOR blend_col, int src_format, int dst_format) { int i, j, k, l, m; int smodes[4] = {ALLEGRO_ALPHA, ALLEGRO_ZERO, ALLEGRO_ONE, ALLEGRO_INVERSE_ALPHA}; int dmodes[4] = {ALLEGRO_INVERSE_ALPHA, ALLEGRO_ZERO, ALLEGRO_ONE, ALLEGRO_ALPHA}; for (i = 0; i < 4; i++) { for (j = 0; j < 4; j++) { for (k = 0; k < 4; k++) { for (l = 0; l < 4; l++) { for (m = 0; m < 3; m++) { do_test2(src_col, dst_col, blend_col, src_format, dst_format, smodes[i], dmodes[j], smodes[k], dmodes[l], m); } } } } } }
static void reply_cb(gpointer data, gint source, PurpleInputCondition cond) { struct stun_conn *sc = data; char buffer[65536]; char *tmp; gssize len; struct in_addr in; struct stun_attrib *attrib; struct stun_header *hdr; struct ifconf ifc; struct ifreq *ifr; struct sockaddr_in *sinptr; memset(&in, 0, sizeof(in)); len = recv(source, buffer, sizeof(buffer) - 1, 0); if (len < 0) { purple_debug_warning("stun", "unable to read stun response\n"); return; } buffer[len] = '\0'; if ((gsize)len < sizeof(struct stun_header)) { purple_debug_warning("stun", "got invalid response\n"); return; } hdr = (struct stun_header*) buffer; if ((gsize)len != (ntohs(hdr->len) + sizeof(struct stun_header))) { purple_debug_warning("stun", "got incomplete response\n"); return; } /* wrong transaction */ if(hdr->transid[0] != sc->packet->transid[0] || hdr->transid[1] != sc->packet->transid[1] || hdr->transid[2] != sc->packet->transid[2] || hdr->transid[3] != sc->packet->transid[3]) { purple_debug_warning("stun", "got wrong transid\n"); return; } if(sc->test==1) { if (hdr->type != MSGTYPE_BINDINGRESPONSE) { purple_debug_warning("stun", "Expected Binding Response, got %d\n", hdr->type); return; } tmp = buffer + sizeof(struct stun_header); while((buffer + len) > (tmp + sizeof(struct stun_attrib))) { attrib = (struct stun_attrib*) tmp; tmp += sizeof(struct stun_attrib); if (!((buffer + len) > (tmp + ntohs(attrib->len)))) break; if(attrib->type == htons(ATTRIB_MAPPEDADDRESS) && ntohs(attrib->len) == 8) { char *ip; /* Skip the first unused byte, * the family(1 byte), and the port(2 bytes); * then read the 4 byte IPv4 address */ memcpy(&in.s_addr, tmp + 4, 4); ip = inet_ntoa(in); if(ip) g_strlcpy(nattype.publicip, ip, sizeof(nattype.publicip)); } tmp += ntohs(attrib->len); } purple_debug_info("stun", "got public ip %s\n", nattype.publicip); nattype.status = PURPLE_STUN_STATUS_DISCOVERED; nattype.type = PURPLE_STUN_NAT_TYPE_UNKNOWN_NAT; nattype.lookup_time = time(NULL); /* is it a NAT? */ ifc.ifc_len = sizeof(buffer); ifc.ifc_req = (struct ifreq *) buffer; ioctl(source, SIOCGIFCONF, &ifc); tmp = buffer; while(tmp < buffer + ifc.ifc_len) { ifr = (struct ifreq *) tmp; tmp += sizeof(struct ifreq); if(ifr->ifr_addr.sa_family == AF_INET) { /* we only care about ipv4 interfaces */ sinptr = (struct sockaddr_in *) &ifr->ifr_addr; if(sinptr->sin_addr.s_addr == in.s_addr) { /* no NAT */ purple_debug_info("stun", "no nat\n"); nattype.type = PURPLE_STUN_NAT_TYPE_PUBLIC_IP; } } } #ifndef NOTYET close_stun_conn(sc); do_callbacks(); #else purple_timeout_remove(sc->timeout); sc->timeout = 0; do_test2(sc); } else if(sc->test == 2) { close_stun_conn(sc); nattype.type = PURPLE_STUN_NAT_TYPE_FULL_CONE; do_callbacks(); #endif } }