* support remote connections over unix domain sockets
@ 2006-04-25 23:53 Ryan Brown
2006-04-26 0:07 ` Masaki MURANAKA
0 siblings, 1 reply; 2+ messages in thread
From: Ryan Brown @ 2006-04-25 23:53 UTC (permalink / raw)
To: gdb-patches
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2006-04-26 0:07 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-04-25 23:53 support remote connections over unix domain sockets Ryan Brown
2006-04-26 0:07 ` Masaki MURANAKA
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox