Changeset 7f432665c1ce3f5fc981129f9f8fc16a0591460c
- Timestamp:
- 26/06/05 11:12:36
(3 years ago)
- Author:
- Rémi Denis-Courmont <rem@videolan.org>
- git-committer:
- Rémi Denis-Courmont <rem@videolan.org> 1119777156 +0000
- git-parent:
[1a57857cc63dde28543a6065c78c487343c6e172]
- git-author:
- Rémi Denis-Courmont <rem@videolan.org> 1119777156 +0000
- Message:
Use integer rather than strings for UDP/TCP port numbers
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r7f95200 |
r7f43266 |
|
| 389 | 389 | # define NI_MAXSERV 32 |
|---|
| 390 | 390 | # endif |
|---|
| | 391 | # define NI_MAXNUMERICHOST 48 |
|---|
| 391 | 392 | |
|---|
| 392 | 393 | # ifndef NI_NUMERICHOST |
|---|
| … | … | |
| 422 | 423 | |
|---|
| 423 | 424 | VLC_EXPORT( const char *, vlc_gai_strerror, ( int ) ); |
|---|
| 424 | | VLC_EXPORT( int, vlc_getnameinfo, ( vlc_object_t *, const struct sockaddr *, int, char *, int, char *, int, int ) ); |
|---|
| 425 | | VLC_EXPORT( int, vlc_getaddrinfo, ( vlc_object_t *, const char *, const char *, const struct addrinfo *, struct addrinfo ** ) ); |
|---|
| | 425 | VLC_EXPORT( int, vlc_getnameinfo, ( vlc_object_t *, const struct sockaddr *, int, char *, int, int *, int ) ); |
|---|
| | 426 | VLC_EXPORT( int, vlc_getaddrinfo, ( vlc_object_t *, const char *, int, const struct addrinfo *, struct addrinfo ** ) ); |
|---|
| 426 | 427 | VLC_EXPORT( void, vlc_freeaddrinfo, ( struct addrinfo * ) ); |
|---|
| 427 | 428 | |
|---|
| r2a5f4e0 |
r7f43266 |
|
| 367 | 367 | mtime_t (*vout_SynchroDate_inner) (vout_synchro_t *); |
|---|
| 368 | 368 | void (*vout_SynchroNewPicture_inner) (vout_synchro_t *, int, int, mtime_t, mtime_t, int, vlc_bool_t); |
|---|
| 369 | | int (*vlc_getaddrinfo_inner) (vlc_object_t *, const char *, const char *, const struct addrinfo *, struct addrinfo **); |
|---|
| 370 | | int (*vlc_getnameinfo_inner) (vlc_object_t *, const struct sockaddr *, int, char *, int, char *, int, int); |
|---|
| | 369 | int (*vlc_getaddrinfo_inner) (vlc_object_t *, const char *, int, const struct addrinfo *, struct addrinfo **); |
|---|
| | 370 | int (*vlc_getnameinfo_inner) (vlc_object_t *, const struct sockaddr *, int, char *, int, int *, int); |
|---|
| 371 | 371 | void (*InitMD5_inner) (struct md5_s *); |
|---|
| 372 | 372 | void (*EndMD5_inner) (struct md5_s *); |
|---|
| rec08d03 |
r7f43266 |
|
| 241 | 241 | if( ftp_ReadCommand( p_access, &i_answer, NULL ) == 2 ) |
|---|
| 242 | 242 | { |
|---|
| 243 | | char hostaddr[NI_MAXHOST]; |
|---|
| | 243 | char hostaddr[NI_MAXNUMERICHOST]; |
|---|
| 244 | 244 | struct sockaddr_storage addr; |
|---|
| 245 | 245 | socklen_t len = sizeof (addr); |
|---|
| … | … | |
| 252 | 252 | |
|---|
| 253 | 253 | i_answer = vlc_getnameinfo( p_this, (struct sockaddr *)&addr, len, |
|---|
| 254 | | hostaddr, sizeof( hostaddr ), NULL, 0, |
|---|
| | 254 | hostaddr, sizeof( hostaddr ), NULL, |
|---|
| 255 | 255 | NI_NUMERICHOST ); |
|---|
| 256 | 256 | if( i_answer ) |
|---|
| rc903b7d |
r7f43266 |
|
| 495 | 495 | |
|---|
| 496 | 496 | int vlc_getnameinfo( vlc_object_t *p_this, const struct sockaddr *sa, int salen, |
|---|
| 497 | | char *host, int hostlen, char *serv, int servlen, int flags ) |
|---|
| 498 | | { |
|---|
| | 497 | char *host, int hostlen, int *portnum, int flags ) |
|---|
| | 498 | { |
|---|
| | 499 | char psz_servbuf[6], *psz_serv; |
|---|
| | 500 | int i_servlen, i_val; |
|---|
| | 501 | |
|---|
| | 502 | flags |= NI_NUMERICSERV; |
|---|
| | 503 | if( portnum != NULL ) |
|---|
| | 504 | { |
|---|
| | 505 | psz_serv = psz_servbuf; |
|---|
| | 506 | i_servlen = sizeof( psz_servbuf ); |
|---|
| | 507 | } |
|---|
| | 508 | else |
|---|
| | 509 | { |
|---|
| | 510 | psz_serv = NULL; |
|---|
| | 511 | i_servlen = 0; |
|---|
| | 512 | } |
|---|
| 499 | 513 | #ifdef WIN32 |
|---|
| 500 | 514 | /* |
|---|
| … | … | |
| 515 | 529 | if( ws2_getnameinfo != NULL ) |
|---|
| 516 | 530 | { |
|---|
| 517 | | int i_val; |
|---|
| 518 | | |
|---|
| 519 | | i_val = ws2_getnameinfo( sa, salen, host, hostlen, serv, servlen, |
|---|
| 520 | | flags ); |
|---|
| | 531 | i_val = ws2_getnameinfo( sa, salen, host, hostlen, psz_serv, |
|---|
| | 532 | i_servlen, flags ); |
|---|
| 521 | 533 | FreeLibrary( wship6_module ); |
|---|
| | 534 | |
|---|
| | 535 | if( portnum != NULL ) |
|---|
| | 536 | *portnum = atoi( psz_serv ); |
|---|
| 522 | 537 | return i_val; |
|---|
| 523 | 538 | } |
|---|
| … | … | |
| 527 | 542 | #endif |
|---|
| 528 | 543 | #if HAVE_GETNAMEINFO |
|---|
| 529 | | return getnameinfo( sa, salen, host, hostlen, serv, servlen, flags ); |
|---|
| | 544 | i_val = getnameinfo( sa, salen, host, hostlen, psz_serv, i_servlen, |
|---|
| | 545 | flags ); |
|---|
| 530 | 546 | #else |
|---|
| 531 | | { |
|---|
| 532 | | vlc_value_t lock; |
|---|
| 533 | | int i_val; |
|---|
| 534 | | |
|---|
| 535 | | /* my getnameinfo implementation is not thread-safe as it uses |
|---|
| 536 | | * gethostbyaddr and the likes */ |
|---|
| 537 | | var_Create( p_this->p_libvlc, "getnameinfo_mutex", VLC_VAR_MUTEX ); |
|---|
| 538 | | var_Get( p_this->p_libvlc, "getnameinfo_mutex", &lock ); |
|---|
| 539 | | vlc_mutex_lock( lock.p_address ); |
|---|
| 540 | | |
|---|
| 541 | | i_val = __getnameinfo( sa, salen, host, hostlen, serv, servlen, flags ); |
|---|
| 542 | | vlc_mutex_unlock( lock.p_address ); |
|---|
| | 547 | { |
|---|
| | 548 | vlc_value_t lock; |
|---|
| | 549 | |
|---|
| | 550 | /* my getnameinfo implementation is not thread-safe as it uses |
|---|
| | 551 | * gethostbyaddr and the likes */ |
|---|
| | 552 | var_Create( p_this->p_libvlc, "getnameinfo_mutex", VLC_VAR_MUTEX ); |
|---|
| | 553 | var_Get( p_this->p_libvlc, "getnameinfo_mutex", &lock ); |
|---|
| | 554 | vlc_mutex_lock( lock.p_address ); |
|---|
| | 555 | |
|---|
| | 556 | i_val = __getnameinfo( sa, salen, host, hostlen, psz_serv, i_servlen, |
|---|
| | 557 | flags ); |
|---|
| | 558 | vlc_mutex_unlock( lock.p_address ); |
|---|
| | 559 | } |
|---|
| | 560 | #endif |
|---|
| | 561 | |
|---|
| | 562 | if( portnum != NULL ) |
|---|
| | 563 | *portnum = atoi( psz_serv ); |
|---|
| | 564 | |
|---|
| 543 | 565 | return i_val; |
|---|
| 544 | | } |
|---|
| 545 | | #endif |
|---|
| 546 | 566 | } |
|---|
| 547 | 567 | |
|---|
| … | … | |
| 549 | 569 | /* TODO: support for setting sin6_scope_id */ |
|---|
| 550 | 570 | int vlc_getaddrinfo( vlc_object_t *p_this, const char *node, |
|---|
| 551 | | const char *service, const struct addrinfo *p_hints, |
|---|
| | 571 | int i_port, const struct addrinfo *p_hints, |
|---|
| 552 | 572 | struct addrinfo **res ) |
|---|
| 553 | 573 | { |
|---|
| 554 | 574 | struct addrinfo hints; |
|---|
| 555 | | char psz_buf[NI_MAXHOST], *psz_node; |
|---|
| | 575 | char psz_buf[NI_MAXHOST], *psz_node, psz_service[6]; |
|---|
| | 576 | |
|---|
| | 577 | /* |
|---|
| | 578 | * In VLC, we always use port number as integer rather than strings |
|---|
| | 579 | * for historical reasons (and portability). |
|---|
| | 580 | */ |
|---|
| | 581 | if( ( i_port > 65535 ) || ( i_port < 0 ) ) |
|---|
| | 582 | { |
|---|
| | 583 | msg_Err( p_this, "invalid port number %d specified", i_port ); |
|---|
| | 584 | return EAI_SERVICE; |
|---|
| | 585 | } |
|---|
| | 586 | |
|---|
| | 587 | /* cannot overflow */ |
|---|
| | 588 | snprintf( psz_service, 6, "%d", i_port ); |
|---|
| 556 | 589 | |
|---|
| 557 | 590 | /* Check if we have to force ipv4 or ipv6 */ |
|---|
| … | … | |
| 586 | 619 | { |
|---|
| 587 | 620 | psz_node = NULL; |
|---|
| 588 | | if( service == NULL ) |
|---|
| 589 | | service = ""; |
|---|
| 590 | 621 | } |
|---|
| 591 | 622 | else |
|---|
| … | … | |
| 608 | 639 | } |
|---|
| 609 | 640 | } |
|---|
| 610 | | |
|---|
| 611 | | if( ( service != NULL ) && ( *service == '\0' ) ) |
|---|
| 612 | | /* We could put NULL, but you can't have both node and service NULL */ |
|---|
| 613 | | service = "0"; |
|---|
| 614 | 641 | |
|---|
| 615 | 642 | #ifdef WIN32 |
|---|
| … | … | |
| 641 | 668 | #endif |
|---|
| 642 | 669 | #if HAVE_GETADDRINFO |
|---|
| 643 | | return getaddrinfo( psz_node, service, &hints, res ); |
|---|
| | 670 | return getaddrinfo( psz_node, psz_service, &hints, res ); |
|---|
| 644 | 671 | #else |
|---|
| 645 | 672 | { |
|---|
| r6eeb0d1 |
r7f43266 |
|
| 86 | 86 | struct addrinfo hints, *res, *ptr; |
|---|
| 87 | 87 | const char *psz_realhost; |
|---|
| 88 | | char *psz_realport, *psz_socks; |
|---|
| 89 | | int i_val, i_handle = -1; |
|---|
| 90 | | |
|---|
| 91 | | if( ( i_port < 0 ) || ( i_port > 65535 ) ) |
|---|
| 92 | | return -1; /* I don't expect the next TCP version shortly */ |
|---|
| | 88 | char *psz_socks; |
|---|
| | 89 | int i_realport, i_val, i_handle = -1; |
|---|
| | 90 | |
|---|
| 93 | 91 | if( i_port == 0 ) |
|---|
| 94 | 92 | i_port = 80; /* historical VLC thing */ |
|---|
| … | … | |
| 106 | 104 | |
|---|
| 107 | 105 | psz_realhost = psz_socks; |
|---|
| 108 | | psz_realport = strdup( ( psz != NULL ) ? psz : "1080" ); |
|---|
| 109 | | |
|---|
| 110 | | msg_Dbg( p_this, "net: connecting to '%s:%s' for '%s:%d'", |
|---|
| 111 | | psz_realhost, psz_realport, psz_host, i_port ); |
|---|
| | 106 | i_realport = ( psz != NULL ) ? atoi( psz ) : 1080; |
|---|
| | 107 | |
|---|
| | 108 | msg_Dbg( p_this, "net: connecting to '%s:%d' for '%s:%d'", |
|---|
| | 109 | psz_realhost, i_realport, psz_host, i_port ); |
|---|
| 112 | 110 | } |
|---|
| 113 | 111 | else |
|---|
| 114 | 112 | { |
|---|
| 115 | 113 | psz_realhost = psz_host; |
|---|
| 116 | | psz_realport = malloc( 6 ); |
|---|
| 117 | | if( psz_realport == NULL ) |
|---|
| 118 | | { |
|---|
| 119 | | free( psz_socks ); |
|---|
| 120 | | return -1; |
|---|
| 121 | | } |
|---|
| 122 | | |
|---|
| 123 | | sprintf( psz_realport, "%d", i_port ); |
|---|
| 124 | | msg_Dbg( p_this, "net: connecting to '%s:%s'", psz_realhost, |
|---|
| 125 | | psz_realport ); |
|---|
| 126 | | } |
|---|
| 127 | | |
|---|
| 128 | | i_val = vlc_getaddrinfo( p_this, psz_realhost, psz_realport, &hints, |
|---|
| 129 | | &res ); |
|---|
| 130 | | free( psz_realport ); |
|---|
| | 114 | i_realport = i_port; |
|---|
| | 115 | |
|---|
| | 116 | msg_Dbg( p_this, "net: connecting to '%s:%d'", psz_realhost, |
|---|
| | 117 | i_realport ); |
|---|
| | 118 | } |
|---|
| | 119 | |
|---|
| | 120 | i_val = vlc_getaddrinfo( p_this, psz_realhost, i_realport, &hints, &res ); |
|---|
| 131 | 121 | if( i_val ) |
|---|
| 132 | 122 | { |
|---|
| 133 | | msg_Err( p_this, "cannot resolve '%s' : %s", psz_realhost, |
|---|
| 134 | | vlc_gai_strerror( i_val ) ); |
|---|
| | 123 | msg_Err( p_this, "cannot resolve '%s:%d' : %s", psz_realhost, |
|---|
| | 124 | i_realport, vlc_gai_strerror( i_val ) ); |
|---|
| 135 | 125 | free( psz_socks ); |
|---|
| 136 | 126 | return -1; |
|---|
| … | … | |
| 323 | 313 | struct addrinfo hints, *res, *ptr; |
|---|
| 324 | 314 | int i_val, *pi_handles, i_size; |
|---|
| 325 | | char *psz_port; |
|---|
| 326 | | |
|---|
| 327 | | if( ( i_port < 0 ) || ( i_port > 65535 ) ) |
|---|
| 328 | | return NULL; /* I don't expect the next TCP version shortly */ |
|---|
| 329 | | if( i_port == 0 ) |
|---|
| 330 | | i_port = 80; /* historical VLC thing */ |
|---|
| 331 | 315 | |
|---|
| 332 | 316 | memset( &hints, 0, sizeof( hints ) ); |
|---|
| … | … | |
| 334 | 318 | hints.ai_flags = AI_PASSIVE; |
|---|
| 335 | 319 | |
|---|
| 336 | | psz_port = malloc( 6 ); |
|---|
| 337 | | if( psz_port == NULL ) |
|---|
| 338 | | return NULL; |
|---|
| 339 | | |
|---|
| 340 | | sprintf( psz_port, "%d", i_port ); |
|---|
| 341 | | msg_Dbg( p_this, "net: listening to '%s:%s'", psz_host, psz_port ); |
|---|
| 342 | | |
|---|
| 343 | | i_val = vlc_getaddrinfo( p_this, psz_host, psz_port, &hints, &res ); |
|---|
| 344 | | free( psz_port ); |
|---|
| | 320 | msg_Dbg( p_this, "net: listening to '%s:%d'", psz_host, i_port ); |
|---|
| | 321 | |
|---|
| | 322 | i_val = vlc_getaddrinfo( p_this, psz_host, i_port, &hints, &res ); |
|---|
| 345 | 323 | if( i_val ) |
|---|
| 346 | 324 | { |
|---|
| 347 | | msg_Err( p_this, "cannot resolve '%s' : %s", psz_host, |
|---|
| | 325 | msg_Err( p_this, "cannot resolve '%s:%d' : %s", psz_host, i_port, |
|---|
| 348 | 326 | vlc_gai_strerror( i_val ) ); |
|---|
| 349 | 327 | return NULL; |
|---|
| … | … | |
| 1111 | 1089 | /* v4 only support ipv4 */ |
|---|
| 1112 | 1090 | hints.ai_family = PF_INET; |
|---|
| 1113 | | if( vlc_getaddrinfo( p_obj, psz_host, NULL, &hints, &p_res ) ) |
|---|
| | 1091 | if( vlc_getaddrinfo( p_obj, psz_host, 0, &hints, &p_res ) ) |
|---|
| 1114 | 1092 | return VLC_EGENERIC; |
|---|
| 1115 | 1093 | |
|---|
| r70702c3 |
r7f43266 |
|
| 296 | 296 | hints.ai_flags = AI_NUMERICHOST; |
|---|
| 297 | 297 | |
|---|
| 298 | | i = vlc_getaddrinfo( (vlc_object_t *)p_sap, p_session->psz_uri, NULL, |
|---|
| | 298 | i = vlc_getaddrinfo( (vlc_object_t *)p_sap, p_session->psz_uri, 0, |
|---|
| 299 | 299 | &hints, &res ); |
|---|
| 300 | 300 | if( i == 0 ) |
|---|
| 301 | 301 | i = vlc_getnameinfo( (vlc_object_t *)p_sap, res->ai_addr, |
|---|
| 302 | 302 | res->ai_addrlen, psz_buf, sizeof( psz_buf ), |
|---|
| 303 | | NULL, 0, NI_NUMERICHOST ); |
|---|
| | 303 | NULL, NI_NUMERICHOST ); |
|---|
| 304 | 304 | if( i ) |
|---|
| 305 | 305 | { |
|---|
| … | … | |
| 585 | 585 | int64_t i_sdp_id = mdate(); |
|---|
| 586 | 586 | int i_sdp_version = 1 + p_sap->i_sessions + (rand()&0xfff); |
|---|
| 587 | | char *psz_group, *psz_name, psz_uribuf[48], *psz_uri; |
|---|
| | 587 | char *psz_group, *psz_name, psz_uribuf[NI_MAXNUMERICHOST], *psz_uri; |
|---|
| 588 | 588 | char ipv; |
|---|
| 589 | 589 | |
|---|