MinGW network fixes

git-svn-id: https://hamlib.svn.sourceforge.net/svnroot/hamlib/trunk@2472 7ae35d74-ebe9-4afe-98af-79ac388436b8
Hamlib-1.2.9
Stéphane Fillod, F8CFE 2008-11-05 23:02:00 +00:00
rodzic c9df61f699
commit ab24cf45e3
4 zmienionych plików z 39 dodań i 7 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.5 2008-11-02 12:42:45 fillods Exp $
* $Id: network.c,v 1.6 2008-11-05 23:02:00 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
@ -134,6 +134,10 @@ static const char *gai_strerror(int errcode)
#endif /* !HAVE_GAI_STRERROR */
#ifdef __MINGW32__
static int wsstarted;
#endif
/**
* \brief Open network port using rig.state data
*
@ -149,9 +153,17 @@ int network_open(hamlib_port_t *rp, int default_port)
int status;
struct addrinfo hints, *res;
char *portstr;
char hostname[FILPATHLEN] = "localhost";
char hostname[FILPATHLEN] = "127.0.0.1";
char defaultportstr[8];
#ifdef __MINGW32__
WSADATA wsadata;
if (!(wsstarted++) && WSAStartup(MAKEWORD(1,1), &wsadata) == SOCKET_ERROR) {
rig_debug(RIG_DEBUG_ERR, "Error creating socket\n");
return -RIG_EIO;
}
#endif
if (!rp)
return -RIG_EINVAL;
@ -204,4 +216,17 @@ int network_open(hamlib_port_t *rp, int default_port)
return RIG_OK;
}
int network_close(hamlib_port_t *rp)
{
int ret;
#ifdef __MINGW32__
ret = closesocket(rp->fd);
if (--wsstarted)
WSACleanup();
#else
ret = close(rp->fd);
#endif
return ret;
}
/** @} */

Wyświetl plik

@ -2,7 +2,7 @@
* Hamlib Interface - network communication header
* Copyright (c) 2000-2008 by Stephane Fillod
*
* $Id: network.h,v 1.2 2008-09-23 22:02:39 fillods Exp $
* $Id: network.h,v 1.3 2008-11-05 23:02:00 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
@ -30,6 +30,7 @@ __BEGIN_DECLS
/* Hamlib internal use, see rig.c */
int network_open(hamlib_port_t *p, int default_port);
int network_close(hamlib_port_t *rp);
__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.100 2008-10-31 23:08:59 fillods Exp $
* $Id: rig.c,v 1.101 2008-11-05 23:02:00 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
@ -297,7 +297,7 @@ RIG * HAMLIB_API rig_init(rig_model_t rig_model)
break;
case RIG_PORT_NETWORK:
strncpy(rs->rigport.pathname, "localhost:4532", FILPATHLEN);
strncpy(rs->rigport.pathname, "127.0.0.1:4532", FILPATHLEN);
break;
default:
@ -669,6 +669,9 @@ int HAMLIB_API rig_close(RIG *rig)
case RIG_PORT_USB:
usb_port_close(&rs->rigport);
break;
case RIG_PORT_NETWORK:
network_close(&rs->rigport);
break;
default:
close(rs->rigport.fd);

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.24 2008-09-23 22:02:39 fillods Exp $
* $Id: rotator.c,v 1.25 2008-11-05 23:02:00 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
@ -234,7 +234,7 @@ ROT * HAMLIB_API rot_init(rot_model_t rot_model)
break;
case RIG_PORT_NETWORK:
strncpy(rs->rotport.pathname, "localhost:4533", FILPATHLEN);
strncpy(rs->rotport.pathname, "127.0.0.1:4533", FILPATHLEN);
break;
default:
@ -410,6 +410,9 @@ int HAMLIB_API rot_close(ROT *rot)
case RIG_PORT_USB:
usb_port_close(&rs->rotport);
break;
case RIG_PORT_NETWORK:
network_close(&rs->rotport);
break;
default:
close(rs->rotport.fd);
}