| 1 |
/* Hey EMACS -*- linux-c -*- */ |
| 2 |
|
| 3 |
/* libticables2 - link cable library, a part of the TiLP project |
| 4 |
* Copyright (C) 2015 Lionel Debroux |
| 5 |
* |
| 6 |
* This program is free software; you can redistribute it and/or modify |
| 7 |
* it under the terms of the GNU General Public License as published by |
| 8 |
* the Free Software Foundation; either version 2 of the License, or |
| 9 |
* (at your option) any later version. |
| 10 |
* |
| 11 |
* This program is distributed in the hope that it will be useful, |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
* GNU General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU General Public License |
| 17 |
* along with this program; if not, write to the Free Software Foundation, |
| 18 |
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 19 |
*/ |
| 20 |
|
| 21 |
/* TCP server virtual link cable unit */ |
| 22 |
|
| 23 |
/* |
| 24 |
* This unit uses a TCP socket between 2 programs which use this lib. |
| 25 |
*/ |
| 26 |
|
| 27 |
#ifdef HAVE_CONFIG_H |
| 28 |
#include <config.h> |
| 29 |
#endif |
| 30 |
|
| 31 |
#include <stdio.h> |
| 32 |
#include <stdlib.h> |
| 33 |
#include <string.h> |
| 34 |
|
| 35 |
#include <fcntl.h> |
| 36 |
#include <unistd.h> |
| 37 |
#include <sys/types.h> |
| 38 |
#include <sys/stat.h> |
| 39 |
#include <sys/ipc.h> |
| 40 |
#include <sys/socket.h> |
| 41 |
#include <errno.h> |
| 42 |
|
| 43 |
#include "../ticables.h" |
| 44 |
#include "../logging.h" |
| 45 |
#include "../error.h" |
| 46 |
#include "../gettext.h" |
| 47 |
#include "../internal.h" |
| 48 |
#include "detect.h" |
| 49 |
|
| 50 |
static int tcps_prepare(CableHandle *h) |
| 51 |
{ |
| 52 |
return 0; |
| 53 |
} |
| 54 |
|
| 55 |
static int tcps_open(CableHandle *h) |
| 56 |
{ |
| 57 |
return 0; |
| 58 |
} |
| 59 |
|
| 60 |
static int tcps_close(CableHandle *h) |
| 61 |
{ |
| 62 |
return 0; |
| 63 |
} |
| 64 |
|
| 65 |
static int tcps_reset(CableHandle *h) |
| 66 |
{ |
| 67 |
return 0; |
| 68 |
} |
| 69 |
|
| 70 |
static int tcps_probe(CableHandle *h) |
| 71 |
{ |
| 72 |
return 0; |
| 73 |
} |
| 74 |
|
| 75 |
static int tcps_put(CableHandle *h, uint8_t *data, uint32_t len) |
| 76 |
{ |
| 77 |
return 0; |
| 78 |
} |
| 79 |
|
| 80 |
static int tcps_get(CableHandle *h, uint8_t *data, uint32_t len) |
| 81 |
{ |
| 82 |
return 0; |
| 83 |
} |
| 84 |
|
| 85 |
static int tcps_check(CableHandle *h, int *status) |
| 86 |
{ |
| 87 |
return 0; |
| 88 |
} |
| 89 |
|
| 90 |
static int tcps_set_device(CableHandle *h, const char * device) |
| 91 |
{ |
| 92 |
if (device != NULL) |
| 93 |
{ |
| 94 |
char * device2 = strdup(device); |
| 95 |
if (device2 != NULL) |
| 96 |
{ |
| 97 |
free(h->device); |
| 98 |
h->device = device2; |
| 99 |
} |
| 100 |
else |
| 101 |
{ |
| 102 |
ticables_warning(_("unable to set device %s.\n"), device); |
| 103 |
} |
| 104 |
return 0; |
| 105 |
} |
| 106 |
return ERR_ILLEGAL_ARG; |
| 107 |
} |
| 108 |
|
| 109 |
extern const CableFncts cable_tcps = |
| 110 |
{ |
| 111 |
CABLE_TCPS, |
| 112 |
"TCPS", |
| 113 |
N_("TCPS"), |
| 114 |
N_("Virtual TCP server link"), |
| 115 |
0, |
| 116 |
&tcps_prepare, |
| 117 |
&tcps_open, &tcps_close, &tcps_reset, &tcps_probe, NULL, |
| 118 |
&tcps_put, &tcps_get, &tcps_check, |
| 119 |
&noop_set_red_wire, &noop_set_white_wire, |
| 120 |
&noop_get_red_wire, &noop_get_white_wire, |
| 121 |
NULL, NULL, |
| 122 |
&tcps_set_device, |
| 123 |
NULL |
| 124 |
}; |