etrax should not select foxboard-utils by default as the package is now in the packag...
[openwrt.git] / package / fonera-mp3 / src / cli / main_tcp.c
1 /*
2 * FOXMP3
3 * Copyright (c) 2006 acmesystems.it - john@acmesystems.it
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA
18 *
19 * Feedback, Bugs... info@acmesystems.it
20 *
21 */
22
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <unistd.h>
26 #include <errno.h>
27 #include <string.h>
28 #include <netdb.h>
29 #include <sys/types.h>
30 #include <netinet/in.h>
31 #include <sys/socket.h>
32
33 #define SOCKET_PORT 369
34
35
36 void print_usage(void){
37 printf("mp3_play_tcp IP COMANND PARAMETERS\n");
38 printf(" Commands :\n");
39 printf(" PLAY filename\n");
40 printf(" STREAM url [URL OF STREAM]\n");
41 printf(" STREAM pls [URL PLS FILE]\n");
42 printf(" VOLUME [0-255]\n");
43 printf(" STOP\n");
44 printf(" STATE\n");
45 printf(" BASS [0-255]\n");
46 }
47
48 void issue_command(unsigned char *str, unsigned char *ip){
49 int s, t, len;
50 struct sockaddr_in remote;
51 struct hostent *he;
52
53 if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
54 perror("socket");
55 exit(1);
56 }
57
58 printf("Connecting to FOXMP3 on IP/DNS : %s ...\n", ip);
59 if((he=gethostbyname(ip)) == NULL) {
60 herror("gethostbyname");
61 exit(1);
62 }
63 if ((s = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
64 perror("socket");
65 exit(1);
66 }
67 remote.sin_family = AF_INET;
68 remote.sin_port = htons(SOCKET_PORT);
69 remote.sin_addr = *((struct in_addr *)he->h_addr);
70 memset(&(remote.sin_zero), '\0', 8);
71
72 if (connect(s, (struct sockaddr *)&remote,
73 sizeof(struct sockaddr)) == -1) {
74 perror("connect");
75 exit(1);
76 }
77 printf("Connected ...\n\nSending command -> \n%s\n\n", str);
78 if (send(s, str, strlen(str), 0) == -1) {
79 perror("send");
80 exit(1);
81 }
82 if ((t=recv(s, str, 2048, 0)) > 0) {
83 str[t] = '\0';
84 printf("The answer was -> \n%s\n", str);
85 } else {
86 if (t < 0){
87 perror("recv");
88 } else {
89 printf("Server closed connection\n");
90 };
91 exit(1);
92 }
93 close(s);
94 }
95
96 int main(int argc, char **argv){
97 unsigned char buffer[2048];
98 buffer[0] = '\0';
99 if(argc > 2){
100 if(((!strcmp(argv[2], "STOP")) || (!strcmp(argv[2], "STATE")))
101 && (argc == 3)){
102 sprintf(buffer, "%s", argv[2]);
103 } else if(((!strcmp(argv[2], "PLAY")) || (!strcmp(argv[2], "VOLUME"))
104 || (!strcmp(argv[2], "BASS"))) && (argc == 4)){
105 sprintf(buffer, "%s %s", argv[2], argv[3]);
106 } else if((!strcmp(argv[2], "STREAM")) && (argc == 5)
107 && ((!strcmp(argv[3], "url")) || (!strcmp(argv[3], "pls")))){
108 sprintf(buffer, "%s %s %s", argv[2], argv[3],
109 argv[4]);
110 }
111 };
112 if(buffer[0] != '\0'){
113 issue_command(buffer, argv[1]);
114 } else {
115 print_usage();
116 };
117 return 0;
118 }
This page took 0.061929 seconds and 5 git commands to generate.