From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19313 invoked by alias); 25 Apr 2006 23:53:38 -0000 Received: (qmail 19305 invoked by uid 22791); 25 Apr 2006 23:53:37 -0000 X-Spam-Check-By: sourceware.org Received: from smtp-out.google.com (HELO smtp-out.google.com) (216.239.33.17) by sourceware.org (qpsmtpd/0.31) with ESMTP; Tue, 25 Apr 2006 23:53:35 +0000 Received: from vegeta.corp.google.com (vegeta.corp.google.com [172.24.0.3]) by smtp-out.google.com with ESMTP id k3PNrLRg021653 for ; Wed, 26 Apr 2006 00:53:30 +0100 Received: from smtp-out2.google.com (fpr7.prod.google.com [10.253.18.7]) by vegeta.corp.google.com with ESMTP id k3PEf1oQ004725 for ; Tue, 25 Apr 2006 16:53:20 -0700 Received: by smtp-out2.google.com with SMTP id 7so341179fpr for ; Tue, 25 Apr 2006 16:53:20 -0700 (PDT) Received: by 10.253.18.8 with SMTP id 8mr413575fpr; Tue, 25 Apr 2006 16:53:19 -0700 (PDT) Received: by 10.253.19.20 with HTTP; Tue, 25 Apr 2006 16:53:20 -0700 (PDT) Message-ID: <6605dfe70604251653s4dae04e7i721e6b8630afd3c0@mail.google.com> Date: Tue, 25 Apr 2006 23:53:00 -0000 From: "Ryan Brown" To: gdb-patches@sources.redhat.com Subject: support remote connections over unix domain sockets MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2006-04/txt/msg00343.txt.bz2 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 * ser-tcp.c (net_open): Add support for unix domain sockets. Index: gdb/ser-tcp.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D 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 #include #include + #include #endif #include *************** 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 =3D 0; if (strncmp (name, "udp:", 4) =3D=3D 0) { use_udp =3D 1; name =3D name + 4; } else if (strncmp (name, "tcp:", 4) =3D=3D 0) name =3D name + 4; ! port_str =3D strchr (name, ':'); ! if (!port_str) ! error (_("net_open: No colon in host name!")); /* Shouldn't ever happen */ ! tmp =3D min (port_str - name, (int) sizeof hostname - 1); ! strncpy (hostname, name, tmp); /* Don't want colon */ ! hostname[tmp] =3D '\000'; /* Tie off host name */ ! port =3D atoi (port_str + 1); ! /* default hostname is localhost */ ! if (!hostname[0]) ! strcpy (hostname, "localhost"); ! hostent =3D gethostbyname (hostname); ! if (!hostent) ! { ! fprintf_unfiltered (gdb_stderr, "%s: unknown host\n", hostname); ! errno =3D ENOENT; ! return -1; } - - if (use_udp) - scb->fd =3D socket (PF_INET, SOCK_DGRAM, 0); - else - scb->fd =3D socket (PF_INET, SOCK_STREAM, 0); - if (scb->fd < 0) return -1; - sockaddr.sin_family =3D PF_INET; - sockaddr.sin_port =3D htons (port); - memcpy (&sockaddr.sin_addr.s_addr, hostent->h_addr, - sizeof (struct in_addr)); - /* set socket nonblocking */ ioarg =3D 1; ioctl (scb->fd, FIONBIO, &ioarg); /* Use Non-blocking connect. connect() will return 0 if connected already. */ ! n =3D connect (scb->fd, (struct sockaddr *) &sockaddr, sizeof (sockaddr= )); if (n < 0 #ifdef USE_WIN32API --- 80,162 ---- #endif use_udp =3D 0; + use_unix =3D 0; if (strncmp (name, "udp:", 4) =3D=3D 0) { use_udp =3D 1; name =3D name + 4; } + else if (strncmp (name, "unix:", 5) =3D=3D 0) + { + use_unix =3D 1; + name =3D name + 5; + } else if (strncmp (name, "tcp:", 4) =3D=3D 0) name =3D name + 4; ! if (use_unix) ! { ! scb->fd =3D socket (AF_UNIX, SOCK_STREAM, 0); ! port =3D 0; ! hostent =3D 0; ! } ! else ! { ! port_str =3D strchr (name, ':'); ! if (!port_str) ! error (_("net_open: No colon in host name!")); /* Shouldn't ever happen */ ! tmp =3D min (port_str - name, (int) sizeof hostname - 1); ! strncpy (hostname, name, tmp); /* Don't want colon */ ! hostname[tmp] =3D '\000'; /* Tie off host name */ ! port =3D atoi (port_str + 1); ! ! /* default hostname is localhost */ ! if (!hostname[0]) ! strcpy (hostname, "localhost"); ! hostent =3D gethostbyname (hostname); ! if (!hostent) ! { ! fprintf_unfiltered (gdb_stderr, "%s: unknown host\n", hostname); ! errno =3D ENOENT; ! return -1; ! } ! if (use_udp) ! scb->fd =3D socket (PF_INET, SOCK_DGRAM, 0); ! else ! scb->fd =3D socket (PF_INET, SOCK_STREAM, 0); } if (scb->fd < 0) return -1; /* set socket nonblocking */ ioarg =3D 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] =3D 0; ! sockaddr.sun_family =3D AF_UNIX; ! ! n =3D connect(scb->fd, (struct sockaddr *)&sockaddr, SUN_LEN(&socka= ddr)); ! } ! else ! { ! struct sockaddr_in sockaddr; ! sockaddr.sin_family =3D PF_INET; ! sockaddr.sin_port =3D htons (port); ! memcpy (&sockaddr.sin_addr.s_addr, hostent->h_addr, ! sizeof (struct in_addr)); ! ! n =3D connect (scb->fd, (struct sockaddr *) &sockaddr, sizeof (sockaddr)); ! } if (n < 0 #ifdef USE_WIN32API