@@ -312,236 +312,21 @@ int NET_UDPDriver::ResolveHostName( char *hostname, node_t* node )
312312 return FALSE ;
313313}
314314
315- #ifdef SYSTEM_TARGET_OSX
316- // get the local IP corresponding to the configured interface -----------------
317- //
318- int NET_UDPDriver::_RetrieveLocalIP ()
319- {
320- // FIXME: implement :)
321- int selected_interface = 0 ;
322-
323- int sockfd = socket ( AF_INET, SOCK_DGRAM, 0 );
324- if ( sockfd < 0 ) {
325- MSGOUT ( " NET_UDPDriver::_RetrieveLocalIP(): can't open socket." );
326- return FALSE ;
327- }
328-
329- int infolen = sizeof ( struct ifreq ) * 10 ;
330- char * infobuf = NULL ;
331- struct ifconf ifc;
332-
333- // get all interface configurations into buffer
334- int lastlen = 0 ;
335- for ( ;; ) {
336-
337- infobuf = (char *) ALLOCMEM ( infolen );
338- if ( infobuf == NULL )
339- OUTOFMEM ( 0 );
340-
341- ifc.ifc_len = infolen;
342- ifc.ifc_buf = infobuf;
343-
344- if ( ioctl ( sockfd, SIOCGIFCONF, &ifc ) < 0 ) {
345- if ( ( errno != EINVAL ) || ( lastlen != 0 ) ) {
346- MSGOUT ( " NET_UDPDriver::_RetrieveLocalIP(): ioctl error." );
347- FREEMEM ( infobuf );
348- CLOSESOCKET ( sockfd );
349- return FALSE ;
350- }
351- } else {
352- if ( ifc.ifc_len == lastlen )
353- break ;
354- lastlen = ifc.ifc_len ;
355- }
356-
357- infolen += sizeof ( struct ifreq ) * 10 ;
358- FREEMEM ( infobuf );
359- }
360-
361- int ifnum = 0 ;
362-
363- // analyze all interface configurations in buffer
364- for ( char *ptr = infobuf; ptr < infobuf + ifc.ifc_len ; ) {
365-
366- struct ifreq * ifr = (struct ifreq *) ptr;
367-
368- // advance to next structure in buffer
369-
370- int len = sizeof (struct sockaddr );
371-
372- // int len = max( sizeof(struct sockaddr), ifr->ifr_addr.sa_len );
373-
374- ptr += sizeof ( ifr->ifr_name ) + len;
375-
376- // only handle IPV4 entries
377- if ( ifr->ifr_addr .sa_family != AF_INET ) {
378- continue ;
379- }
380-
381- char if_addr[ MAX_IPADDR_LEN + 1 ];
382- sockaddr_in *sa = (struct sockaddr_in *) &ifr->ifr_addr ;
383- inet_ntop ( AF_INET, &sa->sin_addr , if_addr, MAX_IPADDR_LEN + 1 );
384-
385- if ( strcmp ( " 127.0.0.1" , if_addr ) == 0 ) {
386- MSGOUT ( " skipping loopback interface" );
387- continue ;
388- }
389-
390- MSGOUT ( " found interface #%d: %s" , ifnum, if_addr );
391-
392- // is this our interface, then take the ip address
393- if ( ifnum == selected_interface ) {
394-
395- // store numeric
396- memcpy ( &m_Node, &sa->sin_addr , IP_ADR_LENGTH );
397-
398- // store presentation
399- inet_ntop ( AF_INET, &m_Node, m_szIP, MAX_IPADDR_LEN + 1 );
400-
401- // store port number in ip address
402- NODE_StorePort ( &m_Node, m_selected_port );
403-
404- break ;
405- }
406-
407- ifnum++;
408- }
409-
410- FREEMEM ( infobuf );
411- CLOSESOCKET ( sockfd );
412-
413- return TRUE ;
414- }
415315
416- #else
417- // get the local IP corresponding to the configured interface -----------------
418- //
419316int NET_UDPDriver::_RetrieveLocalIP ()
420317{
421- // FIXME: implement :)
422- int selected_interface = 0 ;
423-
424- int sockfd = socket ( AF_INET, SOCK_DGRAM, 0 );
425- if ( sockfd < 0 ) {
426- MSGOUT ( " NET_UDPDriver::_RetrieveLocalIP(): can't open socket." );
427- return FALSE ;
428- }
429-
430- int infolen = sizeof ( struct ifreq ) * 10 ;
431- char * infobuf = NULL ;
432-
433- struct ifconf ifc;
434-
435- infobuf = (char *) ALLOCMEM ( infolen );
436- if ( infobuf == NULL )
437- OUTOFMEM ( 0 );
438-
439- ifc.ifc_len = infolen;
440- ifc.ifc_buf = infobuf;
441-
442-
443- // get all interface configurations into buffer
444- int lastlen = sizeof ( struct ifreq ) * 10 ;
445- for ( ;; ) {
446-
447- infobuf = (char *) ALLOCMEM ( infolen );
448- if ( infobuf == NULL )
449- OUTOFMEM ( 0 );
450-
451- ifc.ifc_len = infolen;
452- ifc.ifc_buf = infobuf;
453-
454- if ( ioctl ( sockfd, SIOCGIFCONF, &ifc ) < 0 ) {
455- if ( ( errno != EINVAL ) || ( lastlen != 0 ) ) {
456- MSGOUT ( " NET_UDPDriver::_RetrieveLocalIP(): ioctl error." );
457- FREEMEM ( infobuf );
458- CLOSESOCKET ( sockfd );
459- return FALSE ;
460- }
461- } else {
462- // if ifc.ifc_len is less than lastlen, we got it all.
463- if ( ifc.ifc_len < lastlen ){
464- break ;
465- }
466- // if not, save the last length
467- lastlen = ifc.ifc_len ;
468-
469- // make it bigger by 1 record
470- infolen += sizeof ( struct ifreq );
471-
472- }
473-
474- // infolen += sizeof( struct ifreq ) * 10;
475- FREEMEM ( infobuf );
476- }
477-
478- int rc = 0 ;
479- int ifnum = -1 ;
480-
481- // analyze all interface configurations in buffer
482- for ( char *ptr = infobuf; ptr < infobuf + ifc.ifc_len ; ) {
483-
484- struct ifreq * ifr = (struct ifreq *) ptr;
485-
486- // advance to next structure in buffer
487-
488- #ifdef SYSTEM_MACOSX_UNUSED
489- int len = max ( sizeof (struct sockaddr ), ifr->ifr_addr .sa_len );
490- #else
491- int len = sizeof (struct sockaddr );
492- #endif
493-
494- // int len = max( sizeof(struct sockaddr), ifr->ifr_addr.sa_len );
495-
496- ptr += sizeof ( ifr->ifr_name ) + len;
497-
498- // only handle IPV4 entries
499- if ( ifr->ifr_addr .sa_family != AF_INET ) {
500- continue ;
501- }
502-
503- char if_addr[ MAX_IPADDR_LEN + 1 ];
504- sockaddr_in *sa = (struct sockaddr_in *) &ifr->ifr_addr ;
505- inet_ntop ( AF_INET, &sa->sin_addr , if_addr, MAX_IPADDR_LEN + 1 );
506-
507- if ( strcmp ( " 127.0.0.1" , if_addr ) == 0 ) {
508- MSGOUT ( " skipping loopback interface" );
509- continue ;
510- }
511-
512-
513-
514- node_t tmp_node;
515- memcpy ( &tmp_node, &sa->sin_addr , IP_ADR_LENGTH );
516- NetworkInterfaces.push_back (tmp_node);
517-
518-
519- ifnum++;
520- MSGOUT ( " found interface #%d: %s" , ifnum, if_addr );
521- }
522-
523- ASSERT (ifnum > -1 );
524-
525-
526- // see if our preferred interface is in the vector
527- if (NetworkInterfaces.size () >= m_PreferredInterface) {
528- // let's use the preferred interface to set up the bind address
529-
530- _SetupInterface (&NetworkInterfaces[m_PreferredInterface]);
531-
532-
533- } else {
534- // else let's use interface 0
535- _SetupInterface (&NetworkInterfaces[0 ]); // rc checked below
536- }
537-
538- // FREEMEM( infobuf );
539- CLOSESOCKET ( sockfd );
540-
318+ // all of the other stuff that was in here was stupid.
319+ // just listen on all interfaces.
320+ // store numeric
321+ memcpy ( &m_Node, " 0.0.0.0" , IP_ADR_LENGTH );
322+
323+ // store presentation
324+ inet_ntop ( AF_INET, &m_Node, m_szIP, MAX_IPADDR_LEN + 1 );
325+
326+ // store port number in ip address
327+ NODE_StorePort ( &m_Node, m_selected_port );
541328 return TRUE ;
542329}
543-
544- #endif
545330// key table for netiface command -----------------------------------------
546331//
547332key_value_s netiface_key_value[] = {
0 commit comments