diff -ru streamripper-1.60.5/console/streamripper.c streamripper-1.60.5.interface/console/streamripper.c --- streamripper-1.60.5/console/streamripper.c 2004-04-20 23:33:42.000000000 +0200 +++ streamripper-1.60.5.interface/console/streamripper.c 2004-05-04 00:30:29.867344272 +0200 @@ -222,6 +222,8 @@ fprintf(stderr, " -a - Rip to single file, default name is timestamped\n"); fprintf(stderr, " -d - The destination directory\n"); fprintf(stderr, " -s - Don't create a directory for each stream\n"); + fprintf(stderr, " -I - Use the specified interface for stream\n"); + fprintf(stderr, " -R - Use the specified interface for relay\n"); fprintf(stderr, " -r - Create relay server on base port, default port 8000\n"); fprintf(stderr, " -z - Don't scan for free ports if base port is not avail\n"); fprintf(stderr, " -p - Use HTTP proxy server at \n"); @@ -296,6 +298,14 @@ case 'i': m_opt.flags ^= OPT_ADD_ID3; break; + case 'I': + i++; + strncpy(m_opt.stream_interface, argv[i], MAX_PATH_LEN); + break; + case 'R': + i++; + strncpy(m_opt.relay_interface, argv[i], MAX_PATH_LEN); + break; case 'l': i++; time(&m_stop_time); Only in streamripper-1.60.5.interface/console: streamripper.c~ diff -ru streamripper-1.60.5/lib/inet.c streamripper-1.60.5.interface/lib/inet.c --- streamripper-1.60.5/lib/inet.c 2002-05-22 04:10:18.000000000 +0200 +++ streamripper-1.60.5.interface/lib/inet.c 2004-05-04 00:07:26.961577904 +0200 @@ -31,7 +31,7 @@ error_code inet_get_webpage_alloc(HSOCKET *sock, const char *url, const char *proxyurl, char **buffer, unsigned long *size); error_code inet_sc_connect(HSOCKET *sock, const char *url, const char *proxyurl, - SR_HTTP_HEADER *info, char *useragent); + SR_HTTP_HEADER *info, char *useragent, char *interface); /********************************************************************************* * Private functions @@ -42,7 +42,7 @@ * Connects to a shoutcast type stream, leaves when it's about to get the header info */ error_code inet_sc_connect(HSOCKET *sock, const char *url, const char *proxyurl, - SR_HTTP_HEADER *info, char *useragent) + SR_HTTP_HEADER *info, char *useragent, char *interface) { char headbuf[MAX_HEADER_LEN]; URLINFO url_info; @@ -64,7 +64,7 @@ return ret; DEBUG2(( "calling sock_open: host=%s, port=%d\n", url_info.host, url_info.port )); - if ((ret = socklib_open(sock, url_info.host, url_info.port)) != SR_SUCCESS) + if ((ret = socklib_open(sock, url_info.host, url_info.port, interface)) != SR_SUCCESS) return ret; DEBUG2(( "calling httplib_construct_sc_request\n" )); @@ -82,7 +82,7 @@ if (*info->http_location) { /* RECURSIVE CASE */ - inet_sc_connect(sock, info->http_location, proxyurl, info, useragent); + inet_sc_connect(sock, info->http_location, proxyurl, info, useragent, interface); } return SR_SUCCESS; @@ -122,7 +122,7 @@ if ((ret = socklib_init()) != SR_SUCCESS) return ret; - if ((ret = socklib_open(sock, url_info.host, url_info.port)) != SR_SUCCESS) + if ((ret = socklib_open(sock, url_info.host, url_info.port, NULL)) != SR_SUCCESS) return ret; if ((ret = httplib_construct_page_request(url, proxyurl != NULL, headbuf)) != SR_SUCCESS) diff -ru streamripper-1.60.5/lib/inet.h streamripper-1.60.5.interface/lib/inet.h --- streamripper-1.60.5/lib/inet.h 2001-12-24 08:33:50.000000000 +0100 +++ streamripper-1.60.5.interface/lib/inet.h 2004-05-04 00:07:26.961577904 +0200 @@ -8,7 +8,7 @@ extern error_code inet_get_webpage_alloc(HSOCKET *sock, const char *url, const char *proxyurl, char **buffer, unsigned long *size); extern error_code inet_sc_connect(HSOCKET *sock, const char *url, - const char *proxyurl, SR_HTTP_HEADER *info, char *useragent); + const char *proxyurl, SR_HTTP_HEADER *info, char *useragent, char *interface); #endif //__INET_H__ diff -ru streamripper-1.60.5/lib/relaylib.c streamripper-1.60.5.interface/lib/relaylib.c --- streamripper-1.60.5/lib/relaylib.c 2002-05-22 04:10:18.000000000 +0200 +++ streamripper-1.60.5.interface/lib/relaylib.c 2004-05-04 00:07:26.961577904 +0200 @@ -23,6 +23,8 @@ #include #include #include +#include +#include #include #include #include @@ -49,18 +51,19 @@ /********************************************************************************* * Public functions *********************************************************************************/ -error_code relaylib_init(BOOL search_ports, int base_port, int max_port, int *port_used); +error_code relaylib_init(BOOL search_ports, int base_port, int max_port, int *port_used, char *interface); void relaylib_shutdown(); error_code relaylib_set_response_header(char *http_header); error_code relaylib_start(); error_code relaylib_send(char *data, int len); BOOL relaylib_isrunning(); +extern error_code read_interface(char *interface, u_int32_t *addr); /********************************************************************************* * Private functions *********************************************************************************/ static void thread_accept(void *notused); -static error_code try_port(u_short port); +static error_code try_port(u_short port, char *interface); /********************************************************************************* @@ -98,7 +101,7 @@ } #endif -error_code relaylib_init(BOOL search_ports, int relay_port, int max_port, int *port_used) +error_code relaylib_init(BOOL search_ports, int relay_port, int max_port, int *port_used, char *interface) { int ret; #ifdef WIN32 @@ -130,7 +133,7 @@ for(;relay_port <= max_port; relay_port++) { - if ((ret = try_port((u_short)relay_port)) == SR_ERROR_CANT_BIND_ON_PORT) + if ((ret = try_port((u_short)relay_port, interface)) == SR_ERROR_CANT_BIND_ON_PORT) continue; // Keep searching. if (ret == SR_SUCCESS) @@ -145,15 +148,16 @@ return SR_ERROR_CANT_BIND_ON_PORT; } -error_code try_port(u_short port) +error_code try_port(u_short port, char *interface) { struct sockaddr_in local; m_listensock = socket(AF_INET, SOCK_STREAM, IPPROTO_IP); if (m_listensock == SOCKET_ERROR) return SR_ERROR_SOCK_BASE; - - local.sin_addr.s_addr = htonl(INADDR_ANY); + + if (read_interface(interface,&local.sin_addr.s_addr) != 0) + local.sin_addr.s_addr = htonl(INADDR_ANY); local.sin_family = AF_INET; local.sin_port = htons(port); diff -ru streamripper-1.60.5/lib/relaylib.h streamripper-1.60.5.interface/lib/relaylib.h --- streamripper-1.60.5/lib/relaylib.h 2001-08-04 07:00:08.000000000 +0200 +++ streamripper-1.60.5.interface/lib/relaylib.h 2004-05-04 00:07:26.961577904 +0200 @@ -3,7 +3,7 @@ #include "types.h" -extern error_code relaylib_init(BOOL search_ports, int relay_port, int max_port, int *port_used); +extern error_code relaylib_init(BOOL search_ports, int relay_port, int max_port, int *port_used, char *interface); extern void relaylib_shutdown(); extern error_code relaylib_set_response_header(char *http_header); extern error_code relaylib_start(); diff -ru streamripper-1.60.5/lib/rip_manager.c streamripper-1.60.5.interface/lib/rip_manager.c --- streamripper-1.60.5/lib/rip_manager.c 2004-04-26 06:47:51.000000000 +0200 +++ streamripper-1.60.5.interface/lib/rip_manager.c 2004-05-04 00:20:54.760773760 +0200 @@ -527,7 +527,7 @@ * Connect to the stream */ ret = inet_sc_connect(&m_sock, m_options.url, pproxy, &m_info, - m_options.useragent); + m_options.useragent, m_options.stream_interface); if (ret != SR_SUCCESS) { goto RETURN_ERR; } @@ -631,7 +631,8 @@ if (GET_MAKE_RELAY(m_options.flags)) { int new_port = 0; ret = relaylib_init(GET_SEARCH_PORTS(m_options.flags), - m_options.relay_port, m_options.max_port, &new_port); + m_options.relay_port, m_options.max_port, &new_port, + m_options.relay_interface); if (ret != SR_SUCCESS) { goto RETURN_ERR; } Only in streamripper-1.60.5.interface/lib: rip_manager.c~ diff -ru streamripper-1.60.5/lib/rip_manager.h streamripper-1.60.5.interface/lib/rip_manager.h --- streamripper-1.60.5/lib/rip_manager.h 2004-04-26 06:47:51.000000000 +0200 +++ streamripper-1.60.5.interface/lib/rip_manager.h 2004-05-04 00:18:06.966282400 +0200 @@ -88,6 +88,8 @@ char proxyurl[MAX_URL_LEN]; // url of a http proxy server, '\0' otherwise char output_directory[MAX_PATH_LEN]; // base directory to output files too char output_file[MAX_PATH_LEN]; // filename base when ripping without splitting + char relay_interface[MAX_PATH_LEN]; // interface to use for relay + char stream_interface[MAX_PATH_LEN]; // interface to use for stream int relay_port; // port to use for the relay server u_short max_port; // highest port the relay server can look if it needs to search u_long maxMB_rip_size; // max number of megabytes that can by writen out before we stop diff -ru streamripper-1.60.5/lib/socklib.c streamripper-1.60.5.interface/lib/socklib.c --- streamripper-1.60.5/lib/socklib.c 2004-03-02 21:33:41.000000000 +0100 +++ streamripper-1.60.5.interface/lib/socklib.c 2004-05-04 00:07:45.324786272 +0200 @@ -29,6 +29,8 @@ #include #include #include +#include +#include #include #include #include @@ -63,7 +65,7 @@ * Public functions *********************************************************************************/ error_code socklib_init(); -error_code socklib_open(HSOCKET *socket_handle, char *host, int port); +error_code socklib_open(HSOCKET *socket_handle, char *host, int port, char *interface); void socklib_close(HSOCKET *socket_handle); void socklib_cleanup(); error_code socklib_read_header(HSOCKET *socket_handle, char *buffer, int size, @@ -72,6 +74,7 @@ int socklib_sendall(HSOCKET *socket_handle, char* buffer, int size); error_code socklib_recvall_alloc(HSOCKET *socket_handle, char** buffer, unsigned long *size, int (*recvall)(HSOCKET *socket_handle, char* buffer, int size)); +error_code read_interface(char *interface, u_int32_t *addr); /********************************************************************************* * Private Vars @@ -110,9 +113,32 @@ * socket_handle gets assigned to the handle for the connection */ -error_code socklib_open(HSOCKET *socket_handle, char *host, int port) +error_code read_interface(char *interface, u_int32_t *addr) { - struct sockaddr_in address; + int fd; + struct ifreq ifr; + + memset(&ifr, 0, sizeof(struct ifreq)); + if((fd = socket(AF_INET, SOCK_DGRAM, 0)) >= 0) { + ifr.ifr_addr.sa_family = AF_INET; + strcpy(ifr.ifr_name, interface); + if (ioctl(fd, SIOCGIFADDR, &ifr) == 0) + *addr = ((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr; + else { + close(fd); + return -2; + } + } else + return -1; + close(fd); + return 0; +} + + +error_code socklib_open(HSOCKET *socket_handle, char *host, int port, + char* interface) +{ + struct sockaddr_in address, local; struct hostent *hp; int len; @@ -121,6 +147,18 @@ DEBUG2(( "creating our socket\n" )); socket_handle->s = socket(AF_INET, SOCK_STREAM, 0); + + if (interface) { + if (read_interface(interface,&local.sin_addr.s_addr) != 0) + local.sin_addr.s_addr = htonl(INADDR_ANY); + local.sin_family = AF_INET; + local.sin_port = 0; + if (bind(socket_handle->s, (struct sockaddr *)&local, sizeof(local)) == SOCKET_ERROR) { + WSACleanup(); + closesocket(socket_handle->s); + return SR_ERROR_CANT_BIND_ON_INTERFACE; + } + } DEBUG2(( "checking hostname\n" )); if ((address.sin_addr.s_addr = inet_addr(host)) == INADDR_NONE) diff -ru streamripper-1.60.5/lib/socklib.h streamripper-1.60.5.interface/lib/socklib.h --- streamripper-1.60.5/lib/socklib.h 2001-08-04 07:00:10.000000000 +0200 +++ streamripper-1.60.5.interface/lib/socklib.h 2004-05-04 00:07:26.962577752 +0200 @@ -15,7 +15,7 @@ extern error_code socklib_init(); -extern error_code socklib_open(HSOCKET *socket_handle, char *host, int port); +extern error_code socklib_open(HSOCKET *socket_handle, char *host, int port, char *interface); extern void socklib_close(HSOCKET *socket_handle); extern void socklib_cleanup(); extern error_code socklib_read_header(HSOCKET *socket_handle, char *buffer, int size, diff -ru streamripper-1.60.5/lib/types.h streamripper-1.60.5.interface/lib/types.h --- streamripper-1.60.5/lib/types.h 2004-04-17 22:53:54.000000000 +0200 +++ streamripper-1.60.5.interface/lib/types.h 2004-05-04 00:07:26.962577752 +0200 @@ -144,6 +144,7 @@ #define SR_ERROR_NO_TRACK_INFO - 0x1D #define SR_EEROR_CANT_FIND_SUBSTR - 0x1E #define SR_ERROR_CANT_BIND_ON_PORT - 0x1F +#define SR_ERROR_CANT_BIND_ON_INTERFACE - 0x40 #define SR_ERROR_HOST_NOT_CONNECTED - 0x20 #define SR_ERROR_HTTP_404_ERROR - 0x21 #define SR_ERROR_HTTP_401_ERROR - 0x22 Only in streamripper-1.60.5/libmad-0.15.1b: mad.h diff -ru streamripper-1.60.5/streamripper.1 streamripper-1.60.5.interface/streamripper.1 --- streamripper-1.60.5/streamripper.1 2004-03-22 16:37:18.000000000 +0100 +++ streamripper-1.60.5.interface/streamripper.1 2004-05-04 00:22:14.662626832 +0200 @@ -38,6 +38,10 @@ add sequence number to output file .IP "\fB\-i\fR" 4 dont add ID3V1 Tags to output file +.IP "\fB\-I \fR" 4 +bind stream socket to the specified interface +.IP "\fB\-R \fR" 4 +bind relay server socket to the specified interface .IP "\fB\-u \fR" 4 Use a different UserAgent then "Streamripper" .IP "\fB\-\-x\fR" 4 Only in streamripper-1.60.5.interface/: streamripper.1~