summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2012-09-07 04:45:51 -0400
committerEric S. Raymond <esr@thyrsus.com>2012-09-07 04:45:51 -0400
commitd6312e3de44a1c3b9ee1d15ac6c30b2d06d09e6e (patch)
treec5fe773c1d6487f2e7e599cb543c5781dec2e61c
parent606a688de6b76dba3a8f7b153eb1fddca51a86c3 (diff)
downloadgpsd-d6312e3de44a1c3b9ee1d15ac6c30b2d06d09e6e.tar.gz
Complete change from int to socket_t for sockets.
-rw-r--r--gpsd.c28
-rw-r--r--gpsd.h-tail2
-rw-r--r--netlib.c2
3 files changed, 20 insertions, 12 deletions
diff --git a/gpsd.c b/gpsd.c
index 5e2a90fd..755feee4 100644
--- a/gpsd.c
+++ b/gpsd.c
@@ -286,10 +286,10 @@ The following driver types are compiled into this gpsd instance:\n",
}
#ifdef CONTROL_SOCKET_ENABLE
-static int filesock(char *filename)
+static socket_t filesock(char *filename)
{
struct sockaddr_un addr;
- int sock;
+ socket_t sock;
/*@ -mayaliasunique -usedef @*/
if ((sock = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
@@ -298,7 +298,11 @@ static int filesock(char *filename)
}
(void)strlcpy(addr.sun_path, filename, sizeof(addr.sun_path));
addr.sun_family = (sa_family_t)AF_UNIX;
- (void)bind(sock, (struct sockaddr *)&addr, (int)sizeof(addr));
+ if (bind(sock, (struct sockaddr *)&addr, (int)sizeof(addr)) < 0) {
+ gpsd_report(LOG_ERROR, "can't bind to local socket %s\n", filename);
+ (void)close(sock);
+ return -1;
+ }
if (listen(sock, QLEN) == -1) {
gpsd_report(LOG_ERROR, "can't listen on local socket %s\n", filename);
(void)close(sock);
@@ -361,10 +365,10 @@ static void adjust_max_fd(int fd, bool on)
}
#ifdef SOCKET_EXPORT_ENABLE
-static int passivesock_af(int af, char *service, char *tcp_or_udp, int qlen)
+static socket_t passivesock_af(int af, char *service, char *tcp_or_udp, int qlen)
/* bind a passive command socket for the daemon */
{
- volatile int s = -1; /* why gcc warned about this I don't know */
+ volatile socket_t s = -1; /* why gcc warned about this I don't know */
/*
* af = address family,
* service = IANA protocol name or number.
@@ -446,7 +450,11 @@ static int passivesock_af(int af, char *service, char *tcp_or_udp, int qlen)
*/
if (s > -1) {
int on = 1;
- (void)setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof(on));
+ if (setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof(on)) == -1) {
+ gpsd_report(LOG_ERROR, "Error: SETSOCKOPT IPV6_V6ONLY\n");
+ (void)close(s);
+ return -1;
+ }
}
break;
#endif
@@ -488,7 +496,7 @@ static int passivesock_af(int af, char *service, char *tcp_or_udp, int qlen)
/* *INDENT-OFF* */
static int passivesocks(char *service, char *tcp_or_udp,
- int qlen, /*@out@*/int socks[])
+ int qlen, /*@out@*/socket_t socks[])
{
int numsocks = AFCOUNT;
int i;
@@ -1822,7 +1830,7 @@ int main(int argc, char *argv[])
struct subscriber_t *sub;
#endif /* SOCKET_EXPORT_ENABLE */
#ifdef CONTROL_SOCKET_ENABLE
- static int csock = -1;
+ static socket_t csock = -1;
fd_set control_fds;
socket_t cfd;
static char *control_socket = NULL;
@@ -2262,7 +2270,7 @@ int main(int argc, char *argv[])
socklen_t alen = (socklen_t) sizeof(fsin);
char *c_ip;
/*@+matchanyintegral@*/
- int ssock =
+ socket_t ssock =
accept(msocks[i], (struct sockaddr *)&fsin, &alen);
/*@+matchanyintegral@*/
@@ -2314,7 +2322,7 @@ int main(int argc, char *argv[])
if (csock > -1 && FD_ISSET(csock, &rfds)) {
socklen_t alen = (socklen_t) sizeof(fsin);
/*@+matchanyintegral@*/
- int ssock = accept(csock, (struct sockaddr *)&fsin, &alen);
+ socket_t ssock = accept(csock, (struct sockaddr *)&fsin, &alen);
/*@-matchanyintegral@*/
if (ssock == -1)
diff --git a/gpsd.h-tail b/gpsd.h-tail
index d278d40d..1c822378 100644
--- a/gpsd.h-tail
+++ b/gpsd.h-tail
@@ -754,7 +754,7 @@ extern void gpsd_clear_data(struct gps_device_t *);
extern socket_t netlib_connectsock(int, const char *, const char *, const char *);
extern socket_t netlib_localsocket(const char *, int);
extern const char /*@observer@*/ *netlib_errstr(const int);
-extern char /*@observer@*/ *netlib_sock2ip(int);
+extern char /*@observer@*/ *netlib_sock2ip(socket_t);
extern void nmea_tpv_dump(struct gps_device_t *, /*@out@*/char[], size_t);
extern void nmea_sky_dump(struct gps_device_t *, /*@out@*/char[], size_t);
diff --git a/netlib.c b/netlib.c
index 82f0e3b2..3c3aa66d 100644
--- a/netlib.c
+++ b/netlib.c
@@ -174,7 +174,7 @@ socket_t netlib_localsocket(const char *sockfile, int socktype)
}
}
-char *netlib_sock2ip(int fd)
+char *netlib_sock2ip(socket_t fd)
/* retrieve the IP address corresponding to a socket */
{
sockaddr_t fsin;