Revision edc9e987c7d0fe871812788dc915ca91a2569a69

markdoliner at pidgin.im markdoliner at pidgin.im
Sat Mar 24 20:46:40 EDT 2007


o   -----------------------------------------------------------------
|   Revision: edc9e987c7d0fe871812788dc915ca91a2569a69
|   Ancestor: 882a63afd71ce6779fd4528afbc16b3884e790e3
|   Author: markdoliner at pidgin.im
|   Date: 2007-03-25T00:41:31
|   Branch: im.pidgin.pidgin
|   
|   Modified files:
|           libpurple/nat-pmp.c libpurple/nat-pmp.h
|   
|   ChangeLog: 
|   
|   More complete namespacing of nat-pmp
|   
|   ============================================================
|   --- libpurple/nat-pmp.c	b7b50208c7e07447afb75b2f2890bd4dd3b0d91c
|   +++ libpurple/nat-pmp.c	f41bf331cb3878920c1effd8efbf7fb8849816b1
|   @@ -31,15 +31,13 @@
|    #include "nat-pmp.h"
|    #include "debug.h"
|    
|   -#include <sys/types.h>
|   -#include <sys/socket.h>
|   -#include <sys/sysctl.h>
|   -
|   +#include <arpa/inet.h>
|    #include <net/route.h>
|    #include <netinet/in.h>
|   +#include <sys/socket.h>
|   +#include <sys/sysctl.h>
|   +#include <sys/types.h>
|    
|   -#include <arpa/inet.h>
|   -
|    #include <netdb.h>
|    #include <stdio.h>
|    #include <stdlib.h>
|   @@ -47,13 +45,12 @@
|    #include <err.h>
|    
|    #include <errno.h>
|   -#include <assert.h>
|    #include <sys/types.h>
|    #include <net/if.h>
|    
|    #ifdef NET_RT_DUMP2
|    
|   -#define PMP_DEBUG
|   +#define PMP_DEBUG 1
|    
|    /*
|     *	Thanks to R. Matthew Emerson for the fixes on this
|   @@ -243,8 +240,8 @@ purple_pmp_get_public_ip()
|    	int sendfd;
|    	int req_attempts = 1;	
|    	struct timeval req_timeout;
|   -	pmp_ip_request_t req;
|   -	pmp_ip_response_t resp;
|   +	PurplePmpIpRequest req;
|   +	PurplePmpIpResponse resp;
|    	struct sockaddr_in *publicsockaddr = NULL;
|    
|    	req_timeout.tv_sec = 0;
|   @@ -253,8 +250,8 @@ purple_pmp_get_public_ip()
|    	sendfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|    	
|    	//	Clean out both req and resp structures
|   -	bzero(&req, sizeof(pmp_ip_request_t));
|   -	bzero(&resp, sizeof(pmp_ip_response_t));
|   +	bzero(&req, sizeof(PurplePmpIpRequest));
|   +	bzero(&resp, sizeof(PurplePmpIpResponse));
|    	req.version = 0;
|    	req.opcode	= 0;
|    	
|   @@ -268,6 +265,7 @@ purple_pmp_get_public_ip()
|    		struct sockaddr_in addr;
|    		socklen_t len = sizeof(struct sockaddr_in);
|    
|   +		/* TODO: Non-blocking! */
|    		if (sendto(sendfd, &req, sizeof(req), 0, (struct sockaddr *)(gateway), sizeof(struct sockaddr)) < 0)
|    		{
|    			purple_debug_info("nat-pmp", "There was an error sending the NAT-PMP public IP request! (%s)\n", strerror(errno));
|   @@ -280,7 +278,8 @@ purple_pmp_get_public_ip()
|    			return NULL;
|    		}		
|    		
|   -		if (recvfrom(sendfd, &resp, sizeof(pmp_ip_response_t), 0, (struct sockaddr *)(&addr), &len) < 0)
|   +		/* TODO: Non-blocking! */
|   +		if (recvfrom(sendfd, &resp, sizeof(PurplePmpIpResponse), 0, (struct sockaddr *)(&addr), &len) < 0)
|    		{			
|    			if ( (errno != EAGAIN) || (req_attempts == 9) )
|    			{
|   @@ -333,9 +332,9 @@ iterate:
|    }
|    
|    /*!
|   - *	will return NULL on error, or a pointer to the pmp_map_response_t type
|   + *	will return NULL on error, or a pointer to the PurplePmpMapResponse type
|     */
|   -pmp_map_response_t *
|   +PurplePmpMapResponse *
|    purple_pmp_create_map(PurplePmpType type, uint16_t privateport, uint16_t publicport, uint32_t lifetime)
|    {
|    	struct sockaddr_in *gateway = default_gw();
|   @@ -353,8 +352,8 @@ purple_pmp_create_map(PurplePmpType type
|    	int sendfd;
|    	int req_attempts = 1;	
|    	struct timeval req_timeout;
|   -	pmp_map_request_t req;
|   -	pmp_map_response_t *resp = (pmp_map_response_t *)(malloc(sizeof(pmp_map_response_t)));
|   +	PurplePmpMapRequest req;
|   +	PurplePmpMapResponse *resp = (PurplePmpMapResponse *)(malloc(sizeof(PurplePmpMapResponse)));
|    	
|    	req_timeout.tv_sec = 0;
|    	req_timeout.tv_usec = PMP_TIMEOUT;
|   @@ -362,8 +361,8 @@ purple_pmp_create_map(PurplePmpType type
|    	sendfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|    	
|    	//	Clean out both req and resp structures
|   -	bzero(&req, sizeof(pmp_map_request_t));
|   -	bzero(resp, sizeof(pmp_map_response_t));
|   +	bzero(&req, sizeof(PurplePmpMapRequest));
|   +	bzero(resp, sizeof(PurplePmpMapResponse));
|    	req.version = 0;
|    	req.opcode	= ((type == PURPLE_PMP_TYPE_UDP) ? PMP_MAP_OPCODE_UDP : PMP_MAP_OPCODE_TCP);	
|    	req.privateport = htons(privateport); //	What a difference byte ordering makes...d'oh!
|   @@ -378,6 +377,7 @@ purple_pmp_create_map(PurplePmpType type
|    		purple_debug_info("nat-pmp", "\tTimeout: %ds %dus, Request #: %d\n", req_timeout.tv_sec, req_timeout.tv_usec, req_attempts);
|    #endif
|    
|   +		/* TODO: Non-blocking! */
|    		if (sendto(sendfd, &req, sizeof(req), 0, (struct sockaddr *)(gateway), sizeof(struct sockaddr)) < 0)
|    		{
|    			purple_debug_info("nat-pmp", "There was an error sending the NAT-PMP mapping request! (%s)\n", strerror(errno));
|   @@ -390,7 +390,8 @@ purple_pmp_create_map(PurplePmpType type
|    			return NULL;
|    		}		
|    		
|   -		if (recvfrom(sendfd, resp, sizeof(pmp_map_response_t), 0, NULL, NULL) < 0)
|   +		/* TODO: Non-blocking! */
|   +		if (recvfrom(sendfd, resp, sizeof(PurplePmpMapResponse), 0, NULL, NULL) < 0)
|    		{			
|    			if ( (errno != EAGAIN) || (req_attempts == 9) )
|    			{
|   @@ -434,12 +435,12 @@ iterate:
|    
|    /*!
|     *	pmp_destroy_map(uint8_t,uint16_t) 
|   - *	will return NULL on error, or a pointer to the pmp_map_response_t type
|   + *	will return NULL on error, or a pointer to the PurplePmpMapResponse type
|     */
|   -pmp_map_response_t *
|   +PurplePmpMapResponse *
|    purple_pmp_destroy_map(PurplePmpType type, uint16_t privateport)
|    {
|   -	pmp_map_response_t *response;
|   +	PurplePmpMapResponse *response;
|    	
|    	response = purple_pmp_create_map(((type == PURPLE_PMP_TYPE_UDP) ? PMP_MAP_OPCODE_UDP : PMP_MAP_OPCODE_TCP),
|    							privateport, 0, 0);
|   @@ -460,13 +461,13 @@ purple_pmp_get_public_ip()
|    	return NULL;
|    }
|    
|   -pmp_map_response_t *
|   +PurplePmpMapResponse *
|    purple_pmp_create_map(PurplePmpType type, uint16_t privateport, uint16_t publicport, uint32_t lifetime)
|    {
|    	return NULL;
|    }
|    
|   -pmp_map_response_t *
|   +PurplePmpMapResponse *
|    purple_pmp_destroy_map(PurplePmpType type, uint16_t privateport)
|    {
|    	return NULL;
|   ============================================================
|   --- libpurple/nat-pmp.h	fde05a571347c5fd3ae9975f2ad0fbe908e10fa2
|   +++ libpurple/nat-pmp.h	bae3d58035c9f41352495b51ae69203bc489e51b
|   @@ -1,5 +1,5 @@
|    /**
|   -* @file nat-pmp.h NAT-PMP Implementation
|   + * @file nat-pmp.h NAT-PMP Implementation
|     * @ingroup core
|     *
|     * purple
|   @@ -28,20 +28,12 @@
|     * OF SUCH DAMAGE.
|     */
|    
|   -#ifndef _PMPMAPPER_H
|   -#define _PMPMAPPER_H
|   +#ifndef _PURPLE_NAT_PMP_H
|   +#define _PURPLE_NAT_PMP_H
|    
|   -#include <stdio.h>
|   -#include <stdlib.h>
|   -#include <errno.h>
|   -#include <assert.h>
|   -#include <sys/socket.h>
|   -#include <sys/sysctl.h>
|   -#include <sys/types.h>
|   -#include <net/if.h>
|   -#include <net/route.h>
|   +#include <stdint.h>
|    
|   -#define PURPLE_PMP_LIFETIME		3600	//	3600 seconds
|   +#define PURPLE_PMP_LIFETIME 3600 /* seconds */
|    
|    /*
|     *	uint8_t:	version, opcodes
|   @@ -57,7 +49,7 @@ typedef struct {
|    typedef struct {
|    	uint8_t	version;
|    	uint8_t opcode;
|   -} pmp_ip_request_t;
|   +} PurplePmpIpRequest;
|    
|    typedef struct {
|    	uint8_t		version;
|   @@ -65,7 +57,7 @@ typedef struct {
|    	uint16_t	resultcode;
|    	uint32_t	epoch;
|    	uint32_t	address;
|   -} pmp_ip_response_t;
|   +} PurplePmpIpResponse;
|    
|    typedef struct {
|    	uint8_t		version;
|   @@ -74,7 +66,7 @@ typedef struct {
|    	uint16_t	privateport;
|    	uint16_t	publicport;
|    	uint32_t	lifetime;
|   -} pmp_map_request_t;
|   +} PurplePmpMapRequest;
|    
|    typedef struct {
|    	uint8_t		version;
|   @@ -84,10 +76,26 @@ typedef struct {
|    	uint16_t	privateport;
|    	uint16_t	publicport;
|    	uint32_t	lifetime;
|   -} pmp_map_response_t;
|   +} PurplePmpMapResponse;
|    
|   +/**
|   + *
|   + */
|   +/*
|   + * TODO: This should probably cache the result of this lookup requests
|   + *       so that subsequent calls to this function do not require a
|   + *       round-trip exchange with the local router.
|   + */
|    char *purple_pmp_get_public_ip();
|   +
|   +/**
|   + *
|   + */
|   +PurplePmpMapResponse *purple_pmp_create_map(PurplePmpType type, uint16_t privateport, uint16_t publicport, uint32_t lifetime);
|   +
|   +/**
|   + *
|   + */
|   +PurplePmpMapResponse *purple_pmp_destroy_map(PurplePmpType type, uint16_t privateport);
|   +
|   +#endif /* _PURPLE_NAT_PMP_H_ */
|   -pmp_map_response_t *purple_pmp_create_map(PurplePmpType type, uint16_t privateport, uint16_t publicport, uint32_t lifetime);
|   -pmp_map_response_t *purple_pmp_destroy_map(PurplePmpType type, uint16_t privateport);
|   -	
|   -#endif

To get the patch for this revision, please do this:
mtn log --last 1 --diffs --from edc9e987c7d0fe871812788dc915ca91a2569a69


More information about the Commits mailing list