tgt: fix conffiles section
[openwrt/svn-archive/archive.git] / multimedia / shairport / patches / 001-fix_ipv6_fallback.patch
1 diff --git a/socketlib.c b/socketlib.c
2 index 9efdf22..eb44bcf 100644
3 --- a/socketlib.c
4 +++ b/socketlib.c
5 @@ -39,9 +39,11 @@
6 #include <openssl/bio.h>
7 #include <openssl/buffer.h>
8
9 -int common_setup(struct addrinfo *pAddrInfo)
10 -{
11 +int common_setup(struct addrinfo **ppAddrInfo, int pPort)
12 +{
13 int tSock;
14 + struct addrinfo *pAddrInfo = *ppAddrInfo;
15 +
16 //printAddrs(pAddrInfo);
17 tSock = socket(pAddrInfo->ai_family, pAddrInfo->ai_socktype, 0);
18 #ifdef AF_INET6
19 @@ -49,7 +51,17 @@ int common_setup(struct addrinfo *pAddrInfo)
20 {
21 //Fallback to ipv4
22 perror("Failed to create ipv6 socket. Trying ipv4");
23 - pAddrInfo->ai_family = AF_INET;
24 + (*ppAddrInfo)->ai_family = AF_INET;
25 + if (pPort != -1)
26 + {
27 + char tService[SERVLEN];
28 + sprintf(tService, "%d", pPort); // copies port to string
29 + int tFamily = AF_INET;
30 + if(getAddr(NULL, tService, tFamily, SOCK_STREAM, ppAddrInfo))
31 + {
32 + return ERROR; // getAddr prints out error message
33 + }
34 + }
35 tSock = socket(pAddrInfo->ai_family, pAddrInfo->ai_socktype, 0);
36 }
37 #endif
38 @@ -63,7 +75,7 @@ int setup_client(struct addrinfo *server_host)
39
40 while(tIdx++ < RETRY_COUNT)
41 {
42 - tSockDesc = common_setup(server_host);
43 + tSockDesc = common_setup(&server_host, -1);
44 if (tSockDesc < 0 && tIdx >= RETRY_COUNT)
45 {
46 perror("Error: Could not create socket");
47 @@ -107,9 +119,23 @@ int getAddr(char *pHostname, char *pService, int pFamily, int pSockType, struct
48 return tError;
49 }
50
51 -int setup_server(struct addrinfo *server_addr)
52 +int setup_server(struct addrinfo *server_addr, int pPort)
53 {
54 - int tSock = common_setup(server_addr);
55 + char tService[SERVLEN];
56 + sprintf(tService, "%d", pPort); // copies port to string
57 + int tFamily = AF_INET;
58 + #ifdef AF_INET6
59 + //printf("Listening on IPv6 Socket\n");
60 + tFamily = AF_INET6;
61 + #else
62 + //printf("Listening on IPv4 Socket");
63 + #endif
64 + if(getAddr(NULL, tService, tFamily, SOCK_STREAM, &server_addr))
65 + {
66 + return ERROR; // getAddr prints out error message
67 + }
68 +
69 + int tSock = common_setup(&server_addr, pPort);
70 if (tSock < 0)
71 {
72 perror("Error: Could not create server socket");
73 @@ -154,21 +180,7 @@ int acceptClient(int pSock, struct addrinfo *server_addr)
74
75 int setupListenServer(struct addrinfo **pAddrInfo, int pPort)
76 {
77 - char tService[SERVLEN];
78 - sprintf(tService, "%d", pPort); // copies port to string
79 - int tFamily = AF_INET;
80 - #ifdef AF_INET6
81 - //printf("Listening on IPv6 Socket\n");
82 - tFamily = AF_INET6;
83 - #else
84 - //printf("Listening on IPv4 Socket");
85 - #endif
86 - if(getAddr(NULL, tService, tFamily, SOCK_STREAM, pAddrInfo))
87 - {
88 - return ERROR; // getAddr prints out error message
89 - }
90 -
91 - int tSocketDescriptor = setup_server(*pAddrInfo);
92 + int tSocketDescriptor = setup_server(*pAddrInfo, pPort);
93 char tAddr[INET6_ADDRSTRLEN];
94 socklen_t tSize = INET6_ADDRSTRLEN;
95 inet_ntop((*pAddrInfo)->ai_family, (*pAddrInfo)->ai_addr, tAddr, tSize);
96 diff --git a/socketlib.h b/socketlib.h
97 index 6d501f3..5cb1bf0 100644
98 --- a/socketlib.h
99 +++ b/socketlib.h
100 @@ -24,7 +24,7 @@
101 #define DEFAULT_UNIX "/unix"
102
103 int setup_client(struct addrinfo *server_info);
104 -int setup_server(struct addrinfo *server_address);
105 +int setup_server(struct addrinfo *server_address, int pPort);
106 int setupListenServer(struct addrinfo **pAddrInfo, int pPort);
107 int acceptClient(int pSock, struct addrinfo *server_addr);
108 void delay(long pMillisecs, struct timeval *pRes);