// ----------------------------- void test_ip() { int i,k; IPADDRESS * ipa[MAXIP]; unsigned ipaddress,ipx; unsigned short ipaddress6[8], ipx6[8]; printf("IPADDRESS testing\n"); srand( time(0) ); for(i=0;i<MAXIP;i++) { if( i % 2 ) { ipa[i]= ip_new(IPV4_FAMILY); ipaddress = rand() * rand(); ip_set( ipa[i], &ipaddress, IPV4_FAMILY ); if( !ip_equal(ipa[i],&ipaddress, IPV4_FAMILY ) ) printf("error with ip_equal\n"); ip_get( ipa[i], &ipx, IPV4_FAMILY ); if( ipx != ipaddress ) printf("error with ip_get\n"); } else { ipa[i]= ip_new(IPV6_FAMILY); for(k=0;k<8;k++) ipaddress6[k] = (char) (rand() % (1<<16)); ip_set( ipa[i], ipaddress6, IPV6_FAMILY ); if( !ip_equal(ipa[i],&ipaddress6, IPV6_FAMILY ) ) printf("error with ip6_equal\n"); ip_get( ipa[i], ipx6, IPV6_FAMILY ); for(k=0;k<8;k++) if( ipx6[k] != ipaddress6[k] ) printf("error with ip6_get\n"); } printf("[%d] ",i); ip_fprint(stdout,ipa[i]); printf("\n"); } printf("IP testing completed\n"); }
// ------------------------------------------------ // Function: ping_request() // ------------------------------------------------ // Input: IP address // Network interface ID // Output: - // ------------------------------------------------ // Description: Sends a ping request message // ------------------------------------------------ void ping_request(IPV4 ip, BYTE interface) { PPBUF buf; buf = ip_new(ip, 64, interface); if(buf == NULL) return; // --------------------- // assemble ICMP message // --------------------- IPH(buf->start)->prot = IP_PROT_ICMP; ICMP(buf->data)->type = PING_REQUEST; ICMP(buf->data)->code = 0; ICMP(buf->data)->checksum = 0; ICMP(buf->data)->id = random(); ICMP(buf->data)->seq = random(); buf->size = sizeof(ICMP_HDR); // ------------------ // calculate checksum // ------------------ icmp_checksum(buf->data, buf->size); ICMP(buf->data)->checksum = HTONS(~WORDOF(chk_H, chk_L)); // ----------------------------- // sends message to IP interface // ----------------------------- ip_send(buf); release_buffer(buf); }
static void __producer_set_file(struct track_info *ti) { __producer_unload(); ip = ip_new(ti->filename); __producer_status_update(PS_STOPPED); file_changed(ti); }
void test_ip4_parsing(void) { unsigned host, mask, not_flag; PORTSET portset; char **curip; int ret; IPADDRESS *adp; char *ips[] = { "138.26.1.24:25", "1.1.1.1/255.255.255.0:444", "1.1.1.1/16:25-28", "1.1.1.1/255.255.255.255:25 27-29", "z/24", "0/0", "0.0.0.0/0.0.0.0:25-26 28-29 31", "0.0.0.0/0.0.2.0", NULL }; for(curip = ips; curip[0] != NULL; curip++) { portset_init(&portset); /* network byte order stuff */ if((ret = ip4_parse(curip[0], 1, ¬_flag, &host, &mask, &portset)) != 0) { fprintf(stderr, "Unable to parse %s with ret %d\n", curip[0], ret); } else { printf("%c", not_flag ? '!' : ' '); printf("%s/", inet_ntoa(*(struct in_addr *) &host)); printf("%s", inet_ntoa(*(struct in_addr *) &mask)); printf(" parsed successfully!\n"); } /* host byte order stuff */ if((ret = ip4_parse(curip[0], 0, ¬_flag, &host, &mask, &portset)) != 0) { fprintf(stderr, "Unable to parse %s with ret %d\n", curip[0], ret); } else { adp = ip_new(IPV4_FAMILY); ip_set(adp, &host, IPV4_FAMILY); ip_fprint(stdout, adp); fprintf(stdout, "*****************\n"); ip_free(adp); } } return; }
static void _consumer_handle_eof(void) { struct track_info *ti; if (ip_is_remote(ip)) { _producer_stop(); _consumer_drain_and_stop(); player_error("lost connection"); return; } if (player_info.ti) player_info.ti->play_count++; if (player_repeat_current) { if (player_cont) { ip_seek(ip, 0); reset_buffer(); } else { _producer_stop(); _consumer_drain_and_stop(); _player_status_changed(); } return; } if (get_next(&ti) == 0) { _producer_unload(); ip = ip_new(ti->filename); _producer_status_update(PS_STOPPED); /* PS_STOPPED, CS_PLAYING */ if (player_cont) { _producer_play(); if (producer_status == PS_UNLOADED) { _consumer_stop(); track_info_unref(ti); file_changed(NULL); } else { /* PS_PLAYING */ file_changed(ti); if (!change_sf(0)) _prebuffer(); } } else { _consumer_drain_and_stop(); file_changed(ti); } } else { _producer_unload(); _consumer_drain_and_stop(); file_changed(NULL); } _player_status_changed(); }
static void __producer_play(void) { if (producer_status == PS_UNLOADED) { struct track_info *ti; if (get_next(&ti) == 0) { int rc; ip = ip_new(ti->filename); rc = ip_open(ip); if (rc) { player_ip_error(rc, "opening file `%s'", ti->filename); ip_delete(ip); track_info_unref(ti); file_changed(NULL); } else { ip_setup(ip); __producer_status_update(PS_PLAYING); file_changed(ti); } } } else if (producer_status == PS_PLAYING) { if (ip_seek(ip, 0.0) == 0) { reset_buffer(); } } else if (producer_status == PS_STOPPED) { int rc; rc = ip_open(ip); if (rc) { player_ip_error(rc, "opening file `%s'", ip_get_filename(ip)); ip_delete(ip); __producer_status_update(PS_UNLOADED); } else { ip_setup(ip); __producer_status_update(PS_PLAYING); } } else if (producer_status == PS_PAUSED) { __producer_status_update(PS_PLAYING); } }