~ubuntu-branches/ubuntu/maverick/transmission/maverick-updates

« back to all changes in this revision

Viewing changes to third-party/miniupnp/miniupnpc.c

  • Committer: Bazaar Package Importer
  • Author(s): Chris Coulson, Krzysztof Klimonda, Chris Coulson
  • Date: 2009-09-09 09:06:11 UTC
  • mfrom: (1.1.27 upstream)
  • Revision ID: james.westby@ubuntu.com-20090909090611-09ai2hyo66h1dhv8
Tags: 1.74-0ubuntu1
[ Krzysztof Klimonda ]
* Merge from debian unstable, remaining changes:
  - debian/control:
    + Added replaces & provides clutch (now included as part of transmission).
    + add liblaunchpad-integration to Build-Depends
  - debian/rules:
    + Create a PO template during package build.
  - debian/patches/01_lpi.patch:
    + Integrate Transmission with Launchpad
  - debian/patches/20_add_X-Ubuntu-Gettext-Domain.diff:
    + Add X-Ubuntu-Gettext-Domain to .desktop file.
* debian/control:
  - add lsb-release to Build-Depends
* This includes the QT client in transmission-qt.

[ Chris Coulson ]
* Update to new upstream version 1.74 (LP: #418367):
  - Better data recovery in the case of an OS or Transmission crash
  - If a data file is moved, stop the torrent instead of redownloading 
    it (LP: #419304).
  - Fix bug that didn't list some peers in the resume file and in PEX
  - More helpful torrent error messages
  - DHT now honors the bind-address-ipv4 configuration option
  - Fix Debian build error with miniupnpc
  - Fix Cygwin build error with strtold
  - Update to a newer snapshot of miniupnpc
  - Fix crash that occurred when adding torrents on some desktops
  - Synchronize the statusbar's and torrent list's speeds
  - Fix the Properties dialog's "Origin" field for multiple torrents
* debian/rules, debian/control:
  - Don't run autoreconf at build time and don't build-dep on libtool.
* debian/control:
  - transmission-common replaces transmission-gtk (<< 1.74) rather than
    (<= 1.73-1).
* Refreshed patches:
  - 01_lpi.patch.
  - dont_build_libevent.patch.
  - qt_client_use_system_libevent.patch.
* Dropped patches not needed anymore:
  - updateminiupnpcstrings_double_escape_slash.patch
* Added 99_autoreconf.patch for autotools update.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: miniupnpc.c,v 1.58 2009/07/09 15:59:46 nanard Exp $ */
 
1
/* $Id: miniupnpc.c,v 1.63 2009/08/07 14:44:50 nanard Exp $ */
2
2
/* Project : miniupnp
3
3
 * Author : Thomas BERNARD
4
 
 * copyright (c) 2005-2007 Thomas Bernard
 
4
 * copyright (c) 2005-2009 Thomas Bernard
5
5
 * This software is subjet to the conditions detailed in the
6
6
 * provided LICENCE file. */
 
7
#define __EXTENSIONS__ 1
 
8
#ifndef MACOSX
 
9
#if !defined(_XOPEN_SOURCE) && !defined(__OpenBSD__) && !defined(__NetBSD__)
 
10
#ifndef __cplusplus
 
11
#define _XOPEN_SOURCE 600
 
12
#endif
 
13
#endif
 
14
#ifndef __BSD_VISIBLE
 
15
#define __BSD_VISIBLE 1
 
16
#endif
 
17
#endif
 
18
 
 
19
#include <stdlib.h>
7
20
#include <stdio.h>
8
 
#include <stdlib.h>
9
21
#include <string.h>
10
22
#ifdef WIN32
11
23
/* Win32 Specific includes and defines */
29
41
#include <arpa/inet.h>
30
42
#include <poll.h>
31
43
#include <netdb.h>
 
44
#include <strings.h>
 
45
#include <errno.h>
32
46
#define closesocket close
 
47
#define MINIUPNPC_IGNORE_EINTR
 
48
#endif
 
49
#ifdef MINIUPNPC_SET_SOCKET_TIMEOUT
 
50
#include <sys/time.h>
33
51
#endif
34
52
#include "miniupnpc.h"
35
53
#include "minissdpc.h"
149
167
        int buffree;
150
168
    int n;
151
169
        int contentlen, headerlen;      /* for the response */
 
170
#ifdef MINIUPNPC_SET_SOCKET_TIMEOUT
 
171
        struct timeval timeout;
 
172
#endif
152
173
        snprintf(soapact, sizeof(soapact), "%s#%s", service, action);
153
174
        if(args==NULL)
154
175
        {
224
245
                        *bufsize = 0;
225
246
                        return -1;
226
247
                }
 
248
#ifdef MINIUPNPC_SET_SOCKET_TIMEOUT
 
249
                /* setting a 3 seconds timeout for the connect() call */
 
250
                timeout.tv_sec = 3;
 
251
                timeout.tv_usec = 0;
 
252
                if(setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(struct timeval)) < 0)
 
253
                {
 
254
                        PRINT_SOCKET_ERROR("setsockopt");
 
255
                }
 
256
                timeout.tv_sec = 3;
 
257
                timeout.tv_usec = 0;
 
258
                if(setsockopt(s, SOL_SOCKET, SO_SNDTIMEO, &timeout, sizeof(struct timeval)) < 0)
 
259
                {
 
260
                        PRINT_SOCKET_ERROR("setsockopt");
 
261
                }
 
262
#endif
227
263
                dest.sin_family = AF_INET;
228
264
                dest.sin_port = htons(port);
229
265
                dest.sin_addr.s_addr = inet_addr(hostname);
230
 
                if(connect(s, (struct sockaddr *)&dest, sizeof(struct sockaddr))<0)
231
 
                {
 
266
#ifdef MINIUPNPC_IGNORE_EINTR
 
267
        do {
 
268
#endif
 
269
            n = connect(s, (struct sockaddr *)&dest, sizeof(struct sockaddr));
 
270
#ifdef MINIUPNPC_IGNORE_EINTR
 
271
        } while(n < 0 && errno == EINTR);
 
272
#endif
 
273
                if(n < 0)
 
274
        {
232
275
                        PRINT_SOCKET_ERROR("connect");
233
276
                        closesocket(s);
234
277
                        *bufsize = 0;
351
394
        "HOST: " UPNP_MCAST_ADDR ":" XSTR(PORT) "\r\n"
352
395
        "ST: %s\r\n"
353
396
        "MAN: \"ssdp:discover\"\r\n"
354
 
        "MX: 3\r\n"
 
397
        "MX: %u\r\n"
355
398
        "\r\n";
356
399
        static const char * const deviceList[] = {
357
400
                "urn:schemas-upnp-org:device:InternetGatewayDevice:1",
365
408
        int sudp;
366
409
        int n;
367
410
        struct sockaddr_in sockudp_r, sockudp_w;
 
411
        unsigned int mx;
368
412
 
369
413
#ifndef WIN32
370
414
        /* first try to get infos from minissdpd ! */
432
476
                return NULL;
433
477
    }
434
478
 
 
479
        /* Calculating maximum response time in seconds */
 
480
        mx = ((unsigned int)delay) / 1000u;
435
481
        /* receiving SSDP response packet */
436
482
        for(n = 0;;)
437
483
        {
439
485
        {
440
486
                /* sending the SSDP M-SEARCH packet */
441
487
                n = snprintf(bufr, sizeof(bufr),
442
 
                             MSearchMsgFmt, deviceList[deviceIndex++]);
 
488
                             MSearchMsgFmt, deviceList[deviceIndex++], mx);
443
489
                /*printf("Sending %s", bufr);*/
444
490
                n = sendto(sudp, bufr, n, 0,
445
491
                           (struct sockaddr *)&sockudp_w, sizeof(struct sockaddr_in));
587
633
    int n;
588
634
#ifndef WIN32
589
635
    struct pollfd fds[1]; /* for the poll */
590
 
    fds[0].fd = socket;
591
 
    fds[0].events = POLLIN;
592
 
    n = poll(fds, 1, timeout);
 
636
#ifdef MINIUPNPC_IGNORE_EINTR
 
637
    do {
 
638
#endif
 
639
        fds[0].fd = socket;
 
640
        fds[0].events = POLLIN;
 
641
        n = poll(fds, 1, timeout);
 
642
#ifdef MINIUPNPC_IGNORE_EINTR
 
643
    } while(n < 0 && errno == EINTR);
 
644
#endif
593
645
    if(n < 0)
594
646
    {
595
647
        PRINT_SOCKET_ERROR("poll");
606
658
    FD_SET(socket, &socketSet);
607
659
    timeval.tv_sec = timeout / 1000;
608
660
    timeval.tv_usec = (timeout % 1000) * 1000;
609
 
    /*n = select(0, &socketSet, NULL, NULL, &timeval);*/
610
661
    n = select(FD_SETSIZE, &socketSet, NULL, NULL, &timeval);
611
662
    if(n < 0)
612
663
    {