jack_netsource : fix crash when hostname is unknown.
[jack2.git] / example-clients / ipunload.c
blobbaedfc1e518b24b1e4b320a1ed3eaf6a1ef771d5
1 /*
2 This program is free software; you can redistribute it and/or modify
3 it under the terms of the GNU General Public License as published by
4 the Free Software Foundation; either version 2 of the License, or
5 (at your option) any later version.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 GNU General Public License for more details.
12 You should have received a copy of the GNU General Public License
13 along with this program; if not, write to the Free Software
14 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 #include <string.h>
18 #include <stdlib.h>
19 #include <stdio.h>
20 #include <jack/jack.h>
21 #include <jack/intclient.h>
23 int
24 main (int argc, char *argv[])
26 char *my_name;
27 char *client_name;
28 jack_client_t *client;
29 jack_status_t status;
30 jack_intclient_t intclient;
32 /* validate args */
33 if ((argc < 2) || (argc > 3)) {
34 fprintf (stderr, "usage: %s client-name [ server-name ]]\n",
35 argv[0]);
36 return 1;
39 /* use `basename $0` for my own client name */
40 my_name = strrchr(argv[0], '/');
41 if (my_name == 0) {
42 my_name = argv[0];
43 } else {
44 my_name++;
47 /* first, become a JACK client */
48 if (argc > 2) {
49 client = jack_client_open (my_name,
50 (JackServerName|JackNoStartServer),
51 &status, argv[2]);
52 } else {
53 client = jack_client_open (my_name, JackNoStartServer, &status);
56 if (client == NULL) {
57 if (status & JackServerFailed) {
58 fprintf (stderr, "JACK server not running.\n");
59 } else {
60 fprintf (stderr, "JACK open failed, "
61 "status = 0x%2.0x\n", status);
63 exit (1);
66 /* then, get the internal client handle */
67 client_name = argv[1];
68 intclient = jack_internal_client_handle (client, client_name, &status);
69 if (status & JackFailure) {
70 fprintf (stderr, "client %s not found.\n", client_name);
71 exit (2);
74 /* now, unload the internal client */
75 status = jack_internal_client_unload (client, intclient);
76 if (status & JackFailure) {
77 if (status & JackNoSuchClient) {
78 fprintf (stderr, "client %s is gone.\n",
79 client_name);
80 } else {
81 fprintf (stderr, "could not unload %s, "
82 "returns 0x%2.0x\n", client_name, status);
84 exit (3);
85 } else {
86 fprintf (stdout, "%s unloaded.\n", client_name);
89 jack_client_close(client);
90 return 0;