kopia lustrzana https://github.com/Hamlib/Hamlib
accept partial 'pathname' for PORT_NETWORK
git-svn-id: https://hamlib.svn.sourceforge.net/svnroot/hamlib/trunk@2406 7ae35d74-ebe9-4afe-98af-79ac388436b8Hamlib-1.2.8
rodzic
a4e9b56a1c
commit
2492903ea9
|
@ -2,7 +2,7 @@
|
||||||
* Hamlib Interface - network communication low-level support
|
* Hamlib Interface - network communication low-level support
|
||||||
* Copyright (c) 2000-2008 by Stephane Fillod
|
* 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
|
* This library is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Library General Public License as
|
* 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)
|
* \param rp port data structure (must spec port id eg hostname:port)
|
||||||
* \return RIG_OK or < 0 if error
|
* \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 fd; /* File descriptor for the port */
|
||||||
int status;
|
int status;
|
||||||
struct addrinfo hints, *res;
|
struct addrinfo hints, *res;
|
||||||
char *portstr;
|
char *portstr;
|
||||||
char hostname[FILPATHLEN];
|
char hostname[FILPATHLEN] = "localhost";
|
||||||
|
char defaultportstr[8];
|
||||||
|
|
||||||
if (!rp)
|
if (!rp)
|
||||||
return -RIG_EINVAL;
|
return -RIG_EINVAL;
|
||||||
|
@ -86,11 +87,20 @@ int network_open(hamlib_port_t *rp) {
|
||||||
hints.ai_family = PF_UNSPEC;
|
hints.ai_family = PF_UNSPEC;
|
||||||
hints.ai_socktype = SOCK_STREAM;
|
hints.ai_socktype = SOCK_STREAM;
|
||||||
|
|
||||||
strcpy(hostname, rp->pathname);
|
if (rp->pathname[0] == ':') {
|
||||||
portstr = strchr(hostname, ':');
|
portstr = rp->pathname+1;
|
||||||
if (!portstr)
|
} else {
|
||||||
return -RIG_ECONF;
|
strncpy(hostname, rp->pathname, FILPATHLEN-1);
|
||||||
|
|
||||||
|
/* search last ':', because IPv6 may have some */
|
||||||
|
portstr = strrchr(hostname, ':');
|
||||||
|
if (portstr) {
|
||||||
*portstr++ = '\0';
|
*portstr++ = '\0';
|
||||||
|
} else {
|
||||||
|
sprintf(defaultportstr, "%d", default_port);
|
||||||
|
portstr = defaultportstr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
status=getaddrinfo(hostname, portstr, &hints, &res);
|
status=getaddrinfo(hostname, portstr, &hints, &res);
|
||||||
if (status != 0) {
|
if (status != 0) {
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* Hamlib Interface - network communication header
|
* Hamlib Interface - network communication header
|
||||||
* Copyright (c) 2000-2008 by Stephane Fillod
|
* 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
|
* This library is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Library General Public License as
|
* it under the terms of the GNU Library General Public License as
|
||||||
|
@ -29,7 +29,7 @@
|
||||||
__BEGIN_DECLS
|
__BEGIN_DECLS
|
||||||
|
|
||||||
/* Hamlib internal use, see rig.c */
|
/* 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
|
__END_DECLS
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* Hamlib Interface - main file
|
* Hamlib Interface - main file
|
||||||
* Copyright (c) 2000-2008 by Stephane Fillod and Frank Singleton
|
* 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
|
* This library is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Library General Public License as
|
* 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 :) */
|
break; /* ez :) */
|
||||||
|
|
||||||
case RIG_PORT_NETWORK:
|
case RIG_PORT_NETWORK:
|
||||||
status = network_open(&rs->rigport);
|
status = network_open(&rs->rigport, 4532);
|
||||||
if (status < 0)
|
if (status < 0)
|
||||||
return status;
|
return status;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* Hamlib Interface - main file
|
* Hamlib Interface - main file
|
||||||
* Copyright (c) 2000-2008 by Stephane Fillod and Frank Singleton
|
* 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
|
* This library is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Library General Public License as
|
* 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 :) */
|
break; /* ez :) */
|
||||||
|
|
||||||
case RIG_PORT_NETWORK:
|
case RIG_PORT_NETWORK:
|
||||||
status = network_open(&rs->rotport);
|
status = network_open(&rs->rotport, 4533);
|
||||||
if (status < 0)
|
if (status < 0)
|
||||||
return status;
|
return status;
|
||||||
break;
|
break;
|
||||||
|
|
Ładowanie…
Reference in New Issue