diff --git a/src/network.c b/src/network.c index c33068bc5..0f0b9d3e8 100644 --- a/src/network.c +++ b/src/network.c @@ -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; +} + /** @} */ diff --git a/src/network.h b/src/network.h index 2637f83cd..9dedd9347 100644 --- a/src/network.h +++ b/src/network.h @@ -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 diff --git a/src/rig.c b/src/rig.c index 7ce3ee1c9..b6eec7cb0 100644 --- a/src/rig.c +++ b/src/rig.c @@ -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); diff --git a/src/rotator.c b/src/rotator.c index 882d4580c..c6597bc5b 100644 --- a/src/rotator.c +++ b/src/rotator.c @@ -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); }