@@ -212,30 +212,40 @@ static struct hdhomerun_device_t *hdhomerun_device_create_from_str_device_id(con
212212 return NULL ;
213213}
214214
215- static struct hdhomerun_device_t * hdhomerun_device_create_from_str_ip ( const char * device_str , struct hdhomerun_debug_t * dbg )
215+ static struct hdhomerun_device_t * hdhomerun_device_create_from_str_ip_result ( unsigned long a [ 4 ], unsigned int port , unsigned int tuner , struct hdhomerun_debug_t * dbg )
216216{
217- unsigned long a [4 ];
218- unsigned int port = 0 ;
219- unsigned int tuner = 0 ;
220- if (sscanf (device_str , "%lu.%lu.%lu.%lu:%u" , & a [0 ], & a [1 ], & a [2 ], & a [3 ], & port ) != 5 ) {
221- if (sscanf (device_str , "%lu.%lu.%lu.%lu-%u" , & a [0 ], & a [1 ], & a [2 ], & a [3 ], & tuner ) != 5 ) {
222- return NULL ;
223- }
224- }
225-
226217 unsigned long device_ip = (a [0 ] << 24 ) | (a [1 ] << 16 ) | (a [2 ] << 8 ) | (a [3 ] << 0 );
227218 struct hdhomerun_device_t * hd = hdhomerun_device_create (HDHOMERUN_DEVICE_ID_WILDCARD , (uint32_t )device_ip , tuner , dbg );
228219 if (!hd ) {
229220 return NULL ;
230221 }
231222
232223 if (hd -> multicast_ip != 0 ) {
233- hd -> multicast_port = port ;
224+ hd -> multicast_port = ( uint16_t ) port ;
234225 }
235226
236227 return hd ;
237228}
238229
230+ static struct hdhomerun_device_t * hdhomerun_device_create_from_str_ip (const char * device_str , struct hdhomerun_debug_t * dbg )
231+ {
232+ unsigned long a [4 ];
233+ unsigned int port = 0 ;
234+ unsigned int tuner = 0 ;
235+
236+ if (sscanf (device_str , "%lu.%lu.%lu.%lu:%u" , & a [0 ], & a [1 ], & a [2 ], & a [3 ], & port ) == 5 ) {
237+ return hdhomerun_device_create_from_str_ip_result (a , port , tuner , dbg );
238+ }
239+ if (sscanf (device_str , "%lu.%lu.%lu.%lu-%u" , & a [0 ], & a [1 ], & a [2 ], & a [3 ], & tuner ) == 5 ) {
240+ return hdhomerun_device_create_from_str_ip_result (a , port , tuner , dbg );
241+ }
242+ if (sscanf (device_str , "%lu.%lu.%lu.%lu" , & a [0 ], & a [1 ], & a [2 ], & a [3 ]) == 4 ) {
243+ return hdhomerun_device_create_from_str_ip_result (a , port , tuner , dbg );
244+ }
245+
246+ return NULL ;
247+ }
248+
239249static struct hdhomerun_device_t * hdhomerun_device_create_from_str_dns (const char * device_str , struct hdhomerun_debug_t * dbg )
240250{
241251#if defined(__CYGWIN__ )
0 commit comments