In my iOS application I am using libssh2 library. I am trying to ssh with ipv6 address, But socket is not creating and getting nil socket. It's working fine with ipv4 address.
static CFSocketRef _CreateSocketConnectedToHost(NSString* name, UInt16 port, CFOptionFlags callBackTypes, CFSocketCallBack callback, const CFSocketContext* context, CFTimeInterval timeOut)
I have search for this but not finding any result for ipv6 support with libssh2.
Please help me, Is libssh2 not supporting for ipv6? Can we make it working using libssh2?
just need to use ipv6 property in socket instead of ipv4 and you able to create socket with ipv6 address.
struct sockaddr_in6 ipAddress6;
CFSocketSignature signature;
ipAddress6.sin6_port = htons(port);
signature.protocolFamily = AF_INET6;
signature.protocol = IPPROTO_IP;//IPPROTO_IPV6;
signature.address = (CFDataRef)[NSData dataWithBytes:&ipAddress6 length:ipAddress6.sin6_len];
Related
I am developing an IOS app using pjsip-2.6 and a IPV4 sip server. First build pjsip with the following code in configsite.h
#define PJ_HAS_IPV6 1
build got successful. Then i added the libraries into my project.Run the application in IPV4 network.Its successfully registered and voice call working great.
Then i switched the network to Apple Nat64 network..Nothings works.Here is my code snippets.
For Creating udp transport on IPV4 i used the following code.
pjsua_transport_config cfg;
pjsua_transport_config_default(&cfg);
cfg.port = 5060;
// Add UDP transport.
status = pjsua_transport_create(PJSIP_TRANSPORT_UDP, &cfg, &transport_id);
if (status != PJ_SUCCESS) error_exit("Error creating transport", status);
For Creating transport on IPV6 i used the following code..
pjsua_transport_config cfg;
pjsua_transport_config_default(&cfg);
cfg.port = 5070;
// Add UDP transport for ipv6
status = pjsua_transport_create(PJSIP_TRANSPORT_UDP6, &cfg, &transport_id_udp6);
if (status != PJ_SUCCESS) error_exit("Error creating transport", status);
For creating the Account in IPV6 network i added..
acc_cfg.cred_info[0].username = pj_str((char*)uname);
acc_cfg.cred_info[0].data_type = PJSIP_CRED_DATA_PLAIN_PASSWD;
acc_cfg.cred_info[0].data = pj_str((char *)passwd);
acc_cfg.cred_info[0].realm = pj_str("*");
acc_cfg.cred_info[0].scheme=pj_str((char*)"Digest");
char regUri[PJSIP_MAX_URL_SIZE];
sprintf(regUri, "sip:%s", sip_server);
acc_cfg.reg_uri = pj_str(regUri);
acc_cfg.ipv6_media_use = PJSUA_IPV6_ENABLED;
acc_cfg.transport_id = transport_id_udp6;
It would be better if someone can point me out the problem.Any help would be appreciated.
I think you are failed to creating the transport in IPV6 network.
One patch available for this (Link: https://github.com/johanlantz/pj-nat64)
you need to integrate that patch for NAT64 issue below are the steps to follow.
1) Download the pj-nat64 source from above link.
2) Unzip the file and copy pj-nat64.c file paste into the pjproject (means pjsip source) (path is: pjsip/src/pjsua-lib)
3) Copy pj-nat64.h file paste into the pjproject (means pjsip source) (path is: pjsip/include/pjsua-lib)
4) Need to add the pj-nat64.o in the makefile of pjsip (Make file path is: pjsip/build)
5) Open the makefile and search for the string in doubles quotes “Defines for building PJSUA-LIB library” there add the pj-nat64.o after pjsua_vid.o
6) Compile the pjsip source for all architecture and take the Library files and headers files
7) After Pjsua_start method has returns success. Include the below lines.
#if defined(PJ_HAS_IPV6) && PJ_HAS_IPV6 == 1
pj_nat64_enable_rewrite_module();
#endif
8) Add the below code in on_reg_state2() method for calls.
the_transport = rp->rdata->tp_info.transport;
NSLog(#"transport called %s",the_transport->factory->type_name);
if (the_transport->factory->type & PJSIP_TRANSPORT_IPV6)
{
ipv4=FALSE;
NSLog(#"enter into the ipv6 loop ");
pjsua_var.acc[0].cfg.ipv6_media_use=PJSUA_IPV6_ENABLED ;
nat64_options option=NAT64_REWRITE_INCOMING_SDP | NAT64_REWRITE_ROUTE_AND_CONTACT;
pj_nat64_set_options(option);
}
Is there a way I can put NodeMCU in STATIONAP mode and communicate between two networks (the network which the esp8266 is the access point and the network which the esp8266 is the station)?
Thanks
Exactly the way that you mentioned does it. Use the commands below :
wifi.setmode(wifi.STATIONAP);
wifi.ap.config({ssid = YOUR_AP_NAME});
wifi.ap.setip({ip = DESIRED_AP_IP, netmask = DESIRED_AP_MASK, gateway = DESIRED_AP_GW});
wifi.sta.config(SSID, PASS);
wifi.sta.connect();
I would like to find out programmatically if the user is using a proxy in iOS. Is there a way to detect it with the new api's (ios 7 or 8)?
Also, Is it possible to find out if the user has proxy unknowingly?
you can simply find the proxy in the CFDictionaryRef response.
CFDictionaryRef dicRef = CFNetworkCopySystemProxySettings();
if proxy is enable then you can parse it like this.
const CFStringRef proxyCFstr = (const CFStringRef)CFDictionaryGetValue(dicRef,
(const void*)kCFNetworkProxiesHTTPProxy);
based on this you can make detect if proxy is enabled or not.
By default NSStream based sockets do not detect the System proxy settings, which is very inconvenient if you are trying to debug your NSStream based SSL traffic in Charles Proxy for example. To set the proxy setting for the streams I simply use:
NSInputStream *inStream;
NSOutputStream *outStream;
//...assign the streams...
NSDictionary *proxySettings = CFBridgingRelease(CFNetworkCopySystemProxySettings());
[inStream setProperty:proxySettings forKey:NSStreamSOCKSProxyConfigurationKey];
[outStream setProperty:proxySettings forKey:NSStreamSOCKSProxyConfigurationKey];
I am trying to use CFHostGetAddressing to do a simple DNS lookup. However, I notice that it returns an array of sockaddr structs, which I guess means it can only do IPV4.
Is there a way to support DNS entries with IPV6 addresses in iOS? Perhaps a similar API that returns an array of sockaddr_storage structs?
The CFHostGetAddressing() documentation might be misleading, because struct sockaddr
is a structure that covers all the common elements of the various socket addresses (IPv4, IPv6, ...). It is usually only used to pass a generic pointer to the socket functions.
Actually CFHostGetAddressing() works well with IPv6. It returns an array of CFData elements where each element contains a struct sockaddr_in or a struct sockaddr_in6.
Using the code from your previous question as a starting point, the following should work:
let hostRef = CFHostCreateWithName(kCFAllocatorDefault, "localhost").takeRetainedValue()
var resolved = CFHostStartInfoResolution(hostRef, CFHostInfoType.Addresses, nil)
let addresses = CFHostGetAddressing(hostRef, &resolved).takeRetainedValue() as NSArray
for addr in addresses as [NSData] {
var sockaddr = UnsafePointer<sockaddr_storage>.alloc(1)
addr.getBytes(sockaddr, length: sizeof(sockaddr_storage))
// ...
sockaddr.destroy()
}
I'm new to iOS/MacOS programming and have not found any examples I understand. I imagine it is only a few lines of code to do this, so sorry if this is covered already but for the life of me I cannot find it.
I'm using CFStreamCreatePairWithSocketToHost to create in/out streams. I just want to get the local endpoint info (specifically the IP address, don't care about port really). I already obtain the public IP info from my server, but for security/logging reasons I need the local address as well.
This is on iOS, not MacOS, if it matters.
The following code demonstrates how to get the local socket address. It works with IPv4 and IPv6 addresses. (It is more than a few lines, perhaps somebody knows a shorter solution.)
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
// Create socket pair:
CFReadStreamRef readStream;
CFWriteStreamRef writeStream;
CFStringRef remoteHost = CFSTR("localhost");
CFStreamCreatePairWithSocketToHost(NULL, remoteHost, 5555, &readStream, &writeStream);
// Write something (the socket is not valid before you read or write):
CFWriteStreamOpen(writeStream);
CFWriteStreamWrite(writeStream, "Hello\n", 6);
// Get the native socket handle:
CFDataRef socketData = CFWriteStreamCopyProperty(writeStream, kCFStreamPropertySocketNativeHandle);
CFSocketNativeHandle socket;
CFDataGetBytes(socketData, CFRangeMake(0, sizeof(CFSocketNativeHandle)), (UInt8 *)&socket);
// Get the local socket address from the socket handle:
struct sockaddr_storage sa;
socklen_t salen = sizeof(sa);
getsockname(socket, (struct sockaddr *)&sa, &salen);
// Get numeric host and port from socket address:
char host[NI_MAXHOST];
char service[NI_MAXSERV];
getnameinfo((struct sockaddr *)&sa, salen, host, sizeof(host), service, sizeof(service), NI_NUMERICHOST|NI_NUMERICSERV);
NSLog(#"local address: %s, local port: %s", host, service);