GDB (xrefs)
Loading...
Searching...
No Matches
ser-uds.c
Go to the documentation of this file.
1/* Serial interface for local domain connections on Un*x like systems.
2
3 Copyright (C) 1992-2023 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20#include "defs.h"
21#include "serial.h"
22#include "ser-base.h"
23
24#include <sys/socket.h>
25#include <sys/un.h>
26
27#ifndef UNIX_PATH_MAX
28#define UNIX_PATH_MAX sizeof(((struct sockaddr_un *) NULL)->sun_path)
29#endif
30
31/* Open an AF_UNIX socket. */
32
33static int
34uds_open (struct serial *scb, const char *name)
35{
36 struct sockaddr_un addr;
37
38 if (strlen (name) > UNIX_PATH_MAX - 1)
39 {
40 warning
41 (_("The socket name is too long. It may be no longer than %s bytes."),
42 pulongest (UNIX_PATH_MAX - 1L));
43 return -1;
44 }
45
46 memset (&addr, 0, sizeof addr);
47 addr.sun_family = AF_UNIX;
48 strncpy (addr.sun_path, name, UNIX_PATH_MAX - 1);
49
50 int sock = socket (AF_UNIX, SOCK_STREAM, 0);
51
52 if (connect (sock, (struct sockaddr *) &addr,
53 sizeof (struct sockaddr_un)) < 0)
54 {
55 close (sock);
56 scb->fd = -1;
57 return -1;
58 }
59
60 scb->fd = sock;
61
62 return 0;
63}
64
65static void
66uds_close (struct serial *scb)
67{
68 if (scb->fd == -1)
69 return;
70
71 close (scb->fd);
72 scb->fd = -1;
73}
74
75static int
76uds_read_prim (struct serial *scb, size_t count)
77{
78 return recv (scb->fd, scb->buf, count, 0);
79}
80
81static int
82uds_write_prim (struct serial *scb, const void *buf, size_t count)
83{
84 return send (scb->fd, buf, count, 0);
85}
86
87/* The local socket ops. */
88
113
115void
const char *const name
void ser_base_async(struct serial *scb, int async_p)
Definition ser-base.c:587
void ser_base_print_tty_state(struct serial *scb, serial_ttystate ttystate, struct ui_file *stream)
Definition ser-base.c:556
void ser_base_raw(struct serial *scb)
Definition ser-base.c:530
int ser_base_set_tty_state(struct serial *scb, serial_ttystate ttystate)
Definition ser-base.c:550
serial_ttystate ser_base_get_tty_state(struct serial *scb)
Definition ser-base.c:536
int ser_base_drain_output(struct serial *scb)
Definition ser-base.c:524
int ser_base_send_break(struct serial *scb)
Definition ser-base.c:518
int ser_base_setbaudrate(struct serial *scb, int rate)
Definition ser-base.c:565
serial_ttystate ser_base_copy_tty_state(struct serial *scb, serial_ttystate ttystate)
Definition ser-base.c:543
int ser_base_write(struct serial *scb, const void *buf, size_t count)
Definition ser-base.c:475
int ser_base_setstopbits(struct serial *scb, int num)
Definition ser-base.c:571
int ser_base_flush_output(struct serial *scb)
Definition ser-base.c:499
int ser_base_flush_input(struct serial *scb)
Definition ser-base.c:505
int ser_base_readchar(struct serial *scb, int timeout)
Definition ser-base.c:469
int ser_base_setparity(struct serial *scb, int parity)
Definition ser-base.c:579
static int uds_open(struct serial *scb, const char *name)
Definition ser-uds.c:34
static int uds_read_prim(struct serial *scb, size_t count)
Definition ser-uds.c:76
static const struct serial_ops uds_ops
Definition ser-uds.c:89
static int uds_write_prim(struct serial *scb, const void *buf, size_t count)
Definition ser-uds.c:82
#define UNIX_PATH_MAX
Definition ser-uds.c:28
void _initialize_ser_socket()
Definition ser-uds.c:116
static void uds_close(struct serial *scb)
Definition ser-uds.c:66
void serial_add_interface(const struct serial_ops *optable)
Definition serial.c:154
int fd
Definition serial.h:238
unsigned char buf[BUFSIZ]
Definition serial.h:250