From: "Ryan Brown" <ribrdb@google.com>
To: gdb-patches@sources.redhat.com
Subject: support remote connections over unix domain sockets
Date: Tue, 25 Apr 2006 23:53:00 -0000 [thread overview]
Message-ID: <6605dfe70604251653s4dae04e7i721e6b8630afd3c0@mail.google.com> (raw)
This patch modifies net_open in ser-tcp.c to connect to a remote
target named unix:/foo/bar via the unix domain socket /foo/bar.
2006-04-25 Ryan Brown <ribrdb@google.com >
* ser-tcp.c (net_open): Add support for unix domain sockets.
Index: gdb/ser-tcp.c
==============================
=====================================
RCS file: /cvs/src/src/gdb/ser- tcp.c,v
retrieving revision 1.26
diff -c -p -r1.26 ser-tcp.c
*** gdb/ser-tcp.c 10 Feb 2006 22:01:43 -0000 1.26
--- gdb/ser-tcp.c 25 Apr 2006 23:28:42 -0000
***************
*** 47,52 ****
--- 47,53 ----
#include <netdb.h>
#include <sys/socket.h>
#include <netinet/tcp.h>
+ #include <sys/un.h>
#endif
#include <signal.h>
*************** net_open (struct serial *scb, const char
*** 70,78 ****
{
char *port_str, hostname[100];
int n, port, tmp;
! int use_udp;
struct hostent *hostent;
- struct sockaddr_in sockaddr;
#ifdef USE_WIN32API
u_long ioarg;
#else
--- 71,78 ----
{
char *port_str, hostname[100];
int n, port, tmp;
! int use_udp, use_unix;
struct hostent *hostent;
#ifdef USE_WIN32API
u_long ioarg;
#else
*************** net_open (struct serial *scb, const char
*** 80,134 ****
#endif
use_udp = 0;
if (strncmp (name, "udp:", 4) == 0)
{
use_udp = 1;
name = name + 4;
}
else if (strncmp (name, "tcp:", 4) == 0)
name = name + 4;
! port_str = strchr (name, ':');
! if (!port_str)
! error (_("net_open: No colon in host name!")); /*
Shouldn't ever happen */
! tmp = min (port_str - name, (int) sizeof hostname - 1);
! strncpy (hostname, name, tmp); /* Don't want colon */
! hostname[tmp] = '\000'; /* Tie off host name */
! port = atoi (port_str + 1);
! /* default hostname is localhost */
! if (!hostname[0])
! strcpy (hostname, "localhost");
! hostent = gethostbyname (hostname);
! if (!hostent)
! {
! fprintf_unfiltered (gdb_stderr, "%s: unknown host\n", hostname);
! errno = ENOENT;
! return -1;
}
-
- if (use_udp)
- scb->fd = socket (PF_INET, SOCK_DGRAM, 0);
- else
- scb->fd = socket (PF_INET, SOCK_STREAM, 0);
-
if (scb->fd < 0)
return -1;
- sockaddr.sin_family = PF_INET;
- sockaddr.sin_port = htons (port);
- memcpy (&sockaddr.sin_addr.s_addr, hostent->h_addr,
- sizeof (struct in_addr));
-
/* set socket nonblocking */
ioarg = 1;
ioctl (scb->fd, FIONBIO, &ioarg);
/* Use Non-blocking connect. connect() will return 0 if connected
already. */
! n = connect (scb->fd, (struct sockaddr *) &sockaddr, sizeof (sockaddr));
if (n < 0
#ifdef USE_WIN32API
--- 80,162 ----
#endif
use_udp = 0;
+ use_unix = 0;
if (strncmp (name, "udp:", 4) == 0)
{
use_udp = 1;
name = name + 4;
}
+ else if (strncmp (name, "unix:", 5) == 0)
+ {
+ use_unix = 1;
+ name = name + 5;
+ }
else if (strncmp (name, "tcp:", 4) == 0)
name = name + 4;
! if (use_unix)
! {
! scb->fd = socket (AF_UNIX, SOCK_STREAM, 0);
! port = 0;
! hostent = 0;
! }
! else
! {
! port_str = strchr (name, ':');
! if (!port_str)
! error (_("net_open: No colon in host name!")); /*
Shouldn't ever happen */
! tmp = min (port_str - name, (int) sizeof hostname - 1);
! strncpy (hostname, name, tmp); /* Don't want colon */
! hostname[tmp] = '\000'; /* Tie off host name */
! port = atoi (port_str + 1);
!
! /* default hostname is localhost */
! if (!hostname[0])
! strcpy (hostname, "localhost");
! hostent = gethostbyname (hostname);
! if (!hostent)
! {
! fprintf_unfiltered (gdb_stderr, "%s: unknown host\n", hostname);
! errno = ENOENT;
! return -1;
! }
! if (use_udp)
! scb->fd = socket (PF_INET, SOCK_DGRAM, 0);
! else
! scb->fd = socket (PF_INET, SOCK_STREAM, 0);
}
if (scb->fd < 0)
return -1;
/* set socket nonblocking */
ioarg = 1;
ioctl (scb->fd, FIONBIO, &ioarg);
/* Use Non-blocking connect. connect() will return 0 if connected
already. */
! if (use_unix)
! {
! struct sockaddr_un sockaddr;
! memset(&sockaddr, 0, sizeof(sockaddr));
! strncpy(sockaddr.sun_path, name, sizeof (sockaddr.sun_path));
! sockaddr.sun_path[sizeof (sockaddr.sun_path ) - 1] = 0;
! sockaddr.sun_family = AF_UNIX;
!
! n = connect(scb->fd, (struct sockaddr *)&sockaddr, SUN_LEN(&sockaddr));
! }
! else
! {
! struct sockaddr_in sockaddr;
! sockaddr.sin_family = PF_INET;
! sockaddr.sin_port = htons (port);
! memcpy (&sockaddr.sin_addr.s_addr, hostent->h_addr,
! sizeof (struct in_addr));
!
! n = connect (scb->fd, (struct sockaddr *) &sockaddr, sizeof
(sockaddr));
! }
if (n < 0
#ifdef USE_WIN32API
next reply other threads:[~2006-04-25 23:53 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-04-25 23:53 Ryan Brown [this message]
2006-04-26 0:07 ` Masaki MURANAKA
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6605dfe70604251653s4dae04e7i721e6b8630afd3c0@mail.google.com \
--to=ribrdb@google.com \
--cc=gdb-patches@sources.redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox