summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLorenzo Colitti <lorenzo@google.com>2011-01-03 16:10:34 -0800
committerLorenzo Colitti <lorenzo@google.com>2011-03-08 15:01:15 -0800
commit7528e58daa21c43dd937d06b130a033f31c99604 (patch)
treea30199d0b6e67f286a25e3648559562003dccdd9
parent64bfdc7d8d8e0404f7193f776fd226d1cd870f93 (diff)
downloadframeworks_av-7528e58daa21c43dd937d06b130a033f31c99604.zip
frameworks_av-7528e58daa21c43dd937d06b130a033f31c99604.tar.gz
frameworks_av-7528e58daa21c43dd937d06b130a033f31c99604.tar.bz2
Support IPv6 in HTTP streaming.
Bug: 4068057 Change-Id: I1e141ec99fbfa43722eeb2e4161d56548ffc0640
-rw-r--r--media/libstagefright/HTTPStream.cpp26
1 files changed, 17 insertions, 9 deletions
diff --git a/media/libstagefright/HTTPStream.cpp b/media/libstagefright/HTTPStream.cpp
index 7194614..adb6d01 100644
--- a/media/libstagefright/HTTPStream.cpp
+++ b/media/libstagefright/HTTPStream.cpp
@@ -133,15 +133,27 @@ status_t HTTPStream::connect(const char *server, int port) {
return ERROR_ALREADY_CONNECTED;
}
- struct hostent *ent = gethostbyname(server);
- if (ent == NULL) {
+ if (port < 0 || port > (int) USHRT_MAX) {
+ return UNKNOWN_ERROR;
+ }
+
+ char service[sizeof("65536")];
+ sprintf(service, "%d", port);
+ struct addrinfo hints, *ai;
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_flags = AI_ADDRCONFIG | AI_NUMERICSERV;
+ hints.ai_socktype = SOCK_STREAM;
+
+ int ret = getaddrinfo(server, service, &hints, &ai);
+ if (ret) {
return ERROR_UNKNOWN_HOST;
}
CHECK_EQ(mSocket, -1);
- mSocket = socket(AF_INET, SOCK_STREAM, 0);
+ mSocket = socket(ai[0].ai_family, ai[0].ai_socktype, ai[0].ai_protocol);
if (mSocket < 0) {
+ freeaddrinfo(ai);
return UNKNOWN_ERROR;
}
@@ -153,13 +165,9 @@ status_t HTTPStream::connect(const char *server, int port) {
mLock.unlock();
- struct sockaddr_in addr;
- addr.sin_family = AF_INET;
- addr.sin_port = htons(port);
- addr.sin_addr.s_addr = *(in_addr_t *)ent->h_addr;
- memset(addr.sin_zero, 0, sizeof(addr.sin_zero));
+ status_t res = MyConnect(s, ai[0].ai_addr, ai[0].ai_addrlen);
- status_t res = MyConnect(s, (const struct sockaddr *)&addr, sizeof(addr));
+ freeaddrinfo(ai);
mLock.lock();