accept partial 'pathname' for PORT_NETWORK

git-svn-id: https://hamlib.svn.sourceforge.net/svnroot/hamlib/trunk@2406 7ae35d74-ebe9-4afe-98af-79ac388436b8
Hamlib-1.2.8
Stéphane Fillod, F8CFE 2008-09-23 22:02:40 +00:00
rodzic a4e9b56a1c
commit 2492903ea9
4 zmienionych plików z 24 dodań i 14 usunięć

Wyświetl plik

@ -2,7 +2,7 @@
* Hamlib Interface - network communication low-level support
* Copyright (c) 2000-2008 by Stephane Fillod
*
* $Id: network.c,v 1.1 2008-09-21 19:30:34 fillods Exp $
* $Id: network.c,v 1.2 2008-09-23 22:02:39 fillods Exp $
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
@ -71,13 +71,14 @@
* \param rp port data structure (must spec port id eg hostname:port)
* \return RIG_OK or < 0 if error
*/
int network_open(hamlib_port_t *rp) {
int network_open(hamlib_port_t *rp, int default_port) {
int fd; /* File descriptor for the port */
int status;
struct addrinfo hints, *res;
char *portstr;
char hostname[FILPATHLEN];
char hostname[FILPATHLEN] = "localhost";
char defaultportstr[8];
if (!rp)
return -RIG_EINVAL;
@ -86,11 +87,20 @@ int network_open(hamlib_port_t *rp) {
hints.ai_family = PF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
strcpy(hostname, rp->pathname);
portstr = strchr(hostname, ':');
if (!portstr)
return -RIG_ECONF;
*portstr++ = '\0';
if (rp->pathname[0] == ':') {
portstr = rp->pathname+1;
} else {
strncpy(hostname, rp->pathname, FILPATHLEN-1);
/* search last ':', because IPv6 may have some */
portstr = strrchr(hostname, ':');
if (portstr) {
*portstr++ = '\0';
} else {
sprintf(defaultportstr, "%d", default_port);
portstr = defaultportstr;
}
}
status=getaddrinfo(hostname, portstr, &hints, &res);
if (status != 0) {

Wyświetl plik

@ -2,7 +2,7 @@
* Hamlib Interface - network communication header
* Copyright (c) 2000-2008 by Stephane Fillod
*
* $Id: network.h,v 1.1 2008-09-21 19:30:35 fillods Exp $
* $Id: network.h,v 1.2 2008-09-23 22:02:39 fillods Exp $
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
@ -29,7 +29,7 @@
__BEGIN_DECLS
/* Hamlib internal use, see rig.c */
int network_open(hamlib_port_t *p);
int network_open(hamlib_port_t *p, int default_port);
__END_DECLS

Wyświetl plik

@ -2,7 +2,7 @@
* Hamlib Interface - main file
* Copyright (c) 2000-2008 by Stephane Fillod and Frank Singleton
*
* $Id: rig.c,v 1.98 2008-09-21 19:30:35 fillods Exp $
* $Id: rig.c,v 1.99 2008-09-23 22:02:40 fillods Exp $
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
@ -486,7 +486,7 @@ int HAMLIB_API rig_open(RIG *rig)
break; /* ez :) */
case RIG_PORT_NETWORK:
status = network_open(&rs->rigport);
status = network_open(&rs->rigport, 4532);
if (status < 0)
return status;
break;

Wyświetl plik

@ -2,7 +2,7 @@
* Hamlib Interface - main file
* Copyright (c) 2000-2008 by Stephane Fillod and Frank Singleton
*
* $Id: rotator.c,v 1.23 2008-09-21 19:30:35 fillods Exp $
* $Id: rotator.c,v 1.24 2008-09-23 22:02:39 fillods Exp $
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
@ -333,7 +333,7 @@ int HAMLIB_API rot_open(ROT *rot)
break; /* ez :) */
case RIG_PORT_NETWORK:
status = network_open(&rs->rotport);
status = network_open(&rs->rotport, 4533);
if (status < 0)
return status;
break;