"Fossies" - the Fresh Open Source Software Archive 
Member "jitsi-meet-7685/ios/sdk/src/POSIX.m" (29 Nov 2023, 3373 Bytes) of package /linux/misc/jitsi-meet-7685.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Matlab source code syntax highlighting (style:
standard) with prefixed line numbers.
Alternatively you can here
view or
download the uninterpreted source code file.
1 /*
2 * Copyright @ 2017-present Atlassian Pty Ltd
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #import <React/RCTBridgeModule.h>
18
19 #include <arpa/inet.h>
20 #include <netdb.h>
21 #include <string.h>
22 #include <sys/types.h>
23 #include <sys/socket.h>
24
25 @interface POSIX : NSObject<RCTBridgeModule>
26 @end
27
28 @implementation POSIX
29
30 RCT_EXPORT_MODULE();
31
32 RCT_EXPORT_METHOD(getaddrinfo:(NSString *)hostname
33 servname:(NSString *)servname
34 resolve:(RCTPromiseResolveBlock)resolve
35 reject:(RCTPromiseRejectBlock)reject) {
36 int err;
37 const char *hostname_ = hostname ? hostname.UTF8String : NULL;
38 const char *servname_ = servname ? servname.UTF8String : NULL;
39 struct addrinfo hints;
40 struct addrinfo *res;
41 NSString *rejectCode;
42
43 memset(&hints, 0, sizeof(hints));
44 hints.ai_family = PF_UNSPEC;
45 hints.ai_flags = AI_DEFAULT;
46 if (0 == (err = getaddrinfo(hostname_, servname_, &hints, &res))) {
47 char addr_[MAX(INET_ADDRSTRLEN, INET6_ADDRSTRLEN)];
48 NSMutableArray *res_ = [[NSMutableArray alloc] init];
49
50 for (struct addrinfo *ai = res; ai; ai = ai->ai_next) {
51 int af = ai->ai_family;
52 struct sockaddr *sa = ai->ai_addr;
53 void *addr;
54
55 switch (af) {
56 case AF_INET:
57 addr = &(((struct sockaddr_in *) sa)->sin_addr);
58 break;
59 case AF_INET6:
60 addr = &(((struct sockaddr_in6 *) sa)->sin6_addr);
61 break;
62 default:
63 addr = NULL;
64 break;
65 }
66 if (addr) {
67 if (inet_ntop(af, addr, addr_, sizeof(addr_))) {
68 [res_ addObject:@{
69 @"ai_addr": [NSString stringWithUTF8String:addr_],
70 @"ai_family": [NSNumber numberWithInt:af],
71 @"ai_protocol":
72 [NSNumber numberWithInt:ai->ai_protocol],
73 @"ai_socktype": [NSNumber numberWithInt:ai->ai_socktype]
74 }];
75 } else {
76 err = errno;
77 rejectCode = @"inet_ntop";
78 }
79 } else {
80 err = EAFNOSUPPORT;
81 rejectCode = @"EAFNOSUPPORT";
82 }
83 }
84
85 freeaddrinfo(res);
86
87 // resolve
88 if (res_.count) {
89 resolve(res_);
90 return;
91 }
92
93 if (!err) {
94 err = ERANGE;
95 rejectCode = @"ERANGE";
96 }
97 } else {
98 rejectCode = @"getaddrinfo";
99 }
100
101 // reject
102 NSError *error
103 = [NSError errorWithDomain:NSPOSIXErrorDomain
104 code:err
105 userInfo:nil];
106
107 reject(rejectCode, error.localizedDescription, error);
108 }
109
110 @end